Skip to content

Commit

Permalink
daemon: adjustments to clean up the new net commands for nodes, will …
Browse files Browse the repository at this point in the history
…now function with ovs mode as well
  • Loading branch information
bharnden committed Dec 13, 2023
1 parent a64c685 commit ceec619
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 122 deletions.
73 changes: 46 additions & 27 deletions daemon/core/nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,19 @@ def __init__(
self.net_client: LinuxNetClient = get_net_client(
self.session.use_ovs(), self.host_cmd
)
self.node_net_client: LinuxNetClient = self._get_node_net_client()
options = options if options else NodeOptions()
self.canvas: Optional[int] = options.canvas
self.icon: Optional[str] = options.icon

def _get_node_net_client(self) -> LinuxNetClient:
"""
Create and return network command client to run within context of the node.
:return: network command client
"""
return get_net_client(self.session.use_ovs(), self.cmd)

@classmethod
def create_options(cls) -> NodeOptions:
return NodeOptions()
Expand Down Expand Up @@ -228,19 +237,6 @@ def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
"""
return self.host_cmd(args, wait=wait, shell=shell)

def net_cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
"""
Runs a network command that is in the context of a node, default is to run a
standard host command.
:param args: command to run
:param wait: True to wait for status, False otherwise
:param shell: True to use shell, False otherwise
:return: combined stdout and stderr
:raises CoreCommandError: when a non-zero exit status occurs
"""
return self.cmd(args, wait, shell)

def setposition(self, x: float = None, y: float = None, z: float = None) -> bool:
"""
Set the (x,y,z) position of the object.
Expand Down Expand Up @@ -590,9 +586,6 @@ def __init__(
self.ctrlchnlname: Path = self.session.directory / self.name
self.pid: Optional[int] = None
self._mounts: list[tuple[Path, Path]] = []
self.node_net_client: LinuxNetClient = self.create_node_net_client(
self.session.use_ovs()
)
options = options or CoreNodeOptions()
self.model: Optional[str] = options.model
# add services
Expand All @@ -609,19 +602,17 @@ def __init__(
service_class = self.session.service_manager.get_service(name)
self.add_service(service_class)

@classmethod
def create_options(cls) -> CoreNodeOptions:
return CoreNodeOptions()

def create_node_net_client(self, use_ovs: bool) -> LinuxNetClient:
def _get_node_net_client(self) -> LinuxNetClient:
"""
Create node network client for running network commands within the nodes
container.
Create and return network command client to run within context of the node.
:param use_ovs: True for OVS bridges, False for Linux bridges
:return: node network client
:return: network command client
"""
return get_net_client(use_ovs, self.cmd)
return get_net_client(self.session.use_ovs(), self.net_cmd)

@classmethod
def create_options(cls) -> CoreNodeOptions:
return CoreNodeOptions()

def alive(self) -> bool:
"""
Expand Down Expand Up @@ -665,7 +656,8 @@ def startup(self) -> None:
self.node_net_client.device_up("lo")
# set hostname for node
logger.debug("setting hostname: %s", self.name)
self.node_net_client.set_hostname(self.name)
hostname = self.name.replace("_", "-")
self.cmd(f"hostname {hostname}")
# mark node as up
self.up = True
# create private directories
Expand Down Expand Up @@ -740,6 +732,33 @@ def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
else:
return self.server.remote_cmd(args, wait=wait)

def create_net_cmd(self, args: str, shell: bool = False) -> str:
"""
Create command used to run network commands within the context of a node.
:param args: command arguments
:param shell: True to run shell like, False otherwise
:return: node command
"""
return self.create_cmd(args, shell)

def net_cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
"""
Runs a command that is used to configure and setup the network within a
node.
:param args: command to run
:param wait: True to wait for status, False otherwise
:param shell: True to use shell, False otherwise
:return: combined stdout and stderr
:raises CoreCommandError: when a non-zero exit status occurs
"""
args = self.create_net_cmd(args, shell)
if self.server is None:
return utils.cmd(args, wait=wait, shell=shell)
else:
return self.server.remote_cmd(args, wait=wait)

def path_exists(self, path: str) -> bool:
"""
Determines if a file or directory path exists.
Expand Down
11 changes: 0 additions & 11 deletions daemon/core/nodes/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from core.errors import CoreCommandError, CoreError
from core.executables import BASH
from core.nodes.base import CoreNode, CoreNodeOptions
from core.nodes.netclient import LinuxNetClient, get_net_client

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -100,16 +99,6 @@ def create_options(cls) -> DockerOptions:
"""
return DockerOptions()

def create_node_net_client(self, use_ovs: bool) -> LinuxNetClient:
"""
Create node network client for running network commands within the nodes
container.
:param use_ovs: True for OVS bridges, False for Linux bridges
:return: node network client
"""
return get_net_client(use_ovs, self.cmd, self.net_cmd)

def create_cmd(self, args: str, shell: bool = False) -> str:
"""
Create command used to run commands within the context of a node.
Expand Down
4 changes: 2 additions & 2 deletions daemon/core/nodes/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ def set_config(self) -> None:
if self.has_netem:
cmd = tc_clear_cmd(self.name)
if self.node:
self.node.net_cmd(cmd)
self.node.node_net_client.run(cmd)
else:
self.host_cmd(cmd)
self.has_netem = False
# set updated settings
else:
cmd = tc_cmd(self.name, self.options, self.mtu)
if self.node:
self.node.net_cmd(cmd)
self.node.node_net_client.run(cmd)
else:
self.host_cmd(cmd)
self.has_netem = True
Expand Down
Loading

0 comments on commit ceec619

Please sign in to comment.