def __init__(self, instance=None, disk_name=None, path=None):
        super(Raw, self).__init__("file", "raw", is_block_dev=False)

        self.path = (path or os.path.join(
            libvirt_utils.get_instance_path(instance), disk_name))
        self.preallocate = CONF.preallocate_images != 'none'
        self.correct_format()
Example #2
0
        def image_init(instance=None, disk_name=None, path=None):
            # There's nothing special about this path except that it's
            # predictable and unique for (instance, disk).
            if path is None:
                path = os.path.join(
                    libvirt_utils.get_instance_path(instance), disk_name)
            else:
                disk_name = os.path.basename(path)

            disk = self.disks[disk_name]

            # Used directly by callers. These would have been set if called
            # the real constructor.
            setattr(disk, 'path', path)
            setattr(disk, 'is_block_dev', mock.sentinel.is_block_dev)

            # Used by tests. Note that image_init is a closure over image_type.
            setattr(disk, 'image_type', image_type)

            # Used by tests to manipulate which disks exist.
            if self._exists is not None:
                # We don't just cache the return value here because the
                # caller may want, eg, a test where the disk initially does not
                # exist and later exists.
                disk.exists.side_effect = lambda: self._exists(disk_name)
            else:
                disk.exists.return_value = True

            return disk
Example #3
0
    def __init__(self, instance=None, disk_name=None, path=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  disk_name))
        self.preallocate = CONF.preallocate_images != 'none'
Example #4
0
        def image_init(instance=None, disk_name=None, path=None):
            # There's nothing special about this path except that it's
            # predictable and unique for (instance, disk).
            if path is None:
                path = os.path.join(libvirt_utils.get_instance_path(instance),
                                    disk_name)
            else:
                disk_name = os.path.basename(path)

            disk = self.disks[disk_name]

            # Used directly by callers. These would have been set if called
            # the real constructor.
            setattr(disk, 'path', path)
            setattr(disk, 'is_block_dev', mock.sentinel.is_block_dev)

            # Used by tests. Note that image_init is a closure over image_type.
            setattr(disk, 'image_type', image_type)

            # Used by tests to manipulate which disks exist.
            if self._exists is not None:
                # We don't just cache the return value here because the
                # caller may want, eg, a test where the disk initially does not
                # exist and later exists.
                disk.exists.side_effect = lambda: self._exists(disk_name)
            else:
                disk.exists.return_value = True

            return disk
Example #5
0
    def __init__(self, instance=None, disk_name=None, path=None):
        super(Ploop, self).__init__("file", "ploop", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  disk_name))
        self.resolve_driver_format()
Example #6
0
    def __init__(self, instance=None, disk_name=None, path=None, snapshot_name=None):
        super(Raw, self).__init__("file", "raw", is_block_dev=False)

        self.path = path or os.path.join(libvirt_utils.get_instance_path(instance), disk_name)
        self.snapshot_name = snapshot_name
        self.preallocate = CONF.preallocate_images != "none"
        self.correct_format()
Example #7
0
    def __init__(self, instance=None, disk_name=None, path=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = path or os.path.join(libvirt_utils.get_instance_path(instance), disk_name)
        self.preallocate = CONF.preallocate_images != "none"
        self.disk_info_path = os.path.join(os.path.dirname(self.path), "disk.info")
        self.resolve_driver_format()
Example #8
0
    def __init__(self, instance=None, disk_name=None, path=None):
        super(Ploop, self).__init__("file", "ploop", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  disk_name))
        self.resolve_driver_format()
Example #9
0
    def __init__(self, instance=None, disk_name=None, path=None):
        self.disk_name = disk_name
        super(Raw, self).__init__("file", "raw", is_block_dev=False)

        self.path = path or os.path.join(libvirt_utils.get_instance_path(instance), disk_name)
        self.preallocate = CONF.preallocate_images != "none"
        self.disk_info_path = os.path.join(os.path.dirname(self.path), "disk.info")
        self.correct_format()
