-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add network system of multi-host migration
add support for network subsystem. Signed-off-by: Houqi (Nick) Zuo <[email protected]>
- Loading branch information
Showing
6 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .vt_netmgr import vt_netmgr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |