Skip to content

Commit

Permalink
add network system of multi-host migration
Browse files Browse the repository at this point in the history
add support for network subsystem.

Signed-off-by: Houqi (Nick) Zuo <[email protected]>
  • Loading branch information
nickzhq committed Sep 11, 2024
1 parent 3f666d8 commit 6adfc8c
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 0 deletions.
3 changes: 3 additions & 0 deletions avocado_vt/plugins/vt_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from virttest.vt_cluster import cluster, node_metadata
from virttest.vt_imgr import vt_imgr
from virttest.vt_resmgr import resmgr
from virttest.vt_netmgr import vt_netmgr


class ClusterSetupError(Exception):
Expand Down Expand Up @@ -54,13 +55,15 @@ def _pre_mgr_setup():
# Pre-setup the cluster manager
resmgr.startup()
vt_imgr.startup()
vt_netmgr.startup()
except Exception as err:
raise ClusterManagerSetupError(err)

@staticmethod
def _post_mgr_cleanup():
try:
# Post-cleanup the cluster manager
vt_netmgr.teardown()
vt_imgr.teardown()
resmgr.teardown()
except Exception as err:
Expand Down
1 change: 1 addition & 0 deletions virttest/vt_netmgr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .vt_netmgr import vt_netmgr
197 changes: 197 additions & 0 deletions virttest/vt_netmgr/vt_netmgr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
"""
The upper-level network manager.
from virttest.vt_netgr import vt_netmgr
"""

import logging

from virttest.vt_cluster import cluster
from virttest.vt_resmgr.resources.network import network as nt
from virttest.vt_resmgr.resources.network import port

LOG = logging.getLogger("avocado." + __name__)


class _VTNetworkManager(object):
"""
The Network Manager.
"""

def __init__(self):
self._networks = list()
self._ports = list()

def startup(self):
LOG.info(f"Start the network manager!")

def teardown(self):
LOG.info(f"Stop the network manager!")

def define_network_config(self, params):
"""
Translate the parameters of user layer to parameters of vt framework
layer.
:param params: The parameters of user level.
:type params: dict.
:return: The parsed parameters in vt framework layer.
:rtype: dict.
"""
pass

def create_network_object(self, network_params, name):
"""
TODO
Create the network by its cartesian params.
:param network_params: The network tag defined in cartesian params.
:type network_params: String.
:param name: The name.
:type name: String.
:return: The uuid of created network.
:rtype: String.
"""
# network_obj = nt.Network(network_params, name)
# network_obj.create()
# self._networks.append(network_obj)
# return network_obj.uuid
pass

def delete_network_object(self, descriptor):
"""
TODO
Delete the networks by its descriptor.
:param descriptor: The network name or the uuid.
:type descriptor: String.
"""
be_deleted = []
for obj in self._networks:
if descriptor in (
obj.uuid,
obj.name,
):
obj.delete()
be_deleted.append(obj)

for obj in be_deleted:
self._networks.remove(obj)

def setup_network(self):
pass

def clean_up_network(self):
pass

def get_network_info(self, network_name):
"""
Filter the network based on the network name.
:param network_name: The network name.
:type network_name: String.
:return: The config of network or None if nothing found.
:rtype: dict.
"""
for obj in self._networks:
if network_name in (obj.name,):
return {"uuid": obj.uuid,
"name": obj.name,
"type": obj.type,
"spec": obj.spec,
}
return None

def query_network(self, filter):
"""
Get the network by a filter.
Note: filter may be as following:
network uuid,
network name,
:param filter: The filter.
:type filter: String.
:return: A list of network configuration or [] if nothing found.
:rtype: list.
e.g.: [{"uuid": uuid, "name": name, "type": type, "spec": spec},
{"uuid": uuid, "name": name, "type": type, "spec": spec},
....]
"""
res = []
for obj in self._networks:
if filter in (obj.uuid,) or filter in (obj.name,):
res.append(obj)
return res

def create_port_object(self, name, network_uuid, vm_name, mac_nic, net_type):
"""
TODO
Create the port by its params.
:param name: The port name.
:type name: String.
:param network_uuid: The network uuid which this port belongs to.
:type network_uuid: String.
:param vm_name: The vm name.
:type vm_name: String.
:param mac_nic: The mac address.
:type mac_nic: String.
:param net_type: The net type.
:type net_type: String.
"""
port_obj = port.Port(name, network_uuid, vm_name, mac_nic, net_type)
port_obj.create()
self._networks.append(port_obj)

def delete_port_object(self):
pass

def setup_port(self):
pass

def clean_up_port(self):
pass

def get_port_info(self, filter):
"""
Filter the port.
Note: the filter may be as following:
port uuid,
port name
:param filter: The network name or the uuid.
:type filter: String.
:return: The port config or None If not found.
:rtype: dict.
"""
for obj in self._ports:
if filter in (obj.name, obj.uuid, ):
return filter.to_dict()
return None

def query_port(self, filter):
"""
Get the port configuration.
Note: the filter may be as following:
port uuid,
port name
:param filter: The filter.
:type filter: String.
:return: The port configuration.
:rtype: dict.
"""
res = []
for obj in self._ports:
if filter in (obj.uuid, obj.name):
res.append(filter.to_dict())
return res


vt_netmgr = _VTNetworkManager()
Empty file.
28 changes: 28 additions & 0 deletions virttest/vt_resmgr/resources/network/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from abc import ABC
import uuid


class Network(ABC):
def __init__(self, name, network_params):
self.uuid = uuid.uuid4().hex
self.name = name
self._type = network_params["type"]
self._spec = network_params["spec"]

@property
def type(self):
return self._type

@property
def spec(self):
return self._spec

def create(self):
# TODO
# create the port for the self._spec
pass

def delete(self):
# TODO
# delete the port for the self._spec
pass
38 changes: 38 additions & 0 deletions virttest/vt_resmgr/resources/network/port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from abc import ABC
import uuid

# from virttest.vt_resmgr.resources.network import PortType


class Port(ABC):
def __init__(self, name, network_uuid, vm_name, mac_nic, net_type):
self.uuid = uuid.uuid4().hex
self.name = name
self.network_uuid = network_uuid
self.vm_name = vm_name
self.mac_nic = mac_nic
# if dev_type not in PortType:
# raise NotImplementedError("This type is NOT supported!")
self.net_type = net_type
self.created_by_vt = None

def to_dict(self):
return {
"uuid": self.uuid,
"name": self.name,
"network_uuid": self.network_uuid,
"vm_name": self.vm_name,
"mac_nic": self.mac_nic,
"net_type": self.net_type,
"created_by_vt": self.created_by_vt,
}

def create(self):
# TODO
# create the port
pass

def delete(self):
# TODO
# delete the port
pass

0 comments on commit 6adfc8c

Please sign in to comment.