mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
Allow to resize a Qemu VM disk (extend only).
This commit is contained in:
1 parent
6cec67f79f
commit
ff7911bd99
6 files changed
+148
-6
No files matched your search
@@ -296,7 +296,7 @@ class Qemu(BaseManager):
|
||||
raise QemuError("Could not create disk image {}:{}".format(path, e))
|
||||
|
||||
@asyncio.coroutine
|
||||
def resize_disk(self, qemu_img, path, size):
|
||||
def resize_disk(self, qemu_img, path, extend):
|
||||
"""
|
||||
Resize a Qemu disk with qemu-img
|
||||
|
||||
@@ -305,11 +305,17 @@ class Qemu(BaseManager):
|
||||
:param size: size
|
||||
"""
|
||||
|
||||
if not os.path.isabs(path):
|
||||
directory = self.get_images_directory()
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
path = os.path.join(directory, os.path.basename(path))
|
||||
|
||||
try:
|
||||
if not os.path.exists(path):
|
||||
raise QemuError("Qemu image '{}' does not exist".format(path))
|
||||
command = [qemu_img, "resize", path, "{}M".format(size)]
|
||||
raise QemuError("Qemu disk '{}' does not exist".format(path))
|
||||
command = [qemu_img, "resize", path, "+{}M".format(extend)]
|
||||
process = yield from asyncio.create_subprocess_exec(*command)
|
||||
yield from process.wait()
|
||||
log.info("Qemu disk '{}' extended by {} MB".format(path, extend))
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
raise QemuError("Could not create disk image {}:{}".format(path, e))
|
||||
raise QemuError("Could not update disk image {}:{}".format(path, e))
|
||||
@@ -1586,6 +1586,22 @@ class QemuVM(BaseNode):
|
||||
|
||||
return options
|
||||
|
||||
@asyncio.coroutine
|
||||
def resize_disk(self, drive_name, extend):
|
||||
|
||||
if self.is_running():
|
||||
raise QemuError("Cannot resize {} while the VM is running".format(drive_name))
|
||||
|
||||
if self.linked_clone:
|
||||
disk_image_path = os.path.join(self.working_dir, "{}_disk.qcow2".format(drive_name))
|
||||
else:
|
||||
disk_image_path = getattr(self, "{}_disk_image".format(drive_name))
|
||||
|
||||
if not os.path.exists(disk_image_path):
|
||||
raise QemuError("Disk path '{}' does not exist".format(disk_image_path))
|
||||
qemu_img_path = self._get_qemu_img()
|
||||
yield from self.manager.resize_disk(qemu_img_path, disk_image_path, extend)
|
||||
|
||||
def _cdrom_option(self):
|
||||
|
||||
options = []
|
||||
|
||||
Reference in new issue
Block a user