mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
QEMU config disk - notification of import/export errors
(cherry picked from commit 50c49cfedb
)
This commit is contained in:
parent
750590d0db
commit
f747b3a880
@ -1667,12 +1667,10 @@ class QemuVM(BaseNode):
|
|||||||
mbr = img_file.read(512)
|
mbr = img_file.read(512)
|
||||||
part_type, offset, signature = struct.unpack("<450xB3xL52xH", mbr)
|
part_type, offset, signature = struct.unpack("<450xB3xL52xH", mbr)
|
||||||
if signature != 0xAA55:
|
if signature != 0xAA55:
|
||||||
log.error("mcopy failure: {}: invalid MBR".format(image))
|
raise OSError("mcopy failure: {}: invalid MBR".format(image))
|
||||||
return 1
|
|
||||||
if part_type not in (1, 4, 6, 11, 12, 14):
|
if part_type not in (1, 4, 6, 11, 12, 14):
|
||||||
log.error("mcopy failure: {}: invalid partition type {:02X}"
|
raise OSError("mcopy failure: {}: invalid partition type {:02X}"
|
||||||
.format(image, part_type))
|
.format(image, part_type))
|
||||||
return 1
|
|
||||||
part_image = image + "@@{}S".format(offset)
|
part_image = image + "@@{}S".format(offset)
|
||||||
|
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
@ -1683,15 +1681,13 @@ class QemuVM(BaseNode):
|
|||||||
(stdout, _) = await process.communicate()
|
(stdout, _) = await process.communicate()
|
||||||
retcode = process.returncode
|
retcode = process.returncode
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
log.error("mcopy failure: {}".format(e))
|
raise OSError("mcopy failure: {}".format(e))
|
||||||
return 1
|
|
||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
stdout = stdout.decode("utf-8").rstrip()
|
stdout = stdout.decode("utf-8").rstrip()
|
||||||
if stdout:
|
if stdout:
|
||||||
log.error("mcopy failure: {}".format(stdout))
|
raise OSError("mcopy failure: {}".format(stdout))
|
||||||
else:
|
else:
|
||||||
log.error("mcopy failure: return code {}".format(retcode))
|
raise OSError("mcopy failure: return code {}".format(retcode))
|
||||||
return retcode
|
|
||||||
|
|
||||||
async def _export_config(self):
|
async def _export_config(self):
|
||||||
disk_name = getattr(self, "config_disk_name")
|
disk_name = getattr(self, "config_disk_name")
|
||||||
@ -1707,10 +1703,11 @@ class QemuVM(BaseNode):
|
|||||||
os.mkdir(config_dir)
|
os.mkdir(config_dir)
|
||||||
if os.path.exists(zip_file):
|
if os.path.exists(zip_file):
|
||||||
os.remove(zip_file)
|
os.remove(zip_file)
|
||||||
if await self._mcopy(disk, "-s", "-m", "-n", "--", "::/", config_dir) == 0:
|
await self._mcopy(disk, "-s", "-m", "-n", "--", "::/", config_dir)
|
||||||
pack_zip(zip_file, config_dir)
|
pack_zip(zip_file, config_dir)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.error("Can't export config: {}".format(e))
|
log.warning("Can't export config: {}".format(e))
|
||||||
|
self.project.emit("log.warning", {"message": "{}: Can't export config: {}".format(self._name, e)})
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(config_dir, ignore_errors=True)
|
shutil.rmtree(config_dir, ignore_errors=True)
|
||||||
|
|
||||||
@ -1729,11 +1726,12 @@ class QemuVM(BaseNode):
|
|||||||
config_files = [os.path.join(config_dir, fname)
|
config_files = [os.path.join(config_dir, fname)
|
||||||
for fname in os.listdir(config_dir)]
|
for fname in os.listdir(config_dir)]
|
||||||
if config_files:
|
if config_files:
|
||||||
if await self._mcopy(disk, "-s", "-m", "-o", "--", *config_files, "::/") != 0:
|
await self._mcopy(disk, "-s", "-m", "-o", "--", *config_files, "::/")
|
||||||
os.remove(disk)
|
|
||||||
os.remove(zip_file)
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.error("Can't import config: {}".format(e))
|
log.warning("Can't import config: {}".format(e))
|
||||||
|
self.project.emit("log.warning", {"message": "{}: Can't import config: {}".format(self._name, e)})
|
||||||
|
if os.path.exists(disk):
|
||||||
|
os.remove(disk)
|
||||||
os.remove(zip_file)
|
os.remove(zip_file)
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(config_dir, ignore_errors=True)
|
shutil.rmtree(config_dir, ignore_errors=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user