示例#1
0
    def attach_disk_to_vm(self, vm_ref, instance,
                          adapter_type, disk_type, vmdk_path=None,
                          disk_size=None, linked_clone=False,
                          device_name=None, disk_io_limits=None):
        """Attach disk to VM by reconfiguration."""
        instance_name = instance.name
        client_factory = self._session.vim.client.factory
        devices = vm_util.get_hardware_devices(self._session, vm_ref)
        (controller_key, unit_number,
         controller_spec) = vm_util.allocate_controller_key_and_unit_number(
                                                              client_factory,
                                                              devices,
                                                              adapter_type)

        vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
                                    client_factory, disk_type, vmdk_path,
                                    disk_size, linked_clone, controller_key,
                                    unit_number, device_name, disk_io_limits)
        if controller_spec:
            vmdk_attach_config_spec.deviceChange.append(controller_spec)

        LOG.debug("Reconfiguring VM instance %(instance_name)s to attach "
                  "disk %(vmdk_path)s or device %(device_name)s with type "
                  "%(disk_type)s",
                  {'instance_name': instance_name, 'vmdk_path': vmdk_path,
                   'device_name': device_name, 'disk_type': disk_type},
                  instance=instance)
        vm_util.reconfigure_vm(self._session, vm_ref, vmdk_attach_config_spec)
        LOG.debug("Reconfigured VM instance %(instance_name)s to attach "
                  "disk %(vmdk_path)s or device %(device_name)s with type "
                  "%(disk_type)s",
                  {'instance_name': instance_name, 'vmdk_path': vmdk_path,
                   'device_name': device_name, 'disk_type': disk_type},
                  instance=instance)
示例#2
0
 def detach_disk_from_vm(self,
                         vm_ref,
                         instance,
                         device,
                         destroy_disk=False):
     """Detach disk from VM by reconfiguration."""
     instance_name = instance.name
     client_factory = self._session.vim.client.factory
     vmdk_detach_config_spec = vm_util.get_vmdk_detach_config_spec(
         client_factory, device, destroy_disk)
     disk_key = device.key
     LOG.debug(
         "Reconfiguring VM instance %(instance_name)s to detach "
         "disk %(disk_key)s", {
             'instance_name': instance_name,
             'disk_key': disk_key
         },
         instance=instance)
     vm_util.reconfigure_vm(self._session, vm_ref, vmdk_detach_config_spec)
     LOG.debug(
         "Reconfigured VM instance %(instance_name)s to detach "
         "disk %(disk_key)s", {
             'instance_name': instance_name,
             'disk_key': disk_key
         },
         instance=instance)
示例#3
0
    def attach_disk_to_vm(
        self,
        vm_ref,
        instance,
        adapter_type,
        disk_type,
        vmdk_path=None,
        disk_size=None,
        linked_clone=False,
        device_name=None,
        disk_io_limits=None,
    ):
        """Attach disk to VM by reconfiguration."""
        instance_name = instance.name
        client_factory = self._session.vim.client.factory
        devices = self._session._call_method(vutil, "get_object_property", vm_ref, "config.hardware.device")
        (controller_key, unit_number, controller_spec) = vm_util.allocate_controller_key_and_unit_number(
            client_factory, devices, adapter_type
        )

        vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
            client_factory,
            disk_type,
            vmdk_path,
            disk_size,
            linked_clone,
            controller_key,
            unit_number,
            device_name,
            disk_io_limits,
        )
        if controller_spec:
            vmdk_attach_config_spec.deviceChange.append(controller_spec)

        LOG.debug(
            "Reconfiguring VM instance %(instance_name)s to attach "
            "disk %(vmdk_path)s or device %(device_name)s with type "
            "%(disk_type)s",
            {
                "instance_name": instance_name,
                "vmdk_path": vmdk_path,
                "device_name": device_name,
                "disk_type": disk_type,
            },
            instance=instance,
        )
        vm_util.reconfigure_vm(self._session, vm_ref, vmdk_attach_config_spec)
        LOG.debug(
            "Reconfigured VM instance %(instance_name)s to attach "
            "disk %(vmdk_path)s or device %(device_name)s with type "
            "%(disk_type)s",
            {
                "instance_name": instance_name,
                "vmdk_path": vmdk_path,
                "device_name": device_name,
                "disk_type": disk_type,
            },
            instance=instance,
        )
