コード例 #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
    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)