diff --git a/daemon/core/nodes/netclient.py b/daemon/core/nodes/netclient.py index 398eacde..908f8bc8 100644 --- a/daemon/core/nodes/netclient.py +++ b/daemon/core/nodes/netclient.py @@ -90,15 +90,6 @@ def address_show(self, device: str) -> str: """ return self.run_net(f"{IP} address show {device}") - def get_mac(self, device: str) -> str: - """ - Retrieve MAC address for a given device. - - :param device: device to get mac for - :return: MAC address - """ - return self.run(f"cat /sys/class/net/{device}/address") - def get_ifindex(self, device: str) -> int: """ Retrieve ifindex for a given device. @@ -183,7 +174,7 @@ def create_address(self, device: str, address: str, broadcast: str = None) -> No # IPv6 addresses are removed by default on interface down. # Make sure that the IPv6 address we add is not removed device = utils.sysctl_devname(device) - self.run(f"{SYSCTL} -w net.ipv6.conf.{device}.keep_addr_on_down=1") + self.run_net(f"{SYSCTL} -w net.ipv6.conf.{device}.keep_addr_on_down=1") def delete_address(self, device: str, address: str) -> None: """ diff --git a/daemon/core/nodes/podman.py b/daemon/core/nodes/podman.py index 9a34c610..3d58bb93 100644 --- a/daemon/core/nodes/podman.py +++ b/daemon/core/nodes/podman.py @@ -8,10 +8,12 @@ from mako.template import Template +from core import utils from core.emulator.distributed import DistributedServer 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__) @@ -97,6 +99,16 @@ def create_options(cls) -> PodmanOptions: """ return PodmanOptions() + 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. @@ -109,6 +121,35 @@ def create_cmd(self, args: str, shell: bool = False) -> str: args = f"{BASH} -c {shlex.quote(args)}" return f"{PODMAN} exec {self.name} {args}" + 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 + """ + if shell: + args = f"{BASH} -c {shlex.quote(args)}" + return f"nsenter -t {self.pid} -n -- {args}" + + 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 _unique_name(self, name: str) -> str: """ Creates a session/node unique prefixed name for the provided input.