示例#4
0
    def _update_volume_details(self, vm_ref, volume_uuid, device_uuid):
        # Store the uuid of the volume_device
        volume_option = "volume-%s" % volume_uuid
        extra_opts = {volume_option: device_uuid}

        client_factory = self._session.vim.client.factory
        extra_config_specs = vm_util.get_vm_extra_config_spec(client_factory, extra_opts)
        vm_util.reconfigure_vm(self._session, vm_ref, extra_config_specs)
示例#5
0
    def attach_disk_to_vm(self,
                          vm_ref,
                          instance,
                          adapter_type,
                          disk_type,
                          vmdk_path=None,
                          disk_size=None,
                          linked_clone=False,
                          device_name=None,
                          is_shared=False):
        """Attach disk to VM by reconfiguration."""
        instance_name = instance['name']
        instance_uuid = instance['uuid']
        client_factory = self._session._get_vim().client.factory
        devices = self._session._call_method(vim_util, "get_dynamic_property",
                                             vm_ref, "VirtualMachine",
                                             "config.hardware.device")
        (controller_key, unit_number,
         controller_spec) = vm_util.allocate_controller_key_and_unit_number(
             client_factory, devices, adapter_type, is_shared)
        if is_shared:
            iscsi_attach_config_spec = vm_util.get_iscsi_attach_config_spec(
                client_factory, disk_type, vmdk_path, disk_size, linked_clone,
                controller_key, unit_number, device_name)
            reconfig_task = self._session._call_method(
                self._session._get_vim(),
                "ReconfigVM_Task",
                vm_ref,
                spec=iscsi_attach_config_spec)
            self._session._wait_for_task(reconfig_task)

        vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
            client_factory, disk_type, vmdk_path, disk_size, linked_clone,
            controller_key, unit_number, device_name)
        if controller_spec and not is_shared:
            vmdk_attach_config_spec.deviceChange.append(controller_spec)

        LOG.debug(
            "Reconfiguring VM instance %(instance_name)s to attach "
            "disk %(vmdk_path)s or device %(device_name)s with type "
            "%(disk_type)s", {
                'instance_name': instance_name,
                'vmdk_path': vmdk_path,
                'device_name': device_name,
                'disk_type': disk_type
            },
            instance=instance)
        vm_util.reconfigure_vm(self._session, vm_ref, vmdk_attach_config_spec)
        LOG.debug(
            "Reconfigured VM instance %(instance_name)s to attach "
            "disk %(vmdk_path)s or device %(device_name)s with type "
            "%(disk_type)s", {
                'instance_name': instance_name,
                'vmdk_path': vmdk_path,
                'device_name': device_name,
                'disk_type': disk_type
            },
            instance=instance)
示例#6
0
 def test_reconfigure_vm(self):
     session = fake_session()
     with contextlib.nested(
         mock.patch.object(session, "_call_method", return_value="fake_reconfigure_task"),
         mock.patch.object(session, "_wait_for_task"),
     ) as (_call_method, _wait_for_task):
         vm_util.reconfigure_vm(session, "fake-ref", "fake-spec")
         _call_method.assert_called_once_with(mock.ANY, "ReconfigVM_Task", "fake-ref", spec="fake-spec")
         _wait_for_task.assert_called_once_with("fake_reconfigure_task")
