-
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 system. Signed-off-by: Houqi (Nick) Zuo <[email protected]>
- Loading branch information
Showing
5 changed files
with
181 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
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,113 @@ | ||
""" | ||
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 create_network(self, network_name, params): | ||
""" | ||
Create the network by its cartesian params. | ||
:param network_name: The network tag defined in cartesian params. | ||
:type network_name: String. | ||
:param params: The params for all the network. | ||
:type params: Dict. | ||
""" | ||
network_obj = nt.Network(network_name, params) | ||
network_obj.create() | ||
self._networks.append(network_obj) | ||
|
||
def delete_network(self, descriptor): | ||
""" | ||
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 get_networks(self, descriptor): | ||
""" | ||
Filter the networks based on the descriptor. | ||
NOTE: return all networks if descriptor is None. | ||
:param descriptor: The network name or the uuid. | ||
:type descriptor: String. | ||
""" | ||
if not descriptor: | ||
return self._networks | ||
res = [] | ||
for obj in self._networks: | ||
if descriptor in (obj.uuid, obj.name, ): | ||
res.append(obj) | ||
return res | ||
|
||
def create_port(self, name, network_uuid, mac_addr, dev_type): | ||
""" | ||
Create the port by its cartesian params. | ||
:param name: The network tag defined in cartesian params. | ||
:type name: String. | ||
:param network_uuid: The uuid of the network. | ||
:type network_uuid: String. | ||
:param mac_addr: The mac address. | ||
:type mac_addr: String. | ||
:param dev_type: The device type. | ||
:type dev_type: String. | ||
""" | ||
network_obj = port.Port(name, network_uuid, mac_addr, dev_type) | ||
network_obj.create() | ||
self._networks.append(network_obj) | ||
|
||
def delete_port(self): | ||
pass | ||
|
||
def get_ports(self, descriptor): | ||
""" | ||
Filter the networks based on the descriptor. | ||
NOTE: return all networks if descriptor is None. | ||
:param descriptor: The network name or the uuid. | ||
:type descriptor: String. | ||
""" | ||
if not descriptor: | ||
return self._ports | ||
res = [] | ||
for obj in self._ports: | ||
if descriptor in (obj.uuid, obj.name, obj.mac_addr, | ||
obj.network_uuid, ): | ||
res.append(obj) | ||
return res | ||
|
||
|
||
vt_netmgr = _VTNetworkManager() |
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,13 @@ | ||
from enum import Enum | ||
|
||
|
||
class PortType(Enum): | ||
customized = 0 | ||
tap = 1 | ||
bridge = 2 | ||
ovs = 3 | ||
passt = 4 | ||
sriov = 5 | ||
vhost_vdpa = 6 | ||
vhost_user = 7 | ||
user = 8 |
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, params): | ||
self.uuid = uuid.uuid4().hex | ||
self.name = name | ||
self._type = params["type"] | ||
self._spec = 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,26 @@ | ||
from abc import ABC | ||
import uuid | ||
|
||
from virttest.vt_resmgr.resources.network import PortType | ||
|
||
|
||
class Port(ABC): | ||
def __init__(self, name, network_uuid, mac_addr, dev_type): | ||
self.uuid = uuid.uuid4().hex | ||
self.name = name | ||
self.network_uuid = network_uuid | ||
self.mac_addr = mac_addr | ||
if dev_type not in PortType: | ||
raise NotImplementedError("This type is NOT supported!") | ||
self.type = dev_type | ||
self.created_by_vt = None | ||
|
||
def create(self): | ||
# TODO | ||
# create the port | ||
pass | ||
|
||
def delete(self): | ||
# TODO | ||
# delete the port | ||
pass |