示例#1
0
文件: volumeops.py 项目: B3n0n3/nova
    def _attach_volume_vmdk(self, connection_info, instance,
                            adapter_type=None):
        """Attach vmdk volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        LOG.debug("_attach_volume_vmdk: %s", connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)
        adapter_type = adapter_type or vmdk.adapter_type

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE and
            adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % adapter_type
            raise exception.Invalid(msg)

        # Attach the disk to virtual machine instance
        self.attach_disk_to_vm(vm_ref, instance, adapter_type, vmdk.disk_type,
                               vmdk_path=vmdk.path)

        # Store the uuid of the volume_device
        self._update_volume_details(vm_ref, data['volume_id'],
                                    vmdk.device.backing.uuid)

        LOG.debug("Attached VMDK: %s", connection_info, instance=instance)
示例#2
0
文件: volumeops.py 项目: B3n0n3/nova
    def _detach_volume_vmdk(self, connection_info, instance):
        """Detach volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Detach Volume from VM
        LOG.debug("_detach_volume_vmdk: %s", connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        device = self._get_vmdk_backed_disk_device(vm_ref, data)

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE and
            vmdk.adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % vmdk.adapter_type
            raise exception.Invalid(msg)

        self._consolidate_vmdk_volume(instance, vm_ref, device, volume_ref,
                                      adapter_type=vmdk.adapter_type,
                                      disk_type=vmdk.disk_type)

        self.detach_disk_from_vm(vm_ref, instance, device)

        # Remove key-value pair <volume_id, vmdk_uuid> from instance's
        # extra config. Setting value to empty string will remove the key.
        self._update_volume_details(vm_ref, data['volume_id'], "")

        LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
示例#3
0
    def _attach_volume_vmdk(self,
                            connection_info,
                            instance,
                            adapter_type=None):
        """Attach vmdk volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        LOG.debug("_attach_volume_vmdk: %s",
                  connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)
        adapter_type = adapter_type or vmdk.adapter_type

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE
                and adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % adapter_type
            raise exception.Invalid(msg)

        # Attach the disk to virtual machine instance
        self.attach_disk_to_vm(vm_ref,
                               instance,
                               adapter_type,
                               vmdk.disk_type,
                               vmdk_path=vmdk.path)

        # Store the uuid of the volume_device
        self._update_volume_details(vm_ref, data['volume_id'],
                                    vmdk.device.backing.uuid)

        LOG.debug("Attached VMDK: %s", connection_info, instance=instance)
示例#4
0
    def _detach_volume_vmdk(self, connection_info, instance):
        """Detach volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Detach Volume from VM
        LOG.debug("_detach_volume_vmdk: %s",
                  connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        device = self._get_vmdk_backed_disk_device(vm_ref, data)

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE
                and vmdk.adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % vmdk.adapter_type
            raise exception.Invalid(msg)

        self._consolidate_vmdk_volume(instance,
                                      vm_ref,
                                      device,
                                      volume_ref,
                                      adapter_type=vmdk.adapter_type,
                                      disk_type=vmdk.disk_type)

        self.detach_disk_from_vm(vm_ref, instance, device)
        LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
示例#5
0
    def _detach_volume_vmdk(self, connection_info, instance):
        """Detach volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Detach Volume from VM
        LOG.debug("_detach_volume_vmdk: %s", connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        device = self._get_vmdk_backed_disk_device(vm_ref, data)

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)

        # IDE does not support disk hotplug
        if vmdk.adapter_type == constants.ADAPTER_TYPE_IDE:
            state = vm_util.get_vm_state(self._session, instance)
            if state.lower() != 'poweredoff':
                raise exception.Invalid(_('%s does not support disk '
                                          'hotplug.') % vmdk.adapter_type)

        self._consolidate_vmdk_volume(instance, vm_ref, device, volume_ref,
                                      adapter_type=vmdk.adapter_type,
                                      disk_type=vmdk.disk_type)

        self.detach_disk_from_vm(vm_ref, instance, device)

        # Remove key-value pair <volume_id, vmdk_uuid> from instance's
        # extra config. Setting value to empty string will remove the key.
        self._update_volume_details(vm_ref, data['volume_id'], "")

        LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
示例#6
0
文件: images.py 项目: andymcc/nova
def fetch_image_stream_optimized(context, instance, session, vm_name,
                                 ds_name, vm_folder_ref, res_pool_ref):
    """Fetch image from Glance to ESX datastore."""
    image_ref = instance.image_ref
    LOG.debug("Downloading image file data %(image_ref)s to the ESX "
              "as VM named '%(vm_name)s'",
              {'image_ref': image_ref, 'vm_name': vm_name},
              instance=instance)

    metadata = IMAGE_API.get(context, image_ref)
    file_size = int(metadata['size'])

    vm_import_spec = _build_import_spec_for_import_vapp(
            session, vm_name, ds_name)

    read_iter = IMAGE_API.download(context, image_ref)
    read_handle = rw_handles.ImageReadHandle(read_iter)

    write_handle = rw_handles.VmdkWriteHandle(session,
                                              session._host,
                                              session._port,
                                              res_pool_ref,
                                              vm_folder_ref,
                                              vm_import_spec,
                                              file_size)
    image_transfer(read_handle, write_handle)

    imported_vm_ref = write_handle.get_imported_vm()

    LOG.info(_LI("Downloaded image file data %(image_ref)s"),
             {'image_ref': instance.image_ref}, instance=instance)
    vmdk = vm_util.get_vmdk_info(session, imported_vm_ref, vm_name)
    session._call_method(session.vim, "UnregisterVM", imported_vm_ref)
    LOG.info(_LI("The imported VM was unregistered"), instance=instance)
    return vmdk.capacity_in_bytes
示例#7
0
def fetch_image_stream_optimized(context, instance, session, vm_name,
                                 ds_name, vm_folder_ref, res_pool_ref):
    """Fetch image from Glance to ESX datastore."""
    image_ref = instance.image_ref
    LOG.debug("Downloading image file data %(image_ref)s to the ESX "
              "as VM named '%(vm_name)s'",
              {'image_ref': image_ref, 'vm_name': vm_name},
              instance=instance)

    metadata = IMAGE_API.get(context, image_ref)
    file_size = int(metadata['size'])

    vm_import_spec = _build_import_spec_for_import_vapp(
            session, vm_name, ds_name)

    read_iter = IMAGE_API.download(context, image_ref)
    read_handle = rw_handles.ImageReadHandle(read_iter)

    write_handle = rw_handles.VmdkWriteHandle(session,
                                              session._host,
                                              session._port,
                                              res_pool_ref,
                                              vm_folder_ref,
                                              vm_import_spec,
                                              file_size)
    image_transfer(read_handle, write_handle)

    imported_vm_ref = write_handle.get_imported_vm()

    LOG.info("Downloaded image file data %(image_ref)s",
             {'image_ref': instance.image_ref}, instance=instance)
    vmdk = vm_util.get_vmdk_info(session, imported_vm_ref, vm_name)
    session._call_method(session.vim, "UnregisterVM", imported_vm_ref)
    LOG.info("The imported VM was unregistered", instance=instance)
    return vmdk.capacity_in_bytes
示例#8
0
    def _attach_volume_iscsi(self,
                             connection_info,
                             instance,
                             adapter_type=None):
        """Attach iscsi volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Attach Volume to VM
        LOG.debug("_attach_volume_iscsi: %s",
                  connection_info,
                  instance=instance)

        data = connection_info['data']

        # Discover iSCSI Target
        device_name = self._iscsi_discover_target(data)[0]
        if device_name is None:
            raise exception.StorageError(
                reason=_("Unable to find iSCSI Target"))

        vmdk = vm_util.get_vmdk_info(self._session, vm_ref)
        adapter_type = adapter_type or vmdk.adapter_type

        self.attach_disk_to_vm(vm_ref,
                               instance,
                               adapter_type,
                               'rdmp',
                               device_name=device_name)
        LOG.debug("Attached ISCSI: %s", connection_info, instance=instance)
示例#9
0
文件: images.py 项目: runt18/nova
def fetch_image_ova(context, instance, session, vm_name, ds_name,
                    vm_folder_ref, res_pool_ref):
    """Download the OVA image from the glance image server to the
    Nova compute node.
    """
    image_ref = instance.image_ref
    LOG.debug("Downloading OVA image file %(image_ref)s to the ESX "
              "as VM named '%(vm_name)s'",
              {'image_ref': image_ref, 'vm_name': vm_name},
              instance=instance)

    metadata = IMAGE_API.get(context, image_ref)
    file_size = int(metadata['size'])

    vm_import_spec = _build_import_spec_for_import_vapp(
        session, vm_name, ds_name)

    read_iter = IMAGE_API.download(context, image_ref)
    read_handle = rw_handles.ImageReadHandle(read_iter)

    with tarfile.open(mode="r|", fileobj=read_handle) as tar:
        vmdk_name = None
        for tar_info in tar:
            if tar_info and tar_info.name.endswith(".ovf"):
                extracted = tar.extractfile(tar_info)
                xmlstr = extracted.read()
                vmdk_name = get_vmdk_name_from_ovf(xmlstr)
            elif vmdk_name and tar_info.name.startswith(vmdk_name):
                # Actual file name is <vmdk_name>.XXXXXXX
                extracted = tar.extractfile(tar_info)
                write_handle = rw_handles.VmdkWriteHandle(
                    session,
                    session._host,
                    session._port,
                    res_pool_ref,
                    vm_folder_ref,
                    vm_import_spec,
                    file_size)
                start_transfer(context,
                               extracted,
                               file_size,
                               write_file_handle=write_handle)
                extracted.close()
                LOG.info(_LI("Downloaded OVA image file %(image_ref)s"),
                    {'image_ref': instance.image_ref}, instance=instance)
                imported_vm_ref = write_handle.get_imported_vm()
                vmdk = vm_util.get_vmdk_info(session,
                                             imported_vm_ref,
                                             vm_name)
                session._call_method(session.vim, "UnregisterVM",
                                     imported_vm_ref)
                LOG.info(_LI("The imported VM was unregistered"),
                         instance=instance)
                return vmdk.capacity_in_bytes
        raise exception.ImageUnacceptable(
            reason=_("Extracting vmdk from OVA failed."),
            image_id=image_ref)
示例#10
0
def fetch_image_ova(context, instance, session, vm_name, ds_name,
                    vm_folder_ref, res_pool_ref):
    """Download the OVA image from the glance image server to the
    Nova compute node.
    """
    image_ref = instance.image_ref
    LOG.debug("Downloading OVA image file %(image_ref)s to the ESX "
              "as VM named '%(vm_name)s'",
              {'image_ref': image_ref, 'vm_name': vm_name},
              instance=instance)

    metadata = IMAGE_API.get(context, image_ref)
    file_size = int(metadata['size'])

    vm_import_spec = _build_import_spec_for_import_vapp(
        session, vm_name, ds_name)

    read_iter = IMAGE_API.download(context, image_ref)
    read_handle = rw_handles.ImageReadHandle(read_iter)

    with tarfile.open(mode="r|", fileobj=read_handle) as tar:
        vmdk_name = None
        for tar_info in tar:
            if tar_info and tar_info.name.endswith(".ovf"):
                extracted = tar.extractfile(tar_info)
                xmlstr = extracted.read()
                vmdk_name = get_vmdk_name_from_ovf(xmlstr)
            elif vmdk_name and tar_info.name.startswith(vmdk_name):
                # Actual file name is <vmdk_name>.XXXXXXX
                extracted = tar.extractfile(tar_info)
                write_handle = rw_handles.VmdkWriteHandle(
                    session,
                    session._host,
                    session._port,
                    res_pool_ref,
                    vm_folder_ref,
                    vm_import_spec,
                    file_size)
                image_transfer(extracted, write_handle)
                LOG.info("Downloaded OVA image file %(image_ref)s",
                         {'image_ref': instance.image_ref}, instance=instance)
                imported_vm_ref = write_handle.get_imported_vm()
                vmdk = vm_util.get_vmdk_info(session,
                                             imported_vm_ref,
                                             vm_name)
                session._call_method(session.vim, "UnregisterVM",
                                     imported_vm_ref)
                LOG.info("The imported VM was unregistered",
                         instance=instance)
                return vmdk.capacity_in_bytes
        raise exception.ImageUnacceptable(
            reason=_("Extracting vmdk from OVA failed."),
            image_id=image_ref)
    def _get_vm_and_vmdk_attribs():
        # Get the vmdk info that the VM is pointing to
        vmdk = vm_util.get_vmdk_info(session, vm_ref)
        if not vmdk.path:
            print "No root disk defined. Unable to snapshot."
            raise error_util.NoRootDiskDefined()

        lst_properties = ["datastore", "summary.config.guestId"]
        props = session._call_method(vutil,
                                     "get_object_properties_dict",
                                     vm_ref,
                                     lst_properties)
        os_type = props['summary.config.guestId']
        datastores = props['datastore']
        return (vmdk, datastores, os_type)
示例#12
0
    def _detach_volume_vmdk(self, connection_info, instance):
        """Detach volume storage to VM instance."""
        # this code is for  sync openstack db, If volume is detached by vmware,
        # don't take the "detach_disk" action
        meta_key = "sync_vmware_os-volume_attachments"
        if meta_key in instance.metadata:
            LOG.debug("Detached VMDK: sync_vmware_os-volume_attachments")
            return

        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Detach Volume from VM
        LOG.debug("_detach_volume_vmdk: %s", connection_info,
                  instance=instance)
        data = connection_info['data']
        volume_ref = self._get_volume_ref(data['volume'])

        device = self._get_vmdk_backed_disk_device(vm_ref, data)

        # Get details required for adding disk device such as
        # adapter_type, disk_type
        vmdk = vm_util.get_vmdk_info(self._session, volume_ref)

        # IDE does not support disk hotplug
        if (instance.vm_state == vm_states.ACTIVE and
            vmdk.adapter_type == constants.ADAPTER_TYPE_IDE):
            msg = _('%s does not support disk hotplug.') % vmdk.adapter_type
            raise exception.Invalid(msg)
        # If the instance is synced from vmware, 
        # don't take the "attach_disk" action
        meta_key = "sync_vmware_" + str(instance.uuid)
        if meta_key not in instance.metadata:
            self._consolidate_vmdk_volume(instance, vm_ref, device, volume_ref,
                                          adapter_type=vmdk.adapter_type,
                                          disk_type=vmdk.disk_type)

            self.detach_disk_from_vm(vm_ref, instance, device)

        # Remove key-value pair <volume_id, vmdk_uuid> from instance's
        # extra config. Setting value to empty string will remove the key.
        self._update_volume_details(vm_ref, data['volume_id'], "")

        LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
示例#13
0
    def _attach_volume_iscsi(self, connection_info, instance):
        """Attach iscsi volume storage to VM instance."""
        vm_ref = vm_util.get_vm_ref(self._session, instance)
        # Attach Volume to VM
        LOG.debug("_attach_volume_iscsi: %s", connection_info,
                  instance=instance)

        data = connection_info['data']

        # Discover iSCSI Target
        device_name = self._iscsi_discover_target(data)[0]
        if device_name is None:
            raise exception.StorageError(
                reason=_("Unable to find iSCSI Target"))

        vmdk = vm_util.get_vmdk_info(self._session, vm_ref)

        self.attach_disk_to_vm(vm_ref, instance,
                               vmdk.adapter_type, 'rdmp',
                               device_name=device_name)
        LOG.debug("Attached ISCSI: %s", connection_info, instance=instance)