Esempio n. 1
0
 def test_spawn_attach_volume_vmdk(self):
     self._create_instance_in_the_db()
     self.type_data = db.flavor_get_by_name(None, "m1.large")
     self.mox.StubOutWithMock(block_device, "volume_in_mapping")
     self.mox.StubOutWithMock(v_driver, "block_device_info_get_mapping")
     ebs_root = "fake_root"
     block_device.volume_in_mapping(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(ebs_root)
     connection_info = self._test_vmdk_connection_info("vmdk")
     root_disk = [{"connection_info": connection_info}]
     v_driver.block_device_info_get_mapping(mox.IgnoreArg()).AndReturn(root_disk)
     mount_point = "/dev/vdc"
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "_get_volume_uuid")
     volumeops.VMwareVolumeOps._get_volume_uuid(mox.IgnoreArg(), "volume-fake-id").AndReturn("fake_disk_uuid")
     self.mox.StubOutWithMock(vm_util, "get_vmdk_backed_disk_device")
     vm_util.get_vmdk_backed_disk_device(mox.IgnoreArg(), "fake_disk_uuid").AndReturn("fake_device")
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "_consolidate_vmdk_volume")
     volumeops.VMwareVolumeOps._consolidate_vmdk_volume(
         self.instance, mox.IgnoreArg(), "fake_device", mox.IgnoreArg()
     )
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "attach_volume")
     volumeops.VMwareVolumeOps.attach_volume(connection_info, self.instance, mox.IgnoreArg())
     self.mox.ReplayAll()
     self.conn.spawn(
         self.context,
         self.instance,
         self.image,
         injected_files=[],
         admin_password=None,
         network_info=self.network_info,
         block_device_info=None,
     )
Esempio n. 2
0
 def test_spawn_attach_volume_vmdk(self):
     self._create_instance_in_the_db()
     self.type_data = db.flavor_get_by_name(None, 'm1.large')
     self.mox.StubOutWithMock(block_device, 'volume_in_mapping')
     self.mox.StubOutWithMock(v_driver, 'block_device_info_get_mapping')
     ebs_root = 'fake_root'
     block_device.volume_in_mapping(mox.IgnoreArg(),
             mox.IgnoreArg()).AndReturn(ebs_root)
     connection_info = self._test_vmdk_connection_info('vmdk')
     root_disk = [{'connection_info': connection_info}]
     v_driver.block_device_info_get_mapping(
             mox.IgnoreArg()).AndReturn(root_disk)
     mount_point = '/dev/vdc'
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
                              '_get_res_pool_of_vm')
     volumeops.VMwareVolumeOps._get_res_pool_of_vm(
              mox.IgnoreArg()).AndReturn('fake_res_pool')
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
                              '_relocate_vmdk_volume')
     volumeops.VMwareVolumeOps._relocate_vmdk_volume(mox.IgnoreArg(),
              'fake_res_pool', mox.IgnoreArg())
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
                              'attach_volume')
     volumeops.VMwareVolumeOps.attach_volume(connection_info,
             self.instance, mox.IgnoreArg())
     self.mox.ReplayAll()
     self.conn.spawn(self.context, self.instance, self.image,
                     injected_files=[], admin_password=None,
                     network_info=self.network_info,
                     block_device_info=None)
Esempio n. 3
0
 def initialize_volumes_connection(self, block_device_info):
     mapping = driver.block_device_info_get_mapping(block_device_info)
     for vol in mapping:
         connection_info = vol['connection_info']
         volume_driver = self._get_volume_driver(
             connection_info=connection_info)
         volume_driver.initialize_volume_connection(connection_info)
Esempio n. 4
0
 def _detach_instance_volumes(self, instance, block_device_info):
     # We need to detach attached volumes
     block_device_mapping = driver.block_device_info_get_mapping(
         block_device_info)
     if block_device_mapping:
         # Certain disk types, for example 'IDE' do not support hot
         # plugging. Hence we need to power off the instance and update
         # the instance state.
         self._vmops.power_off(instance)
         for disk in block_device_mapping:
             connection_info = disk['connection_info']
             try:
                 # NOTE(claudiub): Passing None as the context, as it is
                 # not currently used.
                 self.detach_volume(None, connection_info, instance,
                                    disk.get('device_name'))
             except exception.DiskNotFound:
                 LOG.warning('The volume %s does not exist!',
                             disk.get('device_name'),
                             instance=instance)
             except Exception as e:
                 with excutils.save_and_reraise_exception():
                     LOG.error("Failed to detach %(device_name)s. "
                               "Exception: %(exc)s",
                               {'device_name': disk.get('device_name'),
                                'exc': e},
                               instance=instance)
Esempio n. 5
0
 def disconnect_volumes(self, block_device_info):
     mapping = driver.block_device_info_get_mapping(block_device_info)
     block_devices = self._group_block_devices_by_type(
         mapping)
     for driver_type, block_device_mapping in block_devices.items():
         volume_driver = self._get_volume_driver(driver_type)
         volume_driver.disconnect_volumes(block_device_mapping)
Esempio n. 6
0
    def attach_boot_volume(self, block_device_info, vm_name):
        """Attach the boot volume to the IDE controller."""

        LOG.debug(_("block device info: %s"), block_device_info)
        ebs_root = driver.block_device_info_get_mapping(
            block_device_info)[0]

        connection_info = ebs_root['connection_info']
        data = connection_info['data']
        target_lun = data['target_lun']
        target_iqn = data['target_iqn']
        target_portal = data['target_portal']
        self._volutils.login_storage_target(target_lun, target_iqn,
                                            target_portal)
        try:
            #Getting the mounted disk
            mounted_disk_path = self._get_mounted_disk_from_lun(target_iqn,
                                                                target_lun)
            #Find the IDE controller for the vm.
            ctrller_path = self._vmutils.get_vm_ide_controller(vm_name, 0)
            #Attaching to the same slot as the VHD disk file
            self._vmutils.attach_volume_to_controller(vm_name,
                                                      ctrller_path, 0,
                                                      mounted_disk_path)
        except Exception as exn:
            LOG.exception(_('Attach boot from volume failed: %s'), exn)
            self._volutils.logout_storage_target(target_iqn)
            raise vmutils.HyperVException(
                _('Unable to attach boot volume to instance %s') % vm_name)
Esempio n. 7
0
 def _detach_instance_volumes(self, instance, block_device_info):
     # We need to detach attached volumes
     block_device_mapping = driver.block_device_info_get_mapping(
         block_device_info)
     if block_device_mapping:
         # Certain disk types, for example 'IDE' do not support hot
         # plugging. Hence we need to power off the instance and update
         # the instance state.
         self._vmops.power_off(instance)
         # TODO(garyk): update the volumeops to read the state form the
         # VM instead of relying on a instance flag
         instance.vm_state = vm_states.STOPPED
         for disk in block_device_mapping:
             connection_info = disk['connection_info']
             try:
                 self.detach_volume(connection_info, instance,
                                    disk.get('device_name'))
             except exception.StorageError:
                 # The volume does not exist
                 # NOTE(garyk): change to warning after string freeze
                 LOG.debug('%s does not exist!', disk.get('device_name'),
                           instance=instance)
             except Exception as e:
                 with excutils.save_and_reraise_exception():
                     LOG.error(_LE("Failed to detach %(device_name)s. "
                                   "Exception: %(exc)s"),
                               {'device_name': disk.get('device_name'),
                                'exc': e},
                               instance=instance)
Esempio n. 8
0
    def _setup_create_instance_mocks(self, setup_vif_mocks_func=None, boot_from_volume=False, block_device_info=None):
        vmutils.VMUtils.create_vm(mox.Func(self._check_vm_name), mox.IsA(int), mox.IsA(int), mox.IsA(bool))

        if not boot_from_volume:
            m = vmutils.VMUtils.attach_ide_drive(
                mox.Func(self._check_vm_name), mox.IsA(str), mox.IsA(int), mox.IsA(int), mox.IsA(str)
            )
            m.WithSideEffects(self._add_ide_disk).InAnyOrder()

        func = mox.Func(self._check_vm_name)
        m = vmutils.VMUtils.create_scsi_controller(func)
        m.InAnyOrder()

        if boot_from_volume:
            mapping = driver.block_device_info_get_mapping(block_device_info)
            data = mapping[0]["connection_info"]["data"]
            target_lun = data["target_lun"]
            target_iqn = data["target_iqn"]
            target_portal = data["target_portal"]

            self._mock_attach_volume(mox.Func(self._check_vm_name), target_iqn, target_lun, target_portal, True)

        vmutils.VMUtils.create_nic(mox.Func(self._check_vm_name), mox.IsA(str), mox.IsA(str)).InAnyOrder()

        if setup_vif_mocks_func:
            setup_vif_mocks_func()
    def _create_network_only(self, xml, instance, network_info,
                             block_device_info=None):
        """Only perform network setup but skip set-up for domain (vm instance)
        because cloudlet code takes care of domain
        """
        block_device_mapping = driver.block_device_info_get_mapping(
            block_device_info)

        for vol in block_device_mapping:
            connection_info = vol['connection_info']
            disk_dev = vol['mount_device'].rpartition("/")[2]
            disk_info = {
                'dev': disk_dev,
                'bus': blockinfo.get_disk_bus_for_disk_dev(
                    libvirt_driver.CONF.libvirt.virt_type, disk_dev
                    ),
                'type': 'disk',
                }
            self.volume_driver_method('connect_volume',
                                      connection_info,
                                      disk_info)

        self.plug_vifs(instance, network_info)
        self.firewall_driver.setup_basic_filtering(instance, network_info)
        self.firewall_driver.prepare_instance_filter(instance, network_info)
        self.firewall_driver.apply_instance_filter(instance, network_info)
Esempio n. 10
0
    def test_vol_drv_iter(self):
        block_device_info = self._fake_bdms()
        bdms = nova_driver.block_device_info_get_mapping(block_device_info)
        vol_adpt = mock.Mock()

        def _get_results(bdms):
            # Patch so we get the same mock back each time.
            with mock.patch('nova.virt.powervm.volume.fcvscsi.'
                            'FCVscsiVolumeAdapter', return_value=vol_adpt):
                return [
                    (bdm, vol_drv) for bdm, vol_drv in self.drv._vol_drv_iter(
                        'context', self.inst, bdms)]

        results = _get_results(bdms)
        self.assertEqual(
            'fake_vol1',
            results[0][0]['connection_info']['data']['volume_id'])
        self.assertEqual(vol_adpt, results[0][1])
        self.assertEqual(
            'fake_vol2',
            results[1][0]['connection_info']['data']['volume_id'])
        self.assertEqual(vol_adpt, results[1][1])

        # Test with empty bdms
        self.assertEqual([], _get_results([]))
Esempio n. 11
0
    def attach_volumes(self, block_device_info, instance_name, ebs_root):
        mapping = driver.block_device_info_get_mapping(block_device_info)

        if ebs_root:
            self.attach_volume(mapping[0]["connection_info"], instance_name, True)
            mapping = mapping[1:]
        for vol in mapping:
            self.attach_volume(vol["connection_info"], instance_name)
Esempio n. 12
0
 def _attach_mapped_block_devices(self, instance, block_device_info):
     block_device_mapping = driver.block_device_info_get_mapping(
             block_device_info)
     for vol in block_device_mapping:
         connection_info = vol['connection_info']
         mount_device = vol['mount_device'].rpartition("/")[2]
         self.attach_volume(connection_info,
                 instance['name'], mount_device)
