mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-01 04:38:12 +00:00
Allows hot-linking for Docker containers. Ref #267.
This commit is contained in:
parent
ce3276d374
commit
d28fad223f
@ -292,7 +292,7 @@ class DockerVM(BaseNode):
|
|||||||
params["Cmd"] = []
|
params["Cmd"] = []
|
||||||
if len(params["Cmd"]) == 0 and len(params["Entrypoint"]) == 0:
|
if len(params["Cmd"]) == 0 and len(params["Entrypoint"]) == 0:
|
||||||
params["Cmd"] = ["/bin/sh"]
|
params["Cmd"] = ["/bin/sh"]
|
||||||
params["Entrypoint"].insert(0, "/gns3/init.sh")
|
params["Entrypoint"].insert(0, "/gns3/init.sh") # FIXME /gns3/init.sh is not found?
|
||||||
|
|
||||||
# Give the information to the container on how many interface should be inside
|
# Give the information to the container on how many interface should be inside
|
||||||
params["Env"].append("GNS3_MAX_ETHERNET=eth{}".format(self.adapters - 1))
|
params["Env"].append("GNS3_MAX_ETHERNET=eth{}".format(self.adapters - 1))
|
||||||
@ -663,11 +663,8 @@ class DockerVM(BaseNode):
|
|||||||
|
|
||||||
:param adapter_number: adapter number
|
:param adapter_number: adapter number
|
||||||
"""
|
"""
|
||||||
if not self._ubridge_hypervisor or not self._ubridge_hypervisor.is_running():
|
|
||||||
return
|
|
||||||
|
|
||||||
adapter = self._ethernet_adapters[adapter_number]
|
adapter = self._ethernet_adapters[adapter_number]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield from self._ubridge_send("bridge delete bridge{name}".format(name=adapter_number))
|
yield from self._ubridge_send("bridge delete bridge{name}".format(name=adapter_number))
|
||||||
except UbridgeError as e:
|
except UbridgeError as e:
|
||||||
@ -695,6 +692,18 @@ class DockerVM(BaseNode):
|
|||||||
raise DockerError("Adapter {adapter_number} doesn't exist on Docker container '{name}'".format(name=self.name,
|
raise DockerError("Adapter {adapter_number} doesn't exist on Docker container '{name}'".format(name=self.name,
|
||||||
adapter_number=adapter_number))
|
adapter_number=adapter_number))
|
||||||
|
|
||||||
|
if self.status == "started" and self.ubridge and self.ubridge.is_running():
|
||||||
|
# the container is running, let's add the UDP tunnel to connect to another node
|
||||||
|
yield from self._ubridge_send('bridge create bridge{}'.format(adapter_number))
|
||||||
|
yield from self._ubridge_send('bridge add_nio_linux_raw bridge{adapter} {ifc}'.format(ifc=adapter.host_ifc, adapter=adapter_number))
|
||||||
|
|
||||||
|
yield from self._ubridge_send('bridge add_nio_udp bridge{adapter} {lport} {rhost} {rport}'.format(adapter=adapter_number,
|
||||||
|
lport=nio.lport,
|
||||||
|
rhost=nio.rhost,
|
||||||
|
rport=nio.rport))
|
||||||
|
|
||||||
|
yield from self._ubridge_send('bridge start bridge{adapter}'.format(adapter=adapter_number))
|
||||||
|
|
||||||
adapter.add_nio(0, nio)
|
adapter.add_nio(0, nio)
|
||||||
log.info("Docker container '{name}' [{id}]: {nio} added to adapter {adapter_number}".format(name=self.name,
|
log.info("Docker container '{name}' [{id}]: {nio} added to adapter {adapter_number}".format(name=self.name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
@ -717,6 +726,11 @@ class DockerVM(BaseNode):
|
|||||||
adapter_number=adapter_number))
|
adapter_number=adapter_number))
|
||||||
|
|
||||||
adapter.remove_nio(0)
|
adapter.remove_nio(0)
|
||||||
|
if self.status == "started" and self.ubridge and self.ubridge.is_running():
|
||||||
|
# the container is running, just delete the UDP tunnel so we can reconnect it later if needed
|
||||||
|
yield from self._ubridge_send("bridge delete bridge{name}".format(name=adapter_number))
|
||||||
|
else:
|
||||||
|
# the container is not running, let's completely delete the connection
|
||||||
yield from self._delete_ubridge_connection(adapter_number)
|
yield from self._delete_ubridge_connection(adapter_number)
|
||||||
|
|
||||||
log.info("Docker VM '{name}' [{id}]: {nio} removed from adapter {adapter_number}".format(name=self.name,
|
log.info("Docker VM '{name}' [{id}]: {nio} removed from adapter {adapter_number}".format(name=self.name,
|
||||||
@ -829,7 +843,7 @@ class DockerVM(BaseNode):
|
|||||||
|
|
||||||
nio.startPacketCapture(output_file)
|
nio.startPacketCapture(output_file)
|
||||||
|
|
||||||
if self.status == "started":
|
if self.status == "started" and self.ubridge and self.ubridge.is_running():
|
||||||
yield from self._start_ubridge_capture(adapter_number, output_file)
|
yield from self._start_ubridge_capture(adapter_number, output_file)
|
||||||
|
|
||||||
log.info("Docker VM '{name}' [{id}]: starting packet capture on adapter {adapter_number}".format(name=self.name,
|
log.info("Docker VM '{name}' [{id}]: starting packet capture on adapter {adapter_number}".format(name=self.name,
|
||||||
@ -856,7 +870,7 @@ class DockerVM(BaseNode):
|
|||||||
|
|
||||||
nio.stopPacketCapture()
|
nio.stopPacketCapture()
|
||||||
|
|
||||||
if self.status == "started":
|
if self.status == "started" and self.ubridge and self.ubridge.is_running():
|
||||||
yield from self._stop_ubridge_capture(adapter_number)
|
yield from self._stop_ubridge_capture(adapter_number)
|
||||||
|
|
||||||
log.info("Docker VM '{name}' [{id}]: stopping packet capture on adapter {adapter_number}".format(name=self.name,
|
log.info("Docker VM '{name}' [{id}]: stopping packet capture on adapter {adapter_number}".format(name=self.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user