Example #10
0
    def __init__(self, instance=None, disk_name=None, path=None,
                 snapshot_name=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  disk_name))
        self.snapshot_name = snapshot_name
Example #11
0
    def __init__(self, instance=None, disk_name=None, path=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = (path or os.path.join(
            libvirt_utils.get_instance_path(instance), disk_name))
        self.preallocate = CONF.preallocate_images != 'none'
        self.disk_info_path = os.path.join(os.path.dirname(self.path),
                                           'disk.info')
        self.resolve_driver_format()
Example #12
0
    def __init__(self, instance=None, disk_name=None, path=None):
        path = path or os.path.join(libvirt_utils.get_instance_path(instance), disk_name)
        super(Qcow2, self).__init__(path, "file", "qcow2", is_block_dev=False)

        self.preallocate = strutils.to_slug(CONF.preallocate_images) == "space"
        if self.preallocate:
            self.driver_io = "native"
        self.disk_info_path = os.path.join(os.path.dirname(path), "disk.info")
        self.resolve_driver_format()
Example #13
0
    def __init__(self, instance=None, disk_name=None, path=None,
                 snapshot_name=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  disk_name))
        self.snapshot_name = snapshot_name
        self.preallocate = CONF.preallocate_images != 'none'
Example #14
0
    def __init__(self, instance=None, disk_name=None, path=None):
        path = (path or os.path.join(libvirt_utils.get_instance_path(instance),
                                     disk_name))
        super(Qcow2, self).__init__(path, "file", "qcow2", is_block_dev=False)

        self.preallocate = (strutils.to_slug(
            CONF.preallocate_images) == 'space')
        if self.preallocate:
            self.driver_io = "native"
        self.disk_info_path = os.path.join(os.path.dirname(path), 'disk.info')
        self.resolve_driver_format()
Example #15
0
    def __init__(self, instance=None, disk_name=None, path=None):
        self.disk_name = disk_name
        super(Raw, self).__init__("file", "raw", is_block_dev=False)

        self.path = (path or os.path.join(
            libvirt_utils.get_instance_path(instance), disk_name))
        self.preallocate = (strutils.to_slug(
            CONF.preallocate_images) == 'space')
        self.disk_info_path = os.path.join(os.path.dirname(self.path),
                                           'disk.info')
        self.correct_format()
Example #16
0
    def __init__(self, instance=None, disk_name=None, path=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  disk_name))
        self.preallocate = (
            strutils.to_slug(CONF.preallocate_images) == 'space')
        self.disk_info_path = os.path.join(os.path.dirname(self.path),
                                           'disk.info')
        self.resolve_driver_format()
Example #17
0
    def __init__(self, instance=None, disk_name=None, path=None):
        self.disk_name = disk_name
        path = (path or os.path.join(libvirt_utils.get_instance_path(instance),
                                     disk_name))
        super(Flat, self).__init__(path, "file", "raw", is_block_dev=False)

        self.preallocate = (
            strutils.to_slug(CONF.preallocate_images) == 'space')
        if self.preallocate:
            self.driver_io = "native"
        self.disk_info_path = os.path.join(os.path.dirname(path), 'disk.info')
        self.correct_format()
Example #18
0
    def setUp(self):
        super(_ImageTestCase, self).setUp()
        self.flags(disable_process_locking=True,
                   instances_path=self.INSTANCES_PATH)
        self.INSTANCE = {'name': 'instance'}
        self.NAME = 'fake.vm'
        self.TEMPLATE = 'template'

        self.PATH = os.path.join(
            libvirt_utils.get_instance_path(self.INSTANCE), self.NAME)
        self.TEMPLATE_DIR = os.path.join(CONF.instances_path,
                                         '_base')
        self.TEMPLATE_PATH = os.path.join(self.TEMPLATE_DIR, 'template')

        self.useFixture(fixtures.MonkeyPatch(
            'nova.virt.libvirt.imagebackend.libvirt_utils',
            fake_libvirt_utils))