Esempio n. 13
0
 def finish_revert_migration(self, instance, network_info, block_device_info=None):
     """Finish reverting a resize, powering back on the instance"""
     # NOTE(vish): Xen currently does not use network info.
     self._vmops.finish_revert_migration(instance)
     block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
     for vol in block_device_mapping:
         connection_info = vol["connection_info"]
         mount_device = vol["mount_device"].rpartition("/")[2]
         self._volumeops.attach_volume(connection_info, instance["name"], mount_device)
 def _check_and_update_volumes(self, vm_gen, block_device_info, slot_map):
     volumes = driver.block_device_info_get_mapping(block_device_info)
     root_device_name = block_device_info['root_disk']['mount_device']
     root_bdm = self._get_root_device_bdm(block_device_info,
                                          root_device_name)
     if root_bdm:
         volumes.remove(root_bdm)
     for vol in volumes:
         self._check_and_update_bdm(slot_map, vm_gen, vol)
Esempio n. 15
0
    def _setup_create_instance_mocks(self, setup_vif_mocks_func=None,
                                     boot_from_volume=False,
                                     block_device_info=None,
                                     admin_permissions=True,
                                     ephemeral_storage=False):
        vmutils.VMUtils.create_vm(mox.IsA(str), mox.IsA(int),
                                  mox.IsA(int), mox.IsA(bool),
                                  CONF.hyperv.dynamic_memory_ratio,
                                  mox.IsA(int),
                                  mox.IsA(str),
                                  mox.IsA(list))

        if not boot_from_volume:
            m = vmutils.VMUtils.attach_ide_drive(mox.Func(self._check_vm_name),
                                                 mox.IsA(str),
                                                 mox.IsA(int),
                                                 mox.IsA(int),
                                                 mox.IsA(str))
            m.WithSideEffects(self._add_disk).InAnyOrder()

        if ephemeral_storage:
            m = vmutils.VMUtils.attach_ide_drive(mox.Func(self._check_vm_name),
                                                 mox.IsA(str),
                                                 mox.IsA(int),
                                                 mox.IsA(int),
                                                 mox.IsA(str))
            m.WithSideEffects(self._add_disk).InAnyOrder()

        func = mox.Func(self._check_vm_name)
        m = vmutils.VMUtils.create_scsi_controller(func)
        m.InAnyOrder()

        if boot_from_volume:
            mapping = driver.block_device_info_get_mapping(block_device_info)
            data = mapping[0]['connection_info']['data']
            target_lun = data['target_lun']
            target_iqn = data['target_iqn']
            target_portal = data['target_portal']

            self._mock_attach_volume(mox.Func(self._check_vm_name), target_iqn,
                                     target_lun, target_portal, True)

        vmutils.VMUtils.create_nic(mox.Func(self._check_vm_name),
                mox.IsA(str), mox.IsA(unicode)).InAnyOrder()

        if setup_vif_mocks_func:
            setup_vif_mocks_func()

        if CONF.hyperv.enable_instance_metrics_collection:
            vmutils.VMUtils.enable_vm_metrics_collection(
                mox.Func(self._check_vm_name))

        vmutils.VMUtils.set_vm_serial_port_connection(
            mox.IsA(str), mox.IsA(int), mox.IsA(str))

        vmops.VMOps._set_instance_disk_qos_specs(mox.IgnoreArg())
Esempio n. 16
0
    def attach_volumes(self, instance, block_device_info, ebs_root):
        """Attach volumes to the properly storage controller."""
        mapping = driver.block_device_info_get_mapping(block_device_info)

        if ebs_root:
            self.attach_volume(instance, mapping[0]['connection_info'],
                               True)
            mapping = mapping[1:]
        for vol in mapping:
            self.attach_volume(instance, vol['connection_info'])
Esempio n. 17
0
    def get_disk_path_mapping(self, block_device_info):
        block_mapping = driver.block_device_info_get_mapping(block_device_info)
        disk_path_mapping = {}
        for vol in block_mapping:
            connection_info = vol['connection_info']
            disk_serial = connection_info['serial']

            disk_path = self.get_disk_resource_path(connection_info)
            disk_path_mapping[disk_serial] = disk_path
        return disk_path_mapping
Esempio n. 18
0
    def get_disk_path_mapping(self, block_device_info):
        block_mapping = driver.block_device_info_get_mapping(block_device_info)
        disk_path_mapping = {}
        for vol in block_mapping:
            connection_info = vol["connection_info"]
            disk_serial = connection_info["serial"]

            disk_path = self.get_mounted_disk_path_from_volume(connection_info)
            disk_path_mapping[disk_serial] = disk_path
        return disk_path_mapping
Esempio n. 19
0
 def test_spawn_attach_volume_iscsi(self):
     self._create_instance_in_the_db()
     self.type_data = db.flavor_get_by_name(None, 'm1.large')
     self.mox.StubOutWithMock(block_device, 'volume_in_mapping')
     self.mox.StubOutWithMock(v_driver, 'block_device_info_get_mapping')
     connection_info = self._test_vmdk_connection_info('iscsi')
     root_disk = [{'connection_info': connection_info}]
     v_driver.block_device_info_get_mapping(
             mox.IgnoreArg()).AndReturn(root_disk)
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
                              'attach_volume')
     volumeops.VMwareVolumeOps.attach_volume(connection_info,
             self.instance, mox.IgnoreArg())
     self.mox.ReplayAll()
     block_device_info = {'mount_device': 'vda'}
     self.conn.spawn(self.context, self.instance, self.image,
                     injected_files=[], admin_password=None,
                     network_info=self.network_info,
                     block_device_info=block_device_info)
