def create_root_disk(self, context, instance):
        base_vhd_path = imagecache.get_cached_image(context, instance)
        base_info = vhdutils.disk_info(base_vhd_path)
        root_vhd_path = pathutils.root_disk_path(
            instance, disk_format=base_info[constants.VHD_IMAGE_TYPE])

        if CONF.use_cow_images:
            LOG.debug(
                "Creating differencing VHD. Parent: %(parent)s, "
                "Target: %(target)s", {
                    'parent': base_vhd_path,
                    'target': root_vhd_path
                },
                instance=instance)
            self._vbox_manage.create_hd(
                filename=root_vhd_path,
                # disk_format=base_info[constants.VHD_IMAGE_TYPE],
                variant=constants.VARIANT_STANDARD,
                parent=base_vhd_path)

        else:
            LOG.debug(
                "Cloning VHD image %(base)s to target: %(target)s", {
                    'base': base_vhd_path,
                    'target': root_vhd_path
                },
                instance=instance)
            self._vbox_manage.clone_hd(
                vhd_path=base_vhd_path,
                new_vdh_path=root_vhd_path,
                disk_format=base_info[constants.VHD_IMAGE_TYPE],
                variant=constants.VARIANT_STANDARD)

        # Resize image if is necesary
        disk_format = vhdutils.get_image_type(root_vhd_path)
        if instance.root_gb and disk_format in (constants.DISK_FORMAT_VDI,
                                                constants.DISK_FORMAT_VHD):
            base_vhd_size = base_info[constants.VHD_CAPACITY] / units.Mi
            root_vhd_size = instance.root_gb * units.Ki
            if vhdutils.is_resize_required(
                    disk_path=root_vhd_path,
                    old_size=base_vhd_size,
                    new_size=root_vhd_size,
                    instance=instance):
                self._vbox_manage.modify_hd(
                    root_vhd_path, constants.FIELD_HD_RESIZE_MB, root_vhd_size)

        return root_vhd_path
Exemple #2
0
    def create_root_disk(self, context, instance):
        base_vhd_path = imagecache.get_cached_image(context, instance)
        base_info = vhdutils.disk_info(base_vhd_path)
        root_vhd_path = pathutils.root_disk_path(
            instance, disk_format=base_info[constants.VHD_IMAGE_TYPE])

        if CONF.use_cow_images:
            LOG.debug(
                "Creating differencing VHD. Parent: %(parent)s, "
                "Target: %(target)s", {
                    'parent': base_vhd_path,
                    'target': root_vhd_path
                },
                instance=instance)
            self._vbox_manage.create_hd(
                filename=root_vhd_path,
                # disk_format=base_info[constants.VHD_IMAGE_TYPE],
                variant=constants.VARIANT_STANDARD,
                parent=base_vhd_path)

        else:
            LOG.debug("Cloning VHD image %(base)s to target: %(target)s", {
                'base': base_vhd_path,
                'target': root_vhd_path
            },
                      instance=instance)
            self._vbox_manage.clone_hd(
                vhd_path=base_vhd_path,
                new_vdh_path=root_vhd_path,
                disk_format=base_info[constants.VHD_IMAGE_TYPE],
                variant=constants.VARIANT_STANDARD)

        # Resize image if is necesary
        disk_format = vhdutils.get_image_type(root_vhd_path)
        if instance.root_gb and disk_format in (constants.DISK_FORMAT_VDI,
                                                constants.DISK_FORMAT_VHD):
            base_vhd_size = base_info[constants.VHD_CAPACITY] / units.Mi
            root_vhd_size = instance.root_gb * units.Ki
            if vhdutils.is_resize_required(disk_path=root_vhd_path,
                                           old_size=base_vhd_size,
                                           new_size=root_vhd_size,
                                           instance=instance):
                self._vbox_manage.modify_hd(root_vhd_path,
                                            constants.FIELD_HD_RESIZE_MB,
                                            root_vhd_size)

        return root_vhd_path
Exemple #3
0
    def test_root_disk_path(self, mock_instance_basepath, mock_join):
        pathutils.root_disk_path(self._instance, 'fake-disk-format')

        mock_instance_basepath.assert_called_once_with(self._instance)
        self.assertEqual(1, mock_join.call_count)
    def test_root_disk_path(self, mock_instance_basepath, mock_join):
        pathutils.root_disk_path(self._instance, "fake-disk-format")

        mock_instance_basepath.assert_called_once_with(self._instance)
        self.assertEqual(1, mock_join.call_count)