Example #19
0
    def setUp(self):
        super(_ImageTestCase, self).setUp()
        self.flags(disable_process_locking=True,
                   instances_path=self.INSTANCES_PATH)
        self.INSTANCE = {'name': 'instance'}
        self.NAME = 'fake.vm'
        self.TEMPLATE = 'template'

        self.PATH = os.path.join(
            libvirt_utils.get_instance_path(self.INSTANCE), self.NAME)
        self.TEMPLATE_DIR = os.path.join(CONF.instances_path, '_base')
        self.TEMPLATE_PATH = os.path.join(self.TEMPLATE_DIR, 'template')

        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.libvirt.imagebackend.libvirt_utils',
                fake_libvirt_utils))
Example #20
0
    def __init__(self, instance=None, name=None, path=None):
        super(Qcow2, self).__init__("file", "qcow2", is_block_dev=False)

        self.path = (path or os.path.join(
            libvirt_utils.get_instance_path(instance), name))
Example #21
0
def get_instance_path(instance, forceold=False):
    return libvirt_utils.get_instance_path(instance, forceold=forceold)
Example #22
0
def get_instance_path(instance, forceold=False, relative=False):
    return libvirt_utils.get_instance_path(instance,
                                           forceold=forceold,
                                           relative=relative)
    def _spawn_using_synthesis(self, context, instance, xml, image_meta,
                               overlay_url):
        # download vm overlay
        overlay_package = VMOverlayPackage(overlay_url)
        meta_raw = overlay_package.read_meta()
        meta_info = msgpack.unpackb(meta_raw)
        basevm_sha256 = meta_info.get(Cloudlet_Const.META_BASE_VM_SHA256, None)
        image_properties = image_meta.get("properties", None)
        if image_properties is None:
            msg = "image does not have properties for cloudlet metadata"
            raise exception.ImageNotFound(msg)
        image_sha256 = image_properties.get(CloudletAPI.PROPERTY_KEY_BASE_UUID)

        # check basevm
        if basevm_sha256 != image_sha256:
            msg = "requested base vm is not compatible with openstack base disk %s != %s" \
                % (basevm_sha256, image_sha256)
            raise exception.ImageNotFound(msg)
        memory_snap_id = str(
            image_properties.get(CloudletAPI.IMAGE_TYPE_BASE_MEM))
        diskhash_snap_id = str(
            image_properties.get(CloudletAPI.IMAGE_TYPE_BASE_DISK_HASH))
        memhash_snap_id = str(
            image_properties.get(CloudletAPI.IMAGE_TYPE_BASE_MEM_HASH))
        basedisk_path = self._get_cache_image(context, instance,
                                              image_meta['id'])
        basemem_path = self._get_cache_image(context, instance, memory_snap_id)
        diskhash_path = self._get_cache_image(context, instance,
                                              diskhash_snap_id)
        memhash_path = self._get_cache_image(context, instance,
                                             memhash_snap_id)

        # download blob
        fileutils.ensure_tree(libvirt_utils.get_instance_path(instance))
        decomp_overlay = os.path.join(
            libvirt_utils.get_instance_path(instance), 'decomp_overlay')

        meta_info = compression.decomp_overlayzip(overlay_url, decomp_overlay)

        # recover VM
        launch_disk, launch_mem, fuse, delta_proc, fuse_proc = \
            synthesis.recover_launchVM(basedisk_path, meta_info,
                                       decomp_overlay,
                                       base_mem=basemem_path,
                                       base_diskmeta=diskhash_path,
                                       base_memmeta=memhash_path)
        # resume VM
        LOG.info(_("Starting VM synthesis"), instance=instance)
        synthesized_vm = synthesis.SynthesizedVM(launch_disk,
                                                 launch_mem,
                                                 fuse,
                                                 disk_only=False,
                                                 qemu_args=False,
                                                 nova_xml=xml,
                                                 nova_conn=self._conn,
                                                 nova_util=libvirt_utils)
        # testing non-thread resume
        delta_proc.start()
        fuse_proc.start()
        delta_proc.join()
        fuse_proc.join()
        LOG.info(_("Finish VM synthesis"), instance=instance)
        synthesized_vm.resume()
        # rettach NIC
        synthesis.rettach_nic(synthesized_vm.machine,
                              synthesized_vm.old_xml_str, xml)

        return synthesized_vm