Esempio n. 20
0
    def _do_destroy_vm(self, context, instance, network_info, block_device_info=None,
                       destroy_disks=True, migrate_data=None):

        is_quick_delete = bool(
            instance.metadata.get(
                'quick_delete_once',
                False))

        instance.metadata['quick_delete_once'] = False
        instance.save()

        try:
            vapp_name = self._get_vcloud_vapp_name(instance)
            the_vapp = self._get_vcloud_vapp(vapp_name)
        except:
            LOG.info("can't find the vapp %s" % instance.uuid)
            return

        try:
            the_vapp = self._power_off_vapp(the_vapp)
        except:
            LOG.error('power off failed')

        vm_task_state = instance.task_state

        if not (is_quick_delete):

            # if the vm have volumes, download the first volume to local
            # directory
            block_device_mapping = driver.block_device_info_get_mapping(
                block_device_info)
            if len(block_device_mapping) > 0:
                # get first block device
                # remote_vmdk_url = vca.get_vapp_referenced_file_url(the_vapp)
                try:
                    self._update_vm_task_state(
                        instance,
                        vcloud_task_states.EXPORTING)
                    remote_vmdk_url = self._query_vmdk_url(the_vapp)
                except:
                    LOG.error('Getting Remote VMDK Url failed')
                    # return
                # download vmdk to local
                else:
                    volume_id = block_device_mapping[0][
                        'connection_info']['data']['volume_id']
                    local_filename = '%s/%s.vmdk' % (
                        CONF.vcloud.vcloud_volumes_dir, volume_id)
                    self._download_vmdk_from_vcloud(
                        context,
                        remote_vmdk_url,
                        local_filename)

        self._update_vm_task_state(instance, vm_task_state)
        self._delete_vapp(the_vapp)
    def _get_boot_order_gen2(self, block_device_info):
        boot_order = [block_device_info['root_disk']]
        boot_order += driver.block_device_info_get_ephemerals(
            block_device_info)
        boot_order += driver.block_device_info_get_mapping(block_device_info)

        self._sort_by_boot_order(boot_order)

        return [self._volops.get_disk_resource_path(
                boot_dev['connection_info']) if boot_dev.get('connection_info')
                else boot_dev['path'] for boot_dev in boot_order]
Esempio n. 22
0
    def spawn(self, context, instance, image_meta, injected_files,
              admin_password, network_info=None, block_device_info=None):
        nodename = instance.get('node')
        if not nodename:
            raise exception.NovaException(_("Baremetal node id not supplied"
                                            " to driver"))
        node = bmdb.bm_node_get(context, nodename)
        if node['instance_uuid']:
            raise exception.NovaException(_("Baremetal node %s already"
                                            " in use") % nodename)

        # TODO(deva): split this huge try: block into manageable parts
        try:
            _update_baremetal_state(context, node, instance,
                                    baremetal_states.BUILDING)

            var = self.baremetal_nodes.define_vars(instance, network_info,
                                                   block_device_info)

            self._plug_vifs(instance, network_info, context=context)

            self._firewall_driver.setup_basic_filtering(instance, network_info)
            self._firewall_driver.prepare_instance_filter(instance,
                                                          network_info)

            self.baremetal_nodes.create_image(var, context, image_meta, node,
                                              instance,
                                              injected_files=injected_files,
                                              admin_password=admin_password)
            self.baremetal_nodes.activate_bootloader(var, context, node,
                                                     instance, image_meta)
            pm = get_power_manager(node)
            state = pm.activate_node()

            _update_baremetal_state(context, node, instance, state)

            self.baremetal_nodes.activate_node(var, context, node, instance)
            self._firewall_driver.apply_instance_filter(instance, network_info)

            block_device_mapping = driver.block_device_info_get_mapping(
                block_device_info)
            for vol in block_device_mapping:
                connection_info = vol['connection_info']
                mountpoint = vol['mount_device']
                self.attach_volume(connection_info, instance['name'],
                                   mountpoint)

            pm.start_console()
        except Exception, e:
            # TODO(deva): add tooling that can revert a failed spawn
            _update_baremetal_state(context, node, instance,
                                    baremetal_states.ERROR)
            raise e
Esempio n. 23
0
 def migrate_disk_and_power_off(self, context, instance, dest, instance_type, network_info, block_device_info=None):
     """Transfers the VHD of a running instance to another host, then shuts
     off the instance copies over the COW disk"""
     # NOTE(vish): Xen currently does not use network info.
     rv = self._vmops.migrate_disk_and_power_off(context, instance, dest, instance_type)
     block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
     name_label = self._vmops._get_orig_vm_name_label(instance)
     for vol in block_device_mapping:
         connection_info = vol["connection_info"]
         mount_device = vol["mount_device"].rpartition("/")[2]
         self._volumeops.detach_volume(connection_info, name_label, mount_device)
     return rv
Esempio n. 24
0
    def _test_pre_live_migration(self, cow, with_volumes):
        self.flags(use_cow_images=cow)

        instance_data = self._get_instance_data()
        instance = db.instance_create(self._context, instance_data)
        instance['system_metadata'] = {}

        network_info = fake_network.fake_get_instance_nw_info(self.stubs,
                                                              spectacular=True)

        m = livemigrationutils.LiveMigrationUtils.check_live_migration_config()
        m.AndReturn(True)

        if cow:
            m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
                                                                  None)
            m.AndReturn(False)

            m = vhdutils.VHDUtils.get_vhd_info(mox.Func(self._check_img_path))
            m.AndReturn({'MaxInternalSize': 1024})

            fake.PathUtils.copyfile(mox.IsA(str), mox.IsA(str))
            vhdutils.VHDUtils.resize_vhd(mox.IsA(str), mox.IsA(object))

        if with_volumes:
            block_device_info = db_fakes.get_fake_block_device_info(
                self._volume_target_portal, self._volume_id)

            mapping = driver.block_device_info_get_mapping(block_device_info)
            data = mapping[0]['connection_info']['data']
            target_lun = data['target_lun']
            target_iqn = data['target_iqn']
            target_portal = data['target_portal']

            fake_mounted_disk = "fake_mounted_disk"
            fake_device_number = 0

            self._mock_login_storage_target(target_iqn, target_lun,
                                            target_portal,
                                            fake_mounted_disk,
                                            fake_device_number)
        else:
            block_device_info = None

        self._mox.ReplayAll()
        self._conn.pre_live_migration(self._context, instance,
                                      block_device_info, network_info)
        self._mox.VerifyAll()

        if cow:
            self.assertTrue(self._fetched_image is not None)
        else:
            self.assertTrue(self._fetched_image is None)