示例#7
0
    def _update_volume_details(self, vm_ref, volume_uuid, device_uuid):
        # Store the uuid of the volume_device
        volume_option = 'volume-%s' % volume_uuid
        extra_opts = {volume_option: device_uuid}

        client_factory = self._session.vim.client.factory
        extra_config_specs = vm_util.get_vm_extra_config_spec(
            client_factory, extra_opts)
        vm_util.reconfigure_vm(self._session, vm_ref, extra_config_specs)
示例#8
0
 def test_reconfigure_vm(self):
     session = fake.FakeSession()
     with contextlib.nested(
         mock.patch.object(session, '_call_method',
                           return_value='fake_reconfigure_task'),
         mock.patch.object(session, '_wait_for_task')
     ) as (_call_method, _wait_for_task):
         vm_util.reconfigure_vm(session, 'fake-ref', 'fake-spec')
         _call_method.assert_called_once_with(mock.ANY,
             'ReconfigVM_Task', 'fake-ref', spec='fake-spec')
         _wait_for_task.assert_called_once_with(
             'fake_reconfigure_task')
示例#9
0
 def test_reconfigure_vm(self):
     session = fake.FakeSession()
     with contextlib.nested(
         mock.patch.object(session, '_call_method',
                           return_value='fake_reconfigure_task'),
         mock.patch.object(session, '_wait_for_task')
     ) as (_call_method, _wait_for_task):
         vm_util.reconfigure_vm(session, 'fake-ref', 'fake-spec')
         _call_method.assert_called_once_with(mock.ANY,
             'ReconfigVM_Task', 'fake-ref', spec='fake-spec')
         _wait_for_task.assert_called_once_with(
             'fake_reconfigure_task')
示例#10
0
    def _update_volume_details(self, vm_ref, instance, volume_uuid):
        # Store the uuid of the volume_device
        hw_devices = self._session._call_method(
            vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device"
        )
        device_uuid = vm_util.get_vmdk_backed_disk_uuid(hw_devices, volume_uuid)
        volume_option = "volume-%s" % volume_uuid
        extra_opts = {volume_option: device_uuid}

        client_factory = self._session.vim.client.factory
        extra_config_specs = vm_util.get_vm_extra_config_spec(client_factory, extra_opts)
        vm_util.reconfigure_vm(self._session, vm_ref, extra_config_specs)
示例#11
0
    def _update_volume_details(self, vm_ref, instance, volume_uuid):
        # Store the uuid of the volume_device
        hw_devices = self._session._call_method(vim_util,
                                                'get_dynamic_property',
                                                vm_ref, 'VirtualMachine',
                                                'config.hardware.device')
        device_uuid = vm_util.get_vmdk_backed_disk_uuid(hw_devices,
                                                        volume_uuid)
        volume_option = 'volume-%s' % volume_uuid
        extra_opts = {volume_option: device_uuid}

        client_factory = self._session._get_vim().client.factory
        extra_config_specs = vm_util.get_vm_extra_config_spec(
                                    client_factory, extra_opts)
        vm_util.reconfigure_vm(self._session, vm_ref, extra_config_specs)
