Exemplo n.º 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)
Exemplo n.º 2
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,
        )
Exemplo n.º 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,
                          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)
Exemplo n.º 4
0
 def _get_controller_key_and_unit(self, vm_ref, adapter_type):
     LOG.debug("_get_controller_key_and_unit vm: %(vm_ref)s, adapter: "
               "%(adapter)s.",
               {'vm_ref': vm_ref, 'adapter': adapter_type})
     client_factory = self._session.vim.client.factory
     devices = self._session._call_method(vutil,
                                          "get_object_property",
                                          vm_ref,
                                          "config.hardware.device")
     return vm_util.allocate_controller_key_and_unit_number(
         client_factory, devices, adapter_type)
Exemplo n.º 5
0
 def test_allocate_controller_key_and_unit_number_scsi(self):
     # Test that we allocate on existing SCSI controller if there is a free
     # slot on it
     devices = [fake.VirtualLsiLogicController(1000, scsiCtlrUnitNumber=7)]
     for unit_number in range(7):
         disk = fake.VirtualDisk(1000, unit_number)
         devices.append(disk)
     factory = fake.FakeFactory()
     (controller_key, unit_number, controller_spec) = vm_util.allocate_controller_key_and_unit_number(
         factory, devices, "lsiLogic"
     )
     self.assertEqual(1000, controller_key)
     self.assertEqual(8, unit_number)
     self.assertIsNone(controller_spec)
Exemplo n.º 6
0
 def test_allocate_controller_key_and_unit_number_ide_default(self):
     # Test that default IDE controllers are used when there is a free slot
     # on them
     disk1 = fake.VirtualDisk(200, 0)
     disk2 = fake.VirtualDisk(200, 1)
     ide0 = fake.VirtualIDEController(200)
     ide1 = fake.VirtualIDEController(201)
     devices = [disk1, disk2, ide0, ide1]
     (controller_key, unit_number, controller_spec) = vm_util.allocate_controller_key_and_unit_number(
         None, devices, "ide"
     )
     self.assertEqual(201, controller_key)
     self.assertEqual(0, unit_number)
     self.assertIsNone(controller_spec)
Exemplo n.º 7
0
 def test_allocate_controller_key_and_unit_number_scsi(self):
     # Test that we allocate on existing SCSI controller if there is a free
     # slot on it
     devices = [fake.VirtualLsiLogicController(1000, scsiCtlrUnitNumber=7)]
     for unit_number in range(7):
         disk = fake.VirtualDisk(1000, unit_number)
         devices.append(disk)
     factory = fake.FakeFactory()
     (controller_key, unit_number,
      controller_spec) = vm_util.allocate_controller_key_and_unit_number(
          factory, devices, 'lsiLogic')
     self.assertEqual(1000, controller_key)
     self.assertEqual(8, unit_number)
     self.assertIsNone(controller_spec)
Exemplo n.º 8
0
 def test_allocate_controller_key_and_unit_number_ide_default(self):
     # Test that default IDE controllers are used when there is a free slot
     # on them
     disk1 = fake.VirtualDisk(200, 0)
     disk2 = fake.VirtualDisk(200, 1)
     ide0 = fake.VirtualIDEController(200)
     ide1 = fake.VirtualIDEController(201)
     devices = [disk1, disk2, ide0, ide1]
     (controller_key, unit_number,
      controller_spec) = vm_util.allocate_controller_key_and_unit_number(
          None, devices, 'ide')
     self.assertEqual(201, controller_key)
     self.assertEqual(0, unit_number)
     self.assertIsNone(controller_spec)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def test_allocate_controller_key_and_unit_number_ide(self):
     # Test that a new controller is created when there is no free slot on
     # the default IDE controllers
     ide0 = fake.VirtualIDEController(200)
     ide1 = fake.VirtualIDEController(201)
     devices = [ide0, ide1]
     for controller_key in [200, 201]:
         for unit_number in [0, 1]:
             disk = fake.VirtualDisk(controller_key, unit_number)
             devices.append(disk)
     factory = fake.FakeFactory()
     (controller_key, unit_number, controller_spec) = vm_util.allocate_controller_key_and_unit_number(
         factory, devices, "ide"
     )
     self.assertEqual(-101, controller_key)
     self.assertEqual(0, unit_number)
     self.assertIsNotNone(controller_spec)
Exemplo n.º 11
0
 def test_allocate_controller_key_and_unit_number_ide(self):
     # Test that a new controller is created when there is no free slot on
     # the default IDE controllers
     ide0 = fake.VirtualIDEController(200)
     ide1 = fake.VirtualIDEController(201)
     devices = [ide0, ide1]
     for controller_key in [200, 201]:
         for unit_number in [0, 1]:
             disk = fake.VirtualDisk(controller_key, unit_number)
             devices.append(disk)
     factory = fake.FakeFactory()
     (controller_key, unit_number,
      controller_spec) = vm_util.allocate_controller_key_and_unit_number(
          factory, devices, 'ide')
     self.assertEqual(-101, controller_key)
     self.assertEqual(0, unit_number)
     self.assertIsNotNone(controller_spec)