示例#1
0
 def get_info(self, instance):
     azure_name = self._get_omni_name_from_instance(instance)
     azure_instance = utils.get_instance(self.compute_client,
                                         drv_conf.resource_group,
                                         azure_name)
     state = self._get_power_state(azure_instance)
     return hardware.InstanceInfo(state=state)
示例#2
0
    def spawn(self,
              context,
              instance,
              image_meta,
              injected_files,
              admin_password,
              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 <Not Yet Implemented>
        :param instance: nova.objects.instance.Instance
                         This function should use the data there to guide
                         the creation of the new instance.
        :param image_meta: image object returned by nova.image.glance that
                           defines the image from which to boot this instance
        :param injected_files: User files to inject into instance.
        :param admin_password: set in instance. <Not Yet Implemented>
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices to be
                                  attached to the instance.
        """
        vm_params = self._prepare_vm_params(instance, network_info,
                                            admin_password)
        name = self._azure_instance_name(instance)
        LOG.info("Spawning vm %s with params %s" % (name, vm_params))
        utils.create_or_update_instance(self.compute_client,
                                        drv_conf.resource_group, name,
                                        vm_params)
        tags = {
            'location': drv_conf.region,
            'tags': {
                'openstack_id': instance.uuid,
                'openstack_project_id': context.project_id,
                'openstack_user_id': context.user_id
            }
        }
        utils.create_or_update_instance(self.compute_client,
                                        drv_conf.resource_group, name, tags)
        az_instance = utils.get_instance(self.compute_client,
                                         drv_conf.resource_group, name)
        self._uuid_to_omni_instance[instance.uuid] = az_instance
        instance.metadata.update({
            OMNI_NAME: name,
            constants.OMNI_ID: az_instance.id
        })
示例#3
0
    def attach_volume(self,
                      context,
                      connection_info,
                      instance,
                      mountpoint,
                      disk_bus=None,
                      device_type=None,
                      encryption=None):
        """Attach the disk to the instance at mountpoint using info."""
        def _check_available_lun(data_disks):
            # We can attach upto 16 data disks to an instance
            luns = [i.lun for i in data_disks]
            for i in range(1, 16):
                if i not in luns:
                    return i
            raise Exception("Could not attach volume")

        volume_data = connection_info['data']
        azure_name = self._get_omni_name_from_instance(instance)
        azure_instance = utils.get_instance(self.compute_client,
                                            drv_conf.resource_group,
                                            azure_name)
        data_disks = azure_instance.storage_profile.data_disks
        lun = _check_available_lun(data_disks)
        name = volume_data['name']
        id = volume_data['id']
        data_disk = {
            'name': name,
            'create_option': 'attach',
            'lun': lun,
            'managed_disk': {
                'id': id
            }
        }
        data_disks.append(data_disk)
        utils.create_or_update_instance(self.compute_client,
                                        drv_conf.resource_group, azure_name,
                                        azure_instance)
        LOG.info("Attached volume %s to instance %s" % (name, instance.uuid))
示例#4
0
 def detach_volume(self,
                   connection_info,
                   instance,
                   mountpoint,
                   encryption=None):
     """Detach the disk attached to the instance."""
     volume_data = connection_info['data']
     azure_name = self._get_omni_name_from_instance(instance)
     azure_instance = utils.get_instance(
         self.compute_client, drv_conf.resource_group, azure_name)
     data_disks = azure_instance.storage_profile.data_disks
     name = volume_data['name']
     filtered_disks = [disk for disk in data_disks if disk.name != name]
     if len(filtered_disks) == len(data_disks):
         LOG.error("Volume %s was not attached to instance %s" %
                   (name, instance.uuid))
         return
     azure_instance.storage_profile.data_disks = filtered_disks
     utils.create_or_update_instance(self.compute_client,
                                     drv_conf.resource_group, azure_name,
                                     azure_instance)
     LOG.info("Detached volume %s from instance %s" % (name, instance.uuid))