Esempio n. 25
0
    def spawn(self, context, instance, image_meta, injected_files,
            admin_password, network_info=None, block_device_info=None):
        LOG.info("spawn: %s" % (instance['name']))

        boot_hdd = None
        booted_from_volume = False

        if instance['image_ref']:
            tmpl = template.get_template(self, context, instance, image_meta)
            sdk_ve = tmpl.create_instance()
            boot_hdd = sdk_ve.get_dev_by_type(pc.PDE_HARD_DISK, 0)
        else:
            sdk_ve = self._create_blank_vm(instance)

        self._apply_flavor(instance, sdk_ve,
                resize_root_disk=bool(instance['image_ref']))
        self._reset_network(sdk_ve)
        for vif in network_info:
            self.vif_driver.setup_dev(self, instance, sdk_ve, vif)

        block_device_mapping = driver.block_device_info_get_mapping(
            block_device_info)

        for vol in block_device_mapping:
            connection_info = vol['connection_info']
            disk_info = {
                'dev': vol['mount_device'],
                'mount_device': vol['mount_device']}
            hdd = self.volume_driver_method('connect_volume',
                                connection_info, sdk_ve, disk_info)
            if instance['root_device_name'] == vol['mount_device']:
                self._set_boot_device(sdk_ve, hdd)
                boot_hdd = hdd
                booted_from_volume = True

        if not boot_hdd:
            raise Exception("Boot disk is missing")

        if CONF.pcs_inject_partition != -2:
            if booted_from_volume:
                LOG.warn(('File injection into a boot from volume'
                          'instance is not supported'), instance=instance)
            else:
                self._inject_files(sdk_ve, boot_hdd, instance,
                                   network_info=network_info,
                                   files=injected_files,
                                   admin_pass=admin_password)

        sdk_ve.start_ex(pc.PSM_VM_START, pc.PNSF_VM_START_WAIT).wait()

        self._plug_vifs(instance, sdk_ve, network_info)
        self._set_admin_password(sdk_ve, admin_password)
def volume_in_mapping(mount_device, block_device_info):
    block_device_list = [
        block_device.strip_dev(volume['mount_device']) for volume in
        driver.block_device_info_get_mapping(block_device_info)
    ]

    swap = driver.block_device_info_get_swap(block_device_info)
    if driver.swap_is_usable(swap):
        block_device_list.append(block_device.strip_dev(
            swap['device_name']))
    block_device_list.extend([
        block_device.strip_dev(ephemeral['device_name']) for ephemeral in
        driver.block_device_info_get_ephemerals(block_device_info)])
Esempio n. 27
0
 def test_spawn_attach_volume_iscsi(self):
     self._create_instance_in_the_db()
     self.type_data = db.flavor_get_by_name(None, "m1.large")
     self.mox.StubOutWithMock(block_device, "volume_in_mapping")
     self.mox.StubOutWithMock(v_driver, "block_device_info_get_mapping")
     ebs_root = "fake_root"
     block_device.volume_in_mapping(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(ebs_root)
     connection_info = self._test_vmdk_connection_info("iscsi")
     root_disk = [{"connection_info": connection_info}]
     v_driver.block_device_info_get_mapping(mox.IgnoreArg()).AndReturn(root_disk)
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "attach_volume")
     volumeops.VMwareVolumeOps.attach_volume(connection_info, self.instance, mox.IgnoreArg())
     self.mox.ReplayAll()
     self.conn.spawn(
         self.context,
         self.instance,
         self.image,
         injected_files=[],
         admin_password=None,
         network_info=self.network_info,
         block_device_info=None,
     )
Esempio n. 28
0
 def finish_migration(self, context, migration, instance, disk_info,
                      network_info, image_meta, resize_instance=False,
                      block_device_info=None):
     """Completes a resize, turning on the migrated instance"""
     self._vmops.finish_migration(context, migration, instance, disk_info,
                                  network_info, image_meta, resize_instance)
     block_device_mapping = driver.block_device_info_get_mapping(
             block_device_info)
     for vol in block_device_mapping:
         connection_info = vol['connection_info']
         mount_device = vol['mount_device'].rpartition("/")[2]
         self._volumeops.attach_volume(connection_info,
                 instance['name'], mount_device)
Esempio n. 29
0
    def spawn(self, context, instance, image_meta, injected_files,
              admin_password, network_info=None, block_device_info=None):
        nodename = None
        for m in instance['system_metadata']:
            if m['key'] == 'node':
                nodename = m['value']
                break
        if nodename is None:
            raise NodeNotSpecified()
        node_id = int(nodename)
        node = bmdb.bm_node_get(context, node_id)
        if not node:
            raise NodeNotFound(nodename=nodename)
        if node['instance_uuid']:
            raise NodeInUse(nodename=nodename, instance_uuid=instance['uuid'])

        _update_baremetal_state(context, node, instance,
                                baremetal_states.BUILDING)

        var = self.baremetal_nodes.define_vars(instance, network_info,
                                               block_device_info)

        self._plug_vifs(instance, network_info, context=context)

        self._firewall_driver.setup_basic_filtering(instance, network_info)
        self._firewall_driver.prepare_instance_filter(instance, network_info)

        self.baremetal_nodes.create_image(var, context, image_meta, node,
                                          instance,
                                          injected_files=injected_files,
                                          admin_password=admin_password)
        self.baremetal_nodes.activate_bootloader(var, context, node,
                                                 instance)

        pm = get_power_manager(node)
        state = pm.activate_node()

        _update_baremetal_state(context, node, instance, state)

        self.baremetal_nodes.activate_node(var, context, node, instance)
        self._firewall_driver.apply_instance_filter(instance, network_info)

        block_device_mapping = driver.block_device_info_get_mapping(
            block_device_info)
        for vol in block_device_mapping:
            connection_info = vol['connection_info']
            mountpoint = vol['mount_device']
            self.attach_volume(connection_info, instance['name'], mountpoint)

        if node['terminal_port']:
            pm.start_console(node['terminal_port'], node['id'])
Esempio n. 30
0
    def fix_instance_volume_disk_paths(self, instance_name, block_device_info):
        mapping = driver.block_device_info_get_mapping(block_device_info)

        if self.ebs_root_in_block_devices(block_device_info):
            mapping = mapping[1:]

        disk_address = 0
        for vol in mapping:
            connection_info = vol['connection_info']
            volume_driver = self._get_volume_driver(
                connection_info=connection_info)
            volume_driver.fix_instance_volume_disk_path(
                instance_name, connection_info, disk_address)
            disk_address += 1
Esempio n. 31
0
    def spawn(self,
              context,
              instance,
              image_meta,
              injected_files,
              admin_password,
              allocations,
              network_info=None,
              block_device_info=None):
        """Create a new instance/VM/domain on the virtualization platform.

        Once this successfully completes, the instance should be
        running (power_state.RUNNING).

        If this fails, any partial instance should be completely
        cleaned up, and the virtualization platform should be in the state
        that it was before this call began.

        :param context: security context
        :param instance: nova.objects.instance.Instance
                         This function should use the data there to guide
                         the creation of the new instance.
        :param nova.objects.ImageMeta image_meta:
            The metadata of the image of the instance.
        :param injected_files: User files to inject into instance.
        :param admin_password: Administrator password to set in instance.
        :param allocations: Information about resources allocated to the
                            instance via placement, of the form returned by
                            SchedulerReportClient.get_allocations_for_consumer.
        :param network_info: instance network information
        :param block_device_info: Information about block devices to be
                                  attached to the instance.
        """
        self._log_operation('spawn', instance)
        # Define the flow
        flow_spawn = tf_lf.Flow("spawn")

        # This FeedTask accumulates VIOS storage connection operations to be
        # run in parallel. Include both SCSI and fibre channel mappings for
        # the scrubber.
        stg_ftsk = pvm_par.build_active_vio_feed_task(
            self.adapter, xag={pvm_const.XAG.VIO_SMAP, pvm_const.XAG.VIO_FMAP})

        flow_spawn.add(
            tf_vm.Create(self.adapter, self.host_wrapper, instance, stg_ftsk))

        # Create a flow for the IO
        flow_spawn.add(
            tf_net.PlugVifs(self.virtapi, self.adapter, instance,
                            network_info))
        flow_spawn.add(tf_net.PlugMgmtVif(self.adapter, instance))

        # Create the boot image.
        flow_spawn.add(
            tf_stg.CreateDiskForImg(self.disk_dvr, context, instance,
                                    image_meta))
        # Connects up the disk to the LPAR
        flow_spawn.add(
            tf_stg.AttachDisk(self.disk_dvr, instance, stg_ftsk=stg_ftsk))

        # Extract the block devices.
        bdms = driver.block_device_info_get_mapping(block_device_info)

        # Determine if there are volumes to connect.  If so, add a connection
        # for each type.
        for bdm, vol_drv in self._vol_drv_iter(context,
                                               instance,
                                               bdms,
                                               stg_ftsk=stg_ftsk):
            # Connect the volume.  This will update the connection_info.
            flow_spawn.add(tf_stg.AttachVolume(vol_drv))

        # If the config drive is needed, add those steps.  Should be done
        # after all the other I/O.
        if configdrive.required_by(instance):
            flow_spawn.add(
                tf_stg.CreateAndConnectCfgDrive(self.adapter,
                                                instance,
                                                injected_files,
                                                network_info,
                                                stg_ftsk,
                                                admin_pass=admin_password))

        # Add the transaction manager flow at the end of the 'I/O
        # connection' tasks. This will run all the connections in parallel.
        flow_spawn.add(stg_ftsk)

        # Last step is to power on the system.
        flow_spawn.add(tf_vm.PowerOn(self.adapter, instance))

        # Run the flow.
        tf_base.run(flow_spawn, instance=instance)
Esempio n. 32
0
def get_disk_mapping(virt_type,
                     instance,
                     disk_bus,
                     cdrom_bus,
                     block_device_info=None,
                     image_meta=None,
                     rescue=False):
    """Determine how to map default disks to the virtual machine.

       This is about figuring out whether the default 'disk',
       'disk.local', 'disk.swap' and 'disk.config' images have
       been overridden by the block device mapping.

       Returns the guest disk mapping for the devices.
    """

    inst_type = flavors.extract_flavor(instance)

    mapping = {}

    pre_assigned_device_names = \
    [block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
        driver.block_device_info_get_ephemerals(block_device_info),
        [driver.block_device_info_get_swap(block_device_info)],
        driver.block_device_info_get_mapping(block_device_info))
     if get_device_name(bdm)]

    if virt_type == "lxc":
        # NOTE(zul): This information is not used by the libvirt driver
        # however we need to populate mapping so the image can be
        # created when the instance is started. This can
        # be removed when we convert LXC to use block devices.
        root_disk_bus = disk_bus
        root_device_type = 'disk'

        root_info = get_next_disk_info(mapping,
                                       root_disk_bus,
                                       root_device_type,
                                       boot_index=1)
        mapping['root'] = root_info
        mapping['disk'] = root_info

        return mapping

    if rescue:
        rescue_info = get_next_disk_info(mapping, disk_bus, boot_index=1)
        mapping['disk.rescue'] = rescue_info
        mapping['root'] = rescue_info

        os_info = get_next_disk_info(mapping, disk_bus)
        mapping['disk'] = os_info

        return mapping

    # NOTE (ndipanov): root_bdm can be None when we boot from image
    # as there is no driver represenation of local targeted images
    # and they will not be in block_device_info list.
    root_bdm = block_device.get_root_bdm(
        driver.block_device_info_get_mapping(block_device_info))

    root_device_name = block_device.strip_dev(
        driver.block_device_info_get_root(block_device_info))
    root_info = get_root_info(virt_type, image_meta, root_bdm, disk_bus,
                              cdrom_bus, root_device_name)

    mapping['root'] = root_info
    # NOTE (ndipanov): This implicitly relies on image->local BDMs not
    #                  being considered in the driver layer - so missing
    #                  bdm with boot_index 0 means - use image, unless it was
    #                  overridden. This can happen when using legacy syntax and
    #                  no root_device_name is set on the instance.
    if not root_bdm and not block_device.volume_in_mapping(
            root_info['dev'], block_device_info):
        mapping['disk'] = root_info

    default_eph = has_default_ephemeral(instance, disk_bus, block_device_info,
                                        mapping)
    if default_eph:
        mapping['disk.local'] = default_eph

    for idx, eph in enumerate(
            driver.block_device_info_get_ephemerals(block_device_info)):
        eph_info = get_info_from_bdm(
            virt_type,
            eph,
            mapping,
            disk_bus,
            assigned_devices=pre_assigned_device_names)
        mapping[get_eph_disk(idx)] = eph_info
        update_bdm(eph, eph_info)

    swap = driver.block_device_info_get_swap(block_device_info)
    if swap and swap.get('swap_size', 0) > 0:
        swap_info = get_info_from_bdm(virt_type, swap, mapping, disk_bus)
        mapping['disk.swap'] = swap_info
        update_bdm(swap, swap_info)
    elif inst_type['swap'] > 0:
        swap_info = get_next_disk_info(mapping, disk_bus)
        if not block_device.volume_in_mapping(swap_info['dev'],
                                              block_device_info):
            mapping['disk.swap'] = swap_info

    block_device_mapping = driver.block_device_info_get_mapping(
        block_device_info)

    for vol in block_device_mapping:
        vol_info = get_info_from_bdm(
            virt_type,
            vol,
            mapping,
            assigned_devices=pre_assigned_device_names)
        mapping[block_device.prepend_dev(vol_info['dev'])] = vol_info
        update_bdm(vol, vol_info)

    if configdrive.required_by(instance):
        device_type = get_config_drive_type()
        disk_bus = get_disk_bus_for_device_type(virt_type, image_meta,
                                                device_type)
        config_info = get_next_disk_info(mapping,
                                         disk_bus,
                                         device_type,
                                         last_device=True)
        mapping['disk.config'] = config_info

    return mapping
Esempio n. 33
0
 def _get_root_device_bdm(self, block_device_info, mount_device=None):
     for mapping in driver.block_device_info_get_mapping(block_device_info):
         if mapping['mount_device'] == mount_device:
             return mapping
Esempio n. 34
0
def _get_disk_mapping(virt_type, instance, disk_bus, cdrom_bus, image_meta,
                      block_device_info):
    """Build disk mapping for a given instance

    :param virt_type: Virt type used by libvirt.
    :param instance: nova.objects.instance.Instance object
    :param disk_bus: Disk bus to use within the mapping
    :param cdrom_bus: CD-ROM bus to use within the mapping
    :param image_meta: objects.image_meta.ImageMeta for the instance
    :param block_device_info: dict detailing disks and volumes attached

    :returns: Disk mapping for the given instance.
    """
    mapping = {}
    pre_assigned_device_names = \
    [block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
        driver.block_device_info_get_ephemerals(block_device_info),
        [driver.block_device_info_get_swap(block_device_info)],
        driver.block_device_info_get_mapping(block_device_info))
     if get_device_name(bdm)]

    # NOTE (ndipanov): root_bdm can be None when we boot from image
    # as there is no driver representation of local targeted images
    # and they will not be in block_device_info list.
    root_bdm = block_device.get_root_bdm(
        driver.block_device_info_get_mapping(block_device_info))

    root_device_name = block_device.strip_dev(
        driver.block_device_info_get_root_device(block_device_info))
    root_info = get_root_info(
        instance, virt_type, image_meta, root_bdm,
        disk_bus, cdrom_bus, root_device_name)

    mapping['root'] = root_info
    # NOTE (ndipanov): This implicitly relies on image->local BDMs not
    #                  being considered in the driver layer - so missing
    #                  bdm with boot_index 0 means - use image, unless it was
    #                  overridden. This can happen when using legacy syntax and
    #                  no root_device_name is set on the instance.
    if not root_bdm and not block_device.volume_in_mapping(root_info['dev'],
                                                           block_device_info):
        mapping['disk'] = root_info
    elif root_bdm:
        # NOTE (ft): If device name is not set in root bdm, root_info has a
        # generated one. We have to copy device name to root bdm to prevent its
        # second generation in loop through bdms. If device name is already
        # set, nothing is changed.
        update_bdm(root_bdm, root_info)

    default_eph = get_default_ephemeral_info(instance, disk_bus,
                                             block_device_info, mapping)
    if default_eph:
        mapping['disk.local'] = default_eph

    for idx, eph in enumerate(driver.block_device_info_get_ephemerals(
            block_device_info)):
        eph_info = get_info_from_bdm(
            instance, virt_type, image_meta, eph, mapping, disk_bus,
            assigned_devices=pre_assigned_device_names)
        mapping[get_eph_disk(idx)] = eph_info
        update_bdm(eph, eph_info)

    swap = driver.block_device_info_get_swap(block_device_info)
    if swap and swap.get('swap_size', 0) > 0:
        swap_info = get_info_from_bdm(
            instance, virt_type, image_meta,
            swap, mapping, disk_bus)
        mapping['disk.swap'] = swap_info
        update_bdm(swap, swap_info)
    elif instance.get_flavor()['swap'] > 0:
        swap_info = get_next_disk_info(mapping, disk_bus,
            assigned_devices=pre_assigned_device_names)
        if not block_device.volume_in_mapping(swap_info['dev'],
                                              block_device_info):
            mapping['disk.swap'] = swap_info

    block_device_mapping = driver.block_device_info_get_mapping(
        block_device_info)

    for bdm in block_device_mapping:
        vol_info = get_info_from_bdm(
            instance, virt_type, image_meta, bdm, mapping,
            assigned_devices=pre_assigned_device_names)
        mapping[block_device.prepend_dev(vol_info['dev'])] = vol_info
        update_bdm(bdm, vol_info)

    if configdrive.required_by(instance):
        device_type = get_config_drive_type()
        disk_bus = get_disk_bus_for_device_type(instance,
                                                virt_type,
                                                image_meta,
                                                device_type)
        config_info = get_next_disk_info(mapping,
                                         disk_bus,
                                         device_type)
        mapping['disk.config'] = config_info
    return mapping
Esempio n. 35
0
def get_disk_mapping(virt_type,
                     instance,
                     disk_bus,
                     cdrom_bus,
                     image_meta,
                     block_device_info=None,
                     rescue=False):
    """Determine how to map default disks to the virtual machine.

       This is about figuring out whether the default 'disk',
       'disk.local', 'disk.swap' and 'disk.config' images have
       been overridden by the block device mapping.

       Returns the guest disk mapping for the devices.
    """

    mapping = {}

    if rescue:
        rescue_info = get_next_disk_info(mapping, disk_bus, boot_index=1)
        mapping['disk.rescue'] = rescue_info
        mapping['root'] = rescue_info

        os_info = get_next_disk_info(mapping, disk_bus)
        mapping['disk'] = os_info

        if configdrive.required_by(instance):
            device_type = get_config_drive_type()
            disk_bus = get_disk_bus_for_device_type(instance, virt_type,
                                                    image_meta, device_type)
            config_info = get_next_disk_info(mapping, disk_bus, device_type)
            mapping['disk.config.rescue'] = config_info

        return mapping

    pre_assigned_device_names = \
    [block_device.strip_dev(get_device_name(bdm)) for bdm in itertools.chain(
        driver.block_device_info_get_ephemerals(block_device_info),
        [driver.block_device_info_get_swap(block_device_info)],
        driver.block_device_info_get_mapping(block_device_info))
     if get_device_name(bdm)]

    # NOTE (ndipanov): root_bdm can be None when we boot from image
    # as there is no driver representation of local targeted images
    # and they will not be in block_device_info list.
    root_bdm = block_device.get_root_bdm(
        driver.block_device_info_get_mapping(block_device_info))

    root_device_name = block_device.strip_dev(
        driver.block_device_info_get_root(block_device_info))
    root_info = get_root_info(instance, virt_type, image_meta, root_bdm,
                              disk_bus, cdrom_bus, root_device_name)

    mapping['root'] = root_info
    # NOTE (ndipanov): This implicitly relies on image->local BDMs not
    #                  being considered in the driver layer - so missing
    #                  bdm with boot_index 0 means - use image, unless it was
    #                  overridden. This can happen when using legacy syntax and
    #                  no root_device_name is set on the instance.
    if not root_bdm and not block_device.volume_in_mapping(
            root_info['dev'], block_device_info):
        mapping['disk'] = root_info
    elif root_bdm:
        # NOTE (ft): If device name is not set in root bdm, root_info has a
        # generated one. We have to copy device name to root bdm to prevent its
        # second generation in loop through bdms. If device name is already
        # set, nothing is changed.
        update_bdm(root_bdm, root_info)

    default_eph = get_default_ephemeral_info(instance, disk_bus,
                                             block_device_info, mapping)
    if default_eph:
        mapping['disk.local'] = default_eph

    for idx, eph in enumerate(
            driver.block_device_info_get_ephemerals(block_device_info)):
        eph_info = get_info_from_bdm(
            instance,
            virt_type,
            image_meta,
            eph,
            mapping,
            disk_bus,
            assigned_devices=pre_assigned_device_names)
        mapping[get_eph_disk(idx)] = eph_info
        update_bdm(eph, eph_info)

    swap = driver.block_device_info_get_swap(block_device_info)
    if swap and swap.get('swap_size', 0) > 0:
        swap_info = get_info_from_bdm(instance, virt_type, image_meta, swap,
                                      mapping, disk_bus)
        mapping['disk.swap'] = swap_info
        update_bdm(swap, swap_info)
    elif instance.get_flavor()['swap'] > 0:
        swap_info = get_next_disk_info(
            mapping, disk_bus, assigned_devices=pre_assigned_device_names)
        if not block_device.volume_in_mapping(swap_info['dev'],
                                              block_device_info):
            mapping['disk.swap'] = swap_info

    block_device_mapping = driver.block_device_info_get_mapping(
        block_device_info)

    for bdm in block_device_mapping:
        vol_info = get_info_from_bdm(
            instance,
            virt_type,
            image_meta,
            bdm,
            mapping,
            assigned_devices=pre_assigned_device_names)
        mapping[block_device.prepend_dev(vol_info['dev'])] = vol_info
        update_bdm(bdm, vol_info)

    if configdrive.required_by(instance):
        device_type = get_config_drive_type()
        disk_bus = get_disk_bus_for_device_type(instance, virt_type,
                                                image_meta, device_type)
        config_info = get_next_disk_info(mapping, disk_bus, device_type)
        mapping['disk.config'] = config_info

    return mapping