예제 #1
0
    def Run(self, args):
        self._ValidateBetaArgs(args)

        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        source_instance_template = instance_utils.GetSourceInstanceTemplate(
            args, holder.resources, self.SOURCE_INSTANCE_TEMPLATE)
        skip_defaults = instance_utils.GetSkipDefaults(
            source_instance_template)
        scheduling = instance_utils.GetScheduling(args, client, skip_defaults)
        service_accounts = instance_utils.GetServiceAccounts(
            args, client, skip_defaults)
        user_metadata = instance_utils.GetValidatedMetadata(args, client)
        boot_disk_size_gb = instance_utils.GetBootDiskSizeGb(args)
        instance_refs = instance_utils.GetInstanceRefs(args, client, holder)
        network_interfaces = instance_utils.GetNetworkInterfacesBeta(
            args, client, holder, instance_refs, skip_defaults)
        machine_type_uris = instance_utils.GetMachineTypeUris(
            args, client, holder, instance_refs, skip_defaults)
        image_uri = self.GetImageUri(args, client, holder, instance_refs)
        labels = containers_utils.GetLabelsMessageWithCosVersion(
            args.labels, image_uri, holder.resources, client.messages.Instance)
        can_ip_forward = instance_utils.GetCanIpForward(args, skip_defaults)
        tags = containers_utils.CreateTagsMessage(client.messages, args.tags)

        requests = []
        for instance_ref, machine_type_uri in zip(instance_refs,
                                                  machine_type_uris):
            metadata = containers_utils.CreateKonletMetadataMessage(
                client.messages, args, instance_ref.Name(), user_metadata)
            disks = instance_utils.CreateDiskMessages(holder, args,
                                                      boot_disk_size_gb,
                                                      image_uri, instance_ref,
                                                      skip_defaults)
            request = client.messages.ComputeInstancesInsertRequest(
                instance=client.messages.Instance(
                    canIpForward=can_ip_forward,
                    disks=disks,
                    description=args.description,
                    labels=labels,
                    machineType=machine_type_uri,
                    metadata=metadata,
                    minCpuPlatform=args.min_cpu_platform,
                    name=instance_ref.Name(),
                    networkInterfaces=network_interfaces,
                    serviceAccounts=service_accounts,
                    scheduling=scheduling,
                    tags=tags),
                sourceInstanceTemplate=source_instance_template,
                project=instance_ref.project,
                zone=instance_ref.zone)

            requests.append(
                (client.apitools_client.instances, 'Insert', request))

        return client.MakeRequests(requests)
예제 #2
0
 def _GetNetworkInterfaces(self, args, client, holder, instance_refs,
                           skip_defaults):
     return instance_utils.GetNetworkInterfacesBeta(args, client, holder,
                                                    instance_refs,
                                                    skip_defaults)