Node Classes

A module that defines objects for standalone use.

exception munet.native.L3ContainerNotRunningError

Exception if no running container exists.

async munet.native.to_thread(func)

to_thread for python < 3.9.

class munet.native.ExternalNetwork(name=None, unet=None, logger=None, mtu=None, config=None)

A network external to munet.

class munet.native.L2Bridge(name=None, unet=None, logger=None, mtu=None, config=None)

A linux bridge with no IP network address.

class munet.native.L3Bridge(name=None, unet=None, logger=None, mtu=None, config=None)

A linux bridge with associated IP network address.

class munet.native.NodeMixin(*args, config=None, **kwargs)

Node attributes and functionality.

async run_cmd()

Run the configured commands for this node.

async async_cleanup_cmd()

Run the configured cleanup commands for this node.

async async_ready_cmd()

Run the configured ready commands for this node.

pytest_hook_run_cmd(stdout, stderr)

Handle pytest options related to running the node cmd.

This function does things such as launch tail’ing windows on the given files if requested by the user.

Parameters:
  • stdout – file-like object with a name attribute, or a path to a file.

  • stderr – file-like object with a name attribute, or a path to a file.

class munet.native.HostnetNode(name, pid=True, **kwargs)

A node for running commands in the host network namespace.

class munet.native.SSHRemote(name, **kwargs)

SSHRemote a node representing an ssh connection to something.

class munet.native.L3NodeMixin(*args, unet=None, **kwargs)

A linux namespace with IP attributes.

add_watch_log(path, watchfor_re=None)

Add a WatchLog to this nodes watched logs.

Parameters:
  • path – If relative is relative to the nodes rundir

  • watchfor_re – Regular expression to watch the log for and raise an exception if found.

Returns:

The watching task if request or None otherwise.

async console(concmd, prompt='(^|\\r?\\n)[^#\\$]*[#\\$] ', is_bourne=True, user=None, password=None, expects=None, sends=None, use_pty=False, will_echo=False, logfile_prefix='console', trace=True, **kwargs)

Create a REPL (read-eval-print-loop) driving a console.

Parameters:
  • concmd – string or list to popen with, or an already open socket

  • prompt – the REPL prompt to look for, the function returns when seen

  • is_bourne – True if the console is a bourne shell

  • user – user name to log in with

  • password – password to log in with

  • expects – a list of regex other than the prompt, the standard user, or password to look for. “ogin:” or “[Pp]assword:”r.

  • sends – what to send when an element of expects matches. Can be the empty string to send nothing.

  • use_pty – true for pty based expect, otherwise uses popen (pipes/files)

  • will_echo – bash is buggy in that it echo’s to non-tty unlike any other sh/ksh, set this value to true if running back

  • logfile_prefix – prefix for 3 logfiles opened to track the console i/o

  • trace – trace the send/expect sequence

  • **kwargs – kwargs passed on the _spawn.

async add_phy_intf(devaddr, lname)

Add a physical inteface (i.e. mv it to vfio-pci driver.

This is primarily useful for Qemu, but also for things like TREX or DPDK

async rem_phy_intf(devaddr)

Remove a physical inteface (i.e. mv it away from vfio-pci driver.

This is primarily useful for Qemu, but also for things like TREX or DPDK

class munet.native.L3NamespaceNode(name, pid=True, **kwargs)

A namespace L3 node.

class munet.native.L3ContainerNode(name, config, **kwargs)

An container (podman) based L3 node.

get_exec_path(binary)

Return the full path to the binary executable inside the image.

binary :: binary name or list of binary names

async async_get_exec_path(binary)

Return the full path to the binary executable inside the image.

binary :: binary name or list of binary names

get_exec_path_host(binary)

Return the full path to the binary executable on the host.

binary :: binary name or list of binary names

async run_cmd()

Run the configured commands for this node.

async async_cleanup_cmd()

Run the configured cleanup commands for this node.

class munet.native.L3QemuVM(name, config, **kwargs)

An VM (qemu) based L3 node.

async moncmd()

Uses internal REPL to send cmmand to qemu monitor and get reply.

mount_volumes()

Mount volumes from the config.

async run_cmd()

Run the configured commands for this node.

get_ns_ifname(ifname)

Return a namespace unique interface name.

This function is primarily overriden by L3QemuVM, IOW by any class that doesn’t create it’s own network namespace and will share that with the root (unet) namespace.

Parameters:

ifname – the interface name.

Returns:

A name unique to the namespace of this object. By defualt the assumption is the ifname is namespace unique.

async mount_mounts()

Mount any shared directories.

async renumber_interfaces()

Re-number the interfaces.

After VM comes up need to renumber the interfaces now on the inside.

async launch()

Launch qemu.

async async_cleanup_cmd()

Run the configured cleanup commands for this node.

class munet.native.Munet(rundir=None, config=None, pid=True, logger=None, **kwargs)

Munet.

__del__()

Catch case of build object but not async_deleted.

Add a link between switch and node or 2 nodes.

add_l3_node(name, config=None, **kwargs)

Add a node to munet.

add_network(name, config=None, **kwargs)

Add a l2 or l3 switch to munet.