Docker init supports /etc/network/interfaces

* Generate an /etc/network/interfaces
* Use busybox also for aux console

Ref #460
This commit is contained in:
Julien Duponchelle committed 2016-03-24 17:10:53 +01:00
1 parent 268c61ce80
commit e6ddce86b3
4 files changed
+78 -14

No files matched your search

+36 -2
View File
@@ -159,6 +159,10 @@ class DockerVM(BaseVM):
binds.append("{}:/gns3:ro".format(get_resource("modules/docker/resources")))
# We mount our own etc/network
network_config = self._create_network_config()
binds.append("{}:/etc/network:rw".format(network_config))
volumes = image_infos.get("ContainerConfig", {}).get("Volumes")
if volumes is None:
return binds
@@ -169,6 +173,37 @@ class DockerVM(BaseVM):
return binds
def _create_network_config(self):
"""
If network config is empty we create a sample config
"""
path = os.path.join(self.working_dir, "etc", "network")
os.makedirs(path, exist_ok=True)
os.makedirs(os.path.join(path, "if-up.d"))
os.makedirs(os.path.join(path, "if-down.d"))
if not os.path.exists(os.path.join(path, "interfaces")):
with open(os.path.join(path, "interfaces"), "w+") as f:
f.write("""#
# This is a sample network config uncomment lines to configure the network
#
""")
for adapter in range(0, self.adapters):
f.write("""
# Static config for eth{adapter}
#auto eth{adapter}
#iface eth{adapter} inet static
#\taddress 192.168.{adapter}.2
#\tnetmask 255.255.255.0
#\tgateway 192.168.{adapter}.1
#\tup echo nameserver 192.168.{adapter}.1 > /etc/resolv.conf
# DHCP config for eth{adapter}
# auto eth{adapter}
# iface eth{adapter} inet dhcp""".format(adapter=adapter))
return path
@asyncio.coroutine
def create(self):
"""Creates the Docker container."""
@@ -199,7 +234,6 @@ class DockerVM(BaseVM):
"Entrypoint": image_infos.get("Config", {"Entrypoint": []})["Entrypoint"]
}
if params["Entrypoint"] is None:
params["Entrypoint"] = []
if self._start_command:
@@ -287,7 +321,7 @@ class DockerVM(BaseVM):
# We can not use the API because docker doesn't expose a websocket api for exec
# https://github.com/GNS3/gns3-gui/issues/1039
process = yield from asyncio.subprocess.create_subprocess_exec(
"docker", "exec", "-i", self._cid, "/bin/sh", "-i",
"docker", "exec", "-i", self._cid, "/gns3/bin/busybox", "sh", "-i",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
stdin=asyncio.subprocess.PIPE)
Binary file not shown.
+2 -6
View File
@@ -52,12 +52,8 @@ sed -n 's/^ *\(eth[0-9]*\):.*/\1/p' < /proc/net/dev | while read dev; do
ip link set dev $dev up
done
if [ -n "$INTERFACES" ]; then
mkdir -p /etc/network/if-up.d /etc/network/if-pre-up.d
mkdir -p /etc/network/if-down.d /etc/network/if-post-down.d
echo -e "$INTERFACES" > /etc/network/interfaces
ifup -a -f
fi
ifup -a -f
# continue normal docker startup
PATH="$OLD_PATH"