def get_instance_path(instance, forceold=False):
    return libvirt_utils.get_instance_path(instance, forceold=forceold)
    def _spawn_using_synthesis(self, context, instance, xml, image_meta, overlay_url):
        # download vm overlay
        overlay_package = VMOverlayPackage(overlay_url)
        meta_raw = overlay_package.read_meta()
        meta_info = msgpack.unpackb(meta_raw)
        basevm_sha256 = meta_info.get(Cloudlet_Const.META_BASE_VM_SHA256, None)
        image_properties = image_meta.get("properties", None)
        if image_properties is None:
            msg = "image does not have properties for cloudlet metadata"
            raise exception.ImageNotFound(msg)
        image_sha256 = image_properties.get(CloudletAPI.PROPERTY_KEY_BASE_UUID)

        # check basevm
        if basevm_sha256 != image_sha256:
            msg = "requested base vm is not compatible with openstack base disk %s != %s" % (
                basevm_sha256,
                image_sha256,
            )
            raise exception.ImageNotFound(msg)
        memory_snap_id = str(image_properties.get(CloudletAPI.IMAGE_TYPE_BASE_MEM))
        diskhash_snap_id = str(image_properties.get(CloudletAPI.IMAGE_TYPE_BASE_DISK_HASH))
        memhash_snap_id = str(image_properties.get(CloudletAPI.IMAGE_TYPE_BASE_MEM_HASH))
        basedisk_path = self._get_cache_image(context, instance, image_meta["id"])
        basemem_path = self._get_cache_image(context, instance, memory_snap_id)
        diskhash_path = self._get_cache_image(context, instance, diskhash_snap_id)
        memhash_path = self._get_cache_image(context, instance, memhash_snap_id)

        # download blob
        fileutils.ensure_tree(libvirt_utils.get_instance_path(instance))
        decomp_overlay = os.path.join(libvirt_utils.get_instance_path(instance), "decomp_overlay")

        meta_info = compression.decomp_overlayzip(overlay_url, decomp_overlay)

        # recover VM
        launch_disk, launch_mem, fuse, delta_proc, fuse_proc = synthesis.recover_launchVM(
            basedisk_path,
            meta_info,
            decomp_overlay,
            base_mem=basemem_path,
            base_diskmeta=diskhash_path,
            base_memmeta=memhash_path,
        )
        # resume VM
        LOG.info(_("Starting VM synthesis"), instance=instance)
        synthesized_vm = synthesis.SynthesizedVM(
            launch_disk,
            launch_mem,
            fuse,
            disk_only=False,
            qemu_args=False,
            nova_xml=xml,
            nova_conn=self._conn,
            nova_util=libvirt_utils,
        )
        # testing non-thread resume
        delta_proc.start()
        fuse_proc.start()
        delta_proc.join()
        fuse_proc.join()
        LOG.info(_("Finish VM synthesis"), instance=instance)
        synthesized_vm.resume()
        # rettach NIC
        synthesis.rettach_nic(synthesized_vm.machine, synthesized_vm.old_xml_str, xml)

        return synthesized_vm
 def basepath(fname='', suffix=suffix):
     return os.path.join(libvirt_utils.get_instance_path(instance),
                         fname + suffix)
Example #27
0
def get_instance_path(instance, relative=False):
    return libvirt_utils.get_instance_path(instance, relative=relative)
 def basepath(fname="", suffix=suffix):
     return os.path.join(libvirt_utils.get_instance_path(instance), fname + suffix)
Example #29
0
    def __init__(self, instance=None, name=None, path=None):
        super(Raw, self).__init__("file", "raw", is_block_dev=False)

        self.path = (path or
                     os.path.join(libvirt_utils.get_instance_path(instance),
                                  name))