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
This commit is contained in:
parent
50c49cfedb
commit
2bbee15b18
@ -27,10 +27,13 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from ...utils.asyncio import subprocess_check_output
|
from ...utils.asyncio import subprocess_check_output
|
||||||
|
from ...utils.get_resource import get_resource
|
||||||
from ..base_manager import BaseManager
|
from ..base_manager import BaseManager
|
||||||
|
from ..error import NodeError, ImageMissingError
|
||||||
from .qemu_error import QemuError
|
from .qemu_error import QemuError
|
||||||
from .qemu_vm import QemuVM
|
from .qemu_vm import QemuVM
|
||||||
from .utils.guest_cid import get_next_guest_cid
|
from .utils.guest_cid import get_next_guest_cid
|
||||||
|
from .utils.ziputils import unpack_zip
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -45,6 +48,7 @@ class Qemu(BaseManager):
|
|||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._guest_cid_lock = asyncio.Lock()
|
self._guest_cid_lock = asyncio.Lock()
|
||||||
|
self._init_config_disk()
|
||||||
|
|
||||||
async def create_node(self, *args, **kwargs):
|
async def create_node(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -343,3 +347,24 @@ class Qemu(BaseManager):
|
|||||||
log.info("Qemu disk '{}' extended by {} MB".format(path, extend))
|
log.info("Qemu disk '{}' extended by {} MB".format(path, extend))
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Could not update disk image {}:{}".format(path, e))
|
raise QemuError("Could not update disk image {}:{}".format(path, e))
|
||||||
|
|
||||||
|
def _init_config_disk(self):
|
||||||
|
"""
|
||||||
|
Initialize the default config disk
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.config_disk = "config.img"
|
||||||
|
try:
|
||||||
|
self.get_abs_image_path(self.config_disk)
|
||||||
|
except (NodeError, ImageMissingError) as e:
|
||||||
|
config_disk_zip = get_resource("compute/qemu/resources/{}.zip"
|
||||||
|
.format(self.config_disk))
|
||||||
|
if config_disk_zip and os.path.exists(config_disk_zip):
|
||||||
|
directory = self.get_images_directory()
|
||||||
|
try:
|
||||||
|
unpack_zip(config_disk_zip, directory)
|
||||||
|
except OSError as e:
|
||||||
|
log.warning("Config disk creation: {}".format(e))
|
||||||
|
else:
|
||||||
|
log.warning("Config disk: image '{}' missing"
|
||||||
|
.format(self.config_disk))
|
||||||
|
@ -46,7 +46,6 @@ from ..nios.nio_tap import NIOTAP
|
|||||||
from ..base_node import BaseNode
|
from ..base_node import BaseNode
|
||||||
from ...schemas.qemu import QEMU_OBJECT_SCHEMA, QEMU_PLATFORMS
|
from ...schemas.qemu import QEMU_OBJECT_SCHEMA, QEMU_PLATFORMS
|
||||||
from ...utils.asyncio import monitor_process
|
from ...utils.asyncio import monitor_process
|
||||||
from ...utils.get_resource import get_resource
|
|
||||||
from ...utils.images import md5sum
|
from ...utils.images import md5sum
|
||||||
from ...utils import macaddress_to_int, int_to_macaddress
|
from ...utils import macaddress_to_int, int_to_macaddress
|
||||||
|
|
||||||
@ -130,31 +129,19 @@ class QemuVM(BaseNode):
|
|||||||
self.adapters = 1 # creates 1 adapter by default
|
self.adapters = 1 # creates 1 adapter by default
|
||||||
|
|
||||||
# config disk
|
# config disk
|
||||||
config_disk_name = "config.img"
|
self.config_disk_name = self.manager.config_disk
|
||||||
self.config_disk_name = ""
|
|
||||||
self.config_disk_image = ""
|
self.config_disk_image = ""
|
||||||
if not shutil.which("mcopy"):
|
if not shutil.which("mcopy"):
|
||||||
log.warning("Config disk: 'mtools' are not installed.")
|
log.warning("Config disk: 'mtools' are not installed.")
|
||||||
|
self.config_disk_name = ""
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.config_disk_image = self.manager.get_abs_image_path(
|
self.config_disk_image = self.manager.get_abs_image_path(
|
||||||
config_disk_name, self.project.path)
|
self.config_disk_name)
|
||||||
self.config_disk_name = config_disk_name
|
|
||||||
except (NodeError, ImageMissingError) as e:
|
except (NodeError, ImageMissingError) as e:
|
||||||
config_disk_zip = get_resource("compute/qemu/resources/{}.zip"
|
|
||||||
.format(config_disk_name))
|
|
||||||
if config_disk_zip and os.path.exists(config_disk_zip):
|
|
||||||
directory = self.manager.get_images_directory()
|
|
||||||
try:
|
|
||||||
unpack_zip(config_disk_zip, directory)
|
|
||||||
self.config_disk_image = os.path.join(directory,
|
|
||||||
config_disk_name)
|
|
||||||
self.config_disk_name = config_disk_name
|
|
||||||
except OSError as e:
|
|
||||||
log.warning("Config disk creation: {}".format(e))
|
|
||||||
else:
|
|
||||||
log.warning("Config disk: image '{}' missing"
|
log.warning("Config disk: image '{}' missing"
|
||||||
.format(config_disk_name))
|
.format(self.config_disk_name))
|
||||||
|
self.config_disk_name = ""
|
||||||
|
|
||||||
log.info('QEMU VM "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
log.info('QEMU VM "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user