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 system.

Signed-off-by: Houqi (Nick) Zuo <[email protected]>
  • Loading branch information
nickzhq committed Aug 31, 2024
1 parent 8173682 commit 4573d72
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
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
113 changes: 113 additions & 0 deletions virttest/vt_netmgr/vt_netmgr.py
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()
13 changes: 13 additions & 0 deletions virttest/vt_resmgr/resources/network/__init__.py
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
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, 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
26 changes: 26 additions & 0 deletions virttest/vt_resmgr/resources/network/port.py
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

0 comments on commit 4573d72

Please sign in to comment.