Example #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)
Example #2
0
    def attach_disk_to_vm(self, vm_ref, instance_name,
                          adapter_type, disk_type, vmdk_path=None,
                          disk_size=None, linked_clone=False,
                          controller_key=None, unit_number=None,
                          device_name=None):
        """
        Attach disk to VM by reconfiguration.
        """
        client_factory = self._session._get_vim().client.factory
        vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
                                    client_factory, adapter_type, disk_type,
                                    vmdk_path, disk_size, linked_clone,
                                    controller_key, unit_number, device_name)

        LOG.debug(_("Reconfiguring VM instance %(instance_name)s to attach "
                    "disk %(vmdk_path)s or device %(device_name)s with type "
                    "%(disk_type)s") % locals())
        reconfig_task = self._session._call_method(
                                        self._session._get_vim(),
                                        "ReconfigVM_Task", vm_ref,
                                        spec=vmdk_attach_config_spec)
        self._session._wait_for_task(instance_name, reconfig_task)
        LOG.debug(_("Reconfigured VM instance %(instance_name)s to attach "
                    "disk %(vmdk_path)s or device %(device_name)s with type "
                    "%(disk_type)s") % locals())
Example #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,
        )
Example #4
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)
Example #5
0
 def _attach_vmdk_to_the_vm():
     """
     Attach the vmdk uploaded to the VM. VM reconfigure is done
     to do so.
     """
     vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
         client_factory, vmdk_file_size_in_kb, uploaded_vmdk_path, adapter_type
     )
     LOG.debug(_("Reconfiguring VM instance to attach the image disk"), instance=instance)
     reconfig_task = self._session._call_method(
         self._session._get_vim(), "ReconfigVM_Task", vm_ref, spec=vmdk_attach_config_spec
     )
     self._session._wait_for_task(instance["uuid"], reconfig_task)
     LOG.debug(_("Reconfigured VM instance to attach the image disk"), instance=instance)
Example #6
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)
Example #7
0
 def _attach_vmdk_to_the_vm():
     """
     Attach the vmdk uploaded to the VM. VM reconfigure is done
     to do so.
     """
     vmdk_attach_config_spec = vm_util.get_vmdk_attach_config_spec(
         client_factory, adapter_type, "preallocated",
         uploaded_vmdk_path, vmdk_file_size_in_kb)
     LOG.debug(_("Reconfiguring VM instance to attach the image disk"),
               instance=instance)
     reconfig_task = self._session._call_method(
         self._session._get_vim(),
         "ReconfigVM_Task",
         vm_ref,
         spec=vmdk_attach_config_spec)
     self._session._wait_for_task(instance['uuid'], reconfig_task)
     LOG.debug(_("Reconfigured VM instance to attach the image disk"),
               instance=instance)