Skip to content

Commit

Permalink
daemon: adjustments to podman nodes to use network namespaced only co…
Browse files Browse the repository at this point in the history
…mmands for network setup
  • Loading branch information
bharnden committed Dec 13, 2023
1 parent 094790a commit d5a2e5a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
11 changes: 1 addition & 10 deletions daemon/core/nodes/netclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
"""
Expand Down
41 changes: 41 additions & 0 deletions daemon/core/nodes/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit d5a2e5a

Please sign in to comment.