mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge pull request #1597 from kazkansouh/2.2-fix-1595-volumes
Fix for issue #1595
This commit is contained in:
2 files changed
+215
-26
No files matched your search
@@ -248,27 +248,32 @@ class DockerVM(BaseNode):
|
||||
|
||||
# We mount our own etc/network
|
||||
try:
|
||||
network_config = self._create_network_config()
|
||||
self._create_network_config()
|
||||
except OSError as e:
|
||||
raise DockerError("Could not create network config in the container: {}".format(e))
|
||||
binds.append("{}:/gns3volumes/etc/network:rw".format(network_config))
|
||||
volumes = ["/etc/network"]
|
||||
|
||||
self._volumes = ["/etc/network"]
|
||||
volumes = list((image_info.get("Config", {}).get("Volumes") or {}).keys())
|
||||
volumes.extend((image_info.get("Config", {}).get("Volumes") or {}).keys())
|
||||
for volume in self._extra_volumes:
|
||||
if not volume.strip() or volume[0] != "/" or volume.find("..") >= 0:
|
||||
raise DockerError("Persistent volume '{}' has invalid format. It must start with a '/' and not contain '..'.".format(volume))
|
||||
volumes.extend(self._extra_volumes)
|
||||
|
||||
self._volumes = []
|
||||
# define lambdas for validation checks
|
||||
nf = lambda x: re.sub(r"//+", "/", (x if x.endswith("/") else x + "/"))
|
||||
incompatible = lambda v1, v2: nf(v1).startswith(nf(v2)) or nf(v2).startswith(nf(v1))
|
||||
generalises = lambda v1, v2: nf(v2).startswith(nf(v1))
|
||||
for volume in volumes:
|
||||
if [ v for v in self._volumes if incompatible(v, volume) ] :
|
||||
raise DockerError("Duplicate persistent volume {} detected.\n\nVolumes specified in docker image as well as user specified persistent volumes must be unique.".format(volume))
|
||||
# remove any mount that is equal or more specific, then append this one
|
||||
self._volumes = list(filter(lambda v: not generalises(volume, v), self._volumes))
|
||||
# if there is nothing more general, append this mount
|
||||
if not [ v for v in self._volumes if generalises(v, volume) ] :
|
||||
self._volumes.append(volume)
|
||||
|
||||
for volume in self._volumes:
|
||||
source = os.path.join(self.working_dir, os.path.relpath(volume, "/"))
|
||||
os.makedirs(source, exist_ok=True)
|
||||
binds.append("{}:/gns3volumes{}".format(source, volume))
|
||||
self._volumes.append(volume)
|
||||
|
||||
return binds
|
||||
|
||||
|
||||
Reference in new issue
Block a user