def CreateRequests(self, args):
        instances_flags.ValidateDockerArgs(args)
        instances_flags.ValidateDiskCommonFlags(args)
        instances_flags.ValidateLocalSsdFlags(args)
        if instance_utils.UseExistingBootDisk(args.disk or []):
            raise exceptions.InvalidArgumentException(
                '--disk', 'Boot disk specified for containerized VM.')

        scheduling = instance_utils.CreateSchedulingMessage(
            messages=self.messages,
            maintenance_policy=args.maintenance_policy,
            preemptible=args.preemptible,
            restart_on_failure=args.restart_on_failure)

        service_accounts = instance_utils.CreateServiceAccountMessages(
            messages=self.messages,
            scopes=([] if args.no_scopes else args.scopes))

        user_metadata = metadata_utils.ConstructMetadataMessage(
            self.messages,
            metadata=args.metadata,
            metadata_from_file=args.metadata_from_file)
        containers_utils.ValidateUserMetadata(user_metadata)

        boot_disk_size_gb = utils.BytesToGb(args.boot_disk_size)
        utils.WarnIfDiskSizeIsTooSmall(boot_disk_size_gb, args.boot_disk_type)

        instance_refs = instances_flags.INSTANCES_ARG.ResolveAsResource(
            args,
            self.resources,
            scope_lister=flags.GetDefaultScopeLister(self.compute_client,
                                                     self.project))

        # Check if the zone is deprecated or has maintenance coming.
        self.WarnForZonalCreation(instance_refs)

        network_interface = instance_utils.CreateNetworkInterfaceMessage(
            resources=self.resources,
            compute_client=self.compute_client,
            network=args.network,
            subnet=args.subnet,
            private_network_ip=args.private_network_ip,
            no_address=args.no_address,
            address=args.address,
            instance_refs=instance_refs)

        machine_type_uris = instance_utils.CreateMachineTypeUris(
            resources=self.resources,
            compute_client=self.compute_client,
            project=self.project,
            machine_type=args.machine_type,
            custom_cpu=args.custom_cpu,
            custom_memory=args.custom_memory,
            instance_refs=instance_refs)

        image_uri = containers_utils.ExpandGciImageFlag(self.compute_client)
        requests = []
        for instance_ref, machine_type_uri in zip(instance_refs,
                                                  machine_type_uris):
            metadata = containers_utils.CreateMetadataMessage(
                self.messages, args.run_as_privileged, args.container_manifest,
                args.docker_image, args.port_mappings, args.run_command,
                user_metadata, instance_ref.Name())
            requests.append(
                self.messages.ComputeInstancesInsertRequest(
                    instance=self.messages.Instance(
                        canIpForward=args.can_ip_forward,
                        disks=(self._CreateDiskMessages(
                            args, boot_disk_size_gb, image_uri, instance_ref)),
                        description=args.description,
                        machineType=machine_type_uri,
                        metadata=metadata,
                        name=instance_ref.Name(),
                        networkInterfaces=[network_interface],
                        serviceAccounts=service_accounts,
                        scheduling=scheduling,
                        tags=containers_utils.CreateTagsMessage(
                            self.messages, args.tags),
                    ),
                    project=self.project,
                    zone=instance_ref.zone))
        return requests
    def CreateRequests(self, args):
        """Creates and returns an InstanceTemplates.Insert request.

    Args:
      args: the argparse arguments that this command was invoked with.

    Returns:
      request: a ComputeInstanceTemplatesInsertRequest message object
    """
        instances_flags.ValidateDockerArgs(args)
        instances_flags.ValidateDiskCommonFlags(args)
        instances_flags.ValidateLocalSsdFlags(args)
        if instance_utils.UseExistingBootDisk(args.disk or []):
            raise exceptions.InvalidArgumentException(
                '--disk', 'Boot disk specified for containerized VM.')

        boot_disk_size_gb = utils.BytesToGb(args.boot_disk_size)
        utils.WarnIfDiskSizeIsTooSmall(boot_disk_size_gb, args.boot_disk_type)

        instance_template_ref = (
            instance_templates_flags.INSTANCE_TEMPLATE_ARG.ResolveAsResource(
                args, self.resources))

        user_metadata = metadata_utils.ConstructMetadataMessage(
            self.messages,
            metadata=args.metadata,
            metadata_from_file=args.metadata_from_file)
        containers_utils.ValidateUserMetadata(user_metadata)

        network_interface = instance_template_utils.CreateNetworkInterfaceMessage(
            resources=self.resources,
            scope_lister=flags.GetDefaultScopeLister(self.compute_client,
                                                     self.project),
            messages=self.messages,
            network=args.network,
            region=args.region,
            subnet=args.subnet,
            address=(instance_template_utils.EPHEMERAL_ADDRESS
                     if not args.no_address and not args.address else
                     args.address))

        scheduling = instance_utils.CreateSchedulingMessage(
            messages=self.messages,
            maintenance_policy=args.maintenance_policy,
            preemptible=args.preemptible,
            restart_on_failure=args.restart_on_failure)

        service_accounts = instance_utils.CreateServiceAccountMessages(
            messages=self.messages,
            scopes=([] if args.no_scopes else args.scopes))

        image_uri = containers_utils.ExpandGciImageFlag(self.compute_client)

        machine_type = instance_utils.InterpretMachineType(
            machine_type=args.machine_type,
            custom_cpu=args.custom_cpu,
            custom_memory=args.custom_memory)

        metadata = containers_utils.CreateMetadataMessage(
            self.messages, args.run_as_privileged, args.container_manifest,
            args.docker_image, args.port_mappings, args.run_command,
            user_metadata, instance_template_ref.Name())

        request = self.messages.ComputeInstanceTemplatesInsertRequest(
            instanceTemplate=self.messages.InstanceTemplate(
                properties=self.messages.InstanceProperties(
                    machineType=machine_type,
                    disks=self._CreateDiskMessages(args, boot_disk_size_gb,
                                                   image_uri),
                    canIpForward=args.can_ip_forward,
                    metadata=metadata,
                    networkInterfaces=[network_interface],
                    serviceAccounts=service_accounts,
                    scheduling=scheduling,
                    tags=containers_utils.CreateTagsMessage(
                        self.messages, args.tags),
                ),
                description=args.description,
                name=instance_template_ref.Name(),
            ),
            project=self.project)

        return [request]