mirror of
https://github.com/GNS3/gns3-registry.git
synced 2024-12-18 20:37:57 +00:00
Image path relatives to image directory
This commit is contained in:
parent
56a071f8f9
commit
ef2ae9e4c3
@ -133,7 +133,7 @@ class Config:
|
||||
raise ConfigException("Missing image for {} you should provide one of the following images:\n{}".format(disk, require_images))
|
||||
else:
|
||||
new_config["name"] += " {}".format(device_config["images"][disk].version)
|
||||
new_config[disk] = device_config["images"][disk].path
|
||||
new_config[disk] = self._relative_image_path(device_config["images"][disk].path)
|
||||
|
||||
|
||||
if device_config["qemu"].get("install_cdrom_to_hda", False):
|
||||
@ -147,6 +147,16 @@ class Config:
|
||||
|
||||
self._config["Qemu"]["vms"].append(new_config)
|
||||
|
||||
def _relative_image_path(self, path):
|
||||
"""
|
||||
:returns: Path relative to image directory if image is inside or full path
|
||||
"""
|
||||
print(os.path.dirname(path))
|
||||
print(self.images_dir)
|
||||
if os.path.dirname(path) == self.images_dir:
|
||||
return os.path.basename(path)
|
||||
return path
|
||||
|
||||
def _get_qemu_binary(self, device_config):
|
||||
"""
|
||||
Create a blank hda disk image
|
||||
|
@ -27,17 +27,10 @@ class Image:
|
||||
"""
|
||||
:params: path of the image
|
||||
"""
|
||||
self._path = path
|
||||
self.path = path
|
||||
self._md5sum = None
|
||||
self._version = None
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
"""
|
||||
:returns: Image path
|
||||
"""
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""
|
||||
@ -62,7 +55,7 @@ class Image:
|
||||
|
||||
if self._md5sum is None:
|
||||
m = hashlib.md5()
|
||||
with open(self._path, "rb") as f:
|
||||
with open(self.path, "rb") as f:
|
||||
while True:
|
||||
buf = f.read(4096)
|
||||
if not buf:
|
||||
|
@ -226,6 +226,18 @@ def test_add_images_two_disk_one_missing(empty_config):
|
||||
assert len(empty_config._config["Qemu"]["vms"]) == 0
|
||||
|
||||
|
||||
def test_add_image_path_relative_to_images_dir(empty_config, tmpdir, linux_microcore_img):
|
||||
with open("devices/microcore-linux.json") as f:
|
||||
config = json.load(f)
|
||||
image = Image(linux_microcore_img)
|
||||
image.version = "3.4.1"
|
||||
image.path = str(tmpdir / "linux-microcore-3.4.1.img")
|
||||
|
||||
config["images"]["hda_disk_image"] = image
|
||||
empty_config.add_images(config)
|
||||
assert empty_config._config["Qemu"]["vms"][0]["hda_disk_image"] == "linux-microcore-3.4.1.img"
|
||||
|
||||
|
||||
def test_save(empty_config, linux_microcore_img):
|
||||
|
||||
with open("devices/microcore-linux.json") as f:
|
||||
|
Loading…
Reference in New Issue
Block a user