示例#12
0
    def attach_disk_to_vm(self, vm_ref, instance,
                          adapter_type, disk_type, vmdk_path=None,
                          disk_size=None, linked_clone=False,
                          device_name=None, is_shared=False):
        """Attach disk to VM by reconfiguration."""
        instance_name = instance['name']
        instance_uuid = instance['uuid']
        client_factory = self._session._get_vim().client.factory
        devices = self._session._call_method(vim_util,
                                    "get_dynamic_property", vm_ref,
                                    "VirtualMachine", "config.hardware.device")
        (controller_key, unit_number,
         controller_spec) = vm_util.allocate_controller_key_and_unit_number(
                                                              client_factory,
                                                              devices,
                                                              adapter_type,
                                                              is_shared)
        if is_shared:
            iscsi_attach_config_spec = vm_util.get_iscsi_attach_config_spec(
                client_factory, disk_type, vmdk_path, disk_size, linked_clone,
                controller_key, unit_number, device_name)
            reconfig_task = self._session._call_method(
                self._session._get_vim(),
                "ReconfigVM_Task", vm_ref,
                spec=iscsi_attach_config_spec)
            self._session._wait_for_task(reconfig_task)

        vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
                                    client_factory, disk_type, vmdk_path,
                                    disk_size, linked_clone, controller_key,
                                    unit_number, device_name)
        if controller_spec and not is_shared:
            vmdk_attach_config_spec.deviceChange.append(controller_spec)

        LOG.debug("Reconfiguring VM instance %(instance_name)s to attach "
                  "disk %(vmdk_path)s or device %(device_name)s with type "
                  "%(disk_type)s",
                  {'instance_name': instance_name, 'vmdk_path': vmdk_path,
                   'device_name': device_name, 'disk_type': disk_type},
                  instance=instance)
        vm_util.reconfigure_vm(self._session, vm_ref, vmdk_attach_config_spec)
        LOG.debug("Reconfigured VM instance %(instance_name)s to attach "
                  "disk %(vmdk_path)s or device %(device_name)s with type "
                  "%(disk_type)s",
                  {'instance_name': instance_name, 'vmdk_path': vmdk_path,
                   'device_name': device_name, 'disk_type': disk_type},
                  instance=instance)
示例#13
0
 def detach_disk_from_vm(self, vm_ref, instance, device,
                         destroy_disk=False):
     """Detach disk from VM by reconfiguration."""
     instance_name = instance['name']
     client_factory = self._session.vim.client.factory
     vmdk_detach_config_spec = vm_util.get_vmdk_detach_config_spec(
                                 client_factory, device, destroy_disk)
     disk_key = device.key
     LOG.debug("Reconfiguring VM instance %(instance_name)s to detach "
               "disk %(disk_key)s",
               {'instance_name': instance_name, 'disk_key': disk_key},
               instance=instance)
     vm_util.reconfigure_vm(self._session, vm_ref, vmdk_detach_config_spec)
     LOG.debug("Reconfigured VM instance %(instance_name)s to detach "
               "disk %(disk_key)s",
               {'instance_name': instance_name, 'disk_key': disk_key},
               instance=instance)
示例#14
0
    def _update_volume_details(self, vm_ref, instance, volume_uuid):
        instance_name = instance['name']
        instance_uuid = instance['uuid']

        # Store the uuid of the volume_device
        hw_devices = self._session._call_method(vim_util,
                                                'get_dynamic_property',
                                                vm_ref, 'VirtualMachine',
                                                'config.hardware.device')
        device_uuid = vm_util.get_vmdk_backed_disk_uuid(hw_devices,
                                                        volume_uuid)
        volume_option = 'volume-%s' % volume_uuid
        extra_opts = {volume_option: device_uuid}

        client_factory = self._session._get_vim().client.factory
        extra_config_specs = vm_util.get_vm_extra_config_spec(
                                    client_factory, extra_opts)
        vm_util.reconfigure_vm(self._session, vm_ref, extra_config_specs)
示例#15
0
    def _attach_fcd(self, vm_ref, adapter_type, fcd_id, ds_ref_val):
        (controller_key, unit_number,
         controller_spec) = self._get_controller_key_and_unit(
             vm_ref, adapter_type)

        if controller_spec:
            # No controller available to attach, create one first.
            config_spec = self._session.vim.client.factory.create(
                'ns0:VirtualMachineConfigSpec')
            config_spec.deviceChange = [controller_spec]
            vm_util.reconfigure_vm(self._session, vm_ref, config_spec)
            (controller_key, unit_number,
             controller_spec) = self._get_controller_key_and_unit(
                 vm_ref, adapter_type)

        vm_util.attach_fcd(
            self._session, vm_ref, fcd_id, ds_ref_val, controller_key,
            unit_number)