示例#1
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.
        """
        compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone
        # GCE expects instance name in format
        # "[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?"
        # So we need to construct it for GCE from uuid
        gce_instance_name = 'inst-' + instance.uuid
        LOG.info("Creating instance %s as %s on GCE." %
                 (instance.display_name, gce_instance_name))
        # Image Info
        image_link = instance.system_metadata['image_gce_link']
        # Flavor Info
        flavor_name = instance.flavor.name
        flavor_link = "zones/%s/machineTypes/%s" % (self.gce_zone, flavor_name)
        # Network Info
        network_interfaces = self._process_network_info(network_info)
        # Create Instance
        operation = gceutils.create_instance(compute, project, zone,
                                             gce_instance_name, image_link,
                                             flavor_link, network_interfaces)
        gceutils.wait_for_operation(compute, project, operation)
        gce_instance = gceutils.get_instance(compute, project, zone,
                                             gce_instance_name)
        # Update GCE info in openstack instance metadata
        instance.metadata.update({'gce_id': gce_instance['name']})
        gce_metadata = [
            {
                'key': 'openstack_id',
                'value': instance.uuid
            },
        ]
        ssh_keys = self._process_ssh_keys(instance)
        if ssh_keys:
            gce_metadata.append(ssh_keys)
        operation = gceutils.set_instance_metadata(
            compute, project, zone, gce_instance['name'], gce_metadata,
            operation='add')
        gceutils.wait_for_operation(compute, project, operation)
        self._uuid_to_gce_instance[instance.uuid] = gceutils.get_instance(
            compute, project, zone, gce_instance_name)
示例#2
0
文件: driver.py 项目: taron-ai/omni
    def get_info(self, instance):
        """Get the current status of an instance, by name (not ID!)
        :param instance: nova.objects.instance.Instance object
        Returns a dict containing:
        :state:           the running state, one of the power_state codes
        :max_mem:         (int) the maximum memory in KBytes allowed
        :mem:             (int) the memory in KBytes used by the domain
        :num_cpu:         (int) the number of virtual CPUs for the domain
        :cpu_time:        (int) the CPU time used in nanoseconds
        """
        compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone
        gce_id = self._get_gce_id_from_instance(instance)
        gce_instance = gceutils.get_instance(compute, project, zone, gce_id)
        power_state = GCE_STATE_MAP[gce_instance['status']]

        gce_flavor = self.gce_flavor_info[instance.flavor.name]
        memory_mb = gce_flavor['memory_mb']
        vcpus = gce_flavor['vcpus']

        return hardware.InstanceInfo(state=power_state,
                                     max_mem_kb=memory_mb * 1024,
                                     mem_kb=memory_mb * 1024,
                                     num_cpu=vcpus,
                                     cpu_time_ns=0,
                                     id=instance.id)
示例#3
0
 def get_info(self, instance):
     compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone
     gce_id = self._get_gce_name_from_instance(instance)
     gce_instance = gceutils.get_instance(compute, project, zone, gce_id)
     power_state = GCE_STATE_MAP[gce_instance['status']]
     return hardware.InstanceInfo(state=power_state)
示例#4
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.
        """
        compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone
        instance_name = instance.name
        LOG.info("Creating instance %s as %s on GCE." %
                 (instance.display_name, instance.name))
        image_link = instance.system_metadata['image_gce_link']
        flavor_name = instance.flavor.name
        flavor_link = "zones/%s/machineTypes/%s" % (self.gce_zone, flavor_name)
        operation = gceutils.create_instance(compute, project, zone,
                                             instance_name, image_link,
                                             flavor_link)
        gceutils.wait_for_operation(compute, project, zone, operation)
        gce_instance = gceutils.get_instance(compute, project, zone,
                                             instance_name)
        # Update GCE info in openstack instance metadata
        instance.metadata.update({'gce_id': gce_instance['name']})
        public_ip_address = gceutils.get_external_ip(compute, project, zone,
                                                     gce_instance)
        if public_ip_address:
            instance.metadata.update({'public_ip_address': public_ip_address})
        operation = gceutils.set_instance_metadata(
            compute,
            project,
            zone,
            gce_instance['name'], [
                {
                    'key': 'openstack_id',
                    'value': instance.uuid
                },
            ],
            operation='add')
        gceutils.wait_for_operation(compute, project, zone, operation)
        self._uuid_to_gce_instance[instance.uuid] = gceutils.get_instance(
            compute, project, zone, instance_name)