8000 Add the ability to have docker nodes connect to a docker network by Ktmi · Pull Request #2 · italovalcy/mininet · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions mininet/nodelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DockerNode( Node ):

def __init__(
self, name, image=None, publish=None, volume=None, env=None,
pull="missing", **kwargs
pull="missing", docker_network=None, **kwargs
):
"""
Create a DockerNode based on the provided parameters:
Expand All @@ -196,11 +196,12 @@ def __init__(
self.volume = volume
self.env = env
self.pull = pull
self.docker_network = docker_network
kwargs["inNamespace"] = True
super().__init__(name, **kwargs)
if not DockerNode.initialized:
DockerNode.initilize()
DockerNode.initialized = True
super().__init__(name, **kwargs)

@classmethod
def initilize(cls):
Expand Down Expand Up @@ -259 8000 ,7 +260,7 @@ def terminate( self ):
time.sleep(1)
quietRun(f"docker rm -f {self.name}")

# pylint: disable=too-many-branches,consider-using-with
# pylint: disable=too-many-branches,consider-using-with,too-many-statements
def startShell( self, mnopts=None ):
"""Start shell for node by running docker in foreground."""
args = [
Expand Down Expand Up @@ -338,6 +339,16 @@ def startShell( self, mnopts=None ):
" ip command."
)

if self.docker_network:
connect_cmd = [
"docker", "network", "connect", self.docker_network, self.name,
]
subprocess.run(
connect_cmd,
capture_output=True,
check=True,
)

@classmethod
def clean_up(cls):
"""Bulk clean up any docker container left over."""
Expand Down
Loading
0