feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Commands for reading and manipulating Cloud TPU VM nodes."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA)
class TpuVMNodes(base.Group):
"""List, create, and manage Cloud TPU VM nodes."""

View File

@@ -0,0 +1,25 @@
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
create_request:
collection: tpu.projects.locations.nodes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
resource_method_params:
nodeId: '{nodesId}'
use_relative_name: false
modify_request_hooks:
- googlecloudsdk.command_lib.util.hooks.request_modifiers:SetParentRequestHook

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Commands for reading Cloud TPU VM node accelerator types."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class AcceleratorTypes(base.Group):
"""List or Describe Available Cloud TPU VM node accelerator types."""

View File

@@ -0,0 +1,21 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Describe an accelerator type available for Cloud TPU VM nodes.
description: Get details on an accelerator type.
examples: |
To describe the `v3-8` accelerator type in zone `us-central1-b`, run:
$ {command} v3-8 --zone=us-central1-b
request:
collection: tpu.projects.locations.acceleratorTypes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
arguments:
resource:
help_text: Name of the accelerator type to describe.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:acceleratortype

View File

@@ -0,0 +1,23 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: List available accelerator types for Cloud TPU VM nodes.
description: List available accelerator types for for Cloud TPU VM nodes.
examples: |
To list all of the accelerator types available in zone `us-central1-b`, run:
$ {command} --zone=us-central1-b
request:
collection: tpu.projects.locations.acceleratorTypes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
arguments:
resource:
help_text: Zone to list accelerator types for.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:location
output:
format: table(type:label=ACCELERATOR_TYPE:sort=1)

View File

@@ -0,0 +1,179 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for attaching a persistent disk to a TPU VM.
Allows TPU VM users to attach persistent disks to TPUs
in a form that is decoupled from the Create and Delete
lifecycle of the actual TPU VM.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import re
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute.tpus.tpu_vm import resource_args
from googlecloudsdk.command_lib.compute.tpus.tpu_vm import util as tpu_utils
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import properties
MODE_OPTIONS = {
'read-write':
('Read-write. It is an error to attach a disk in read-write mode to '
'more than one TPU VM.'),
'read-only':
'Read-only.',
}
DETAILED_HELP = {
'DESCRIPTION':
"""
*{command}* is used to attach a disk to a TPU VM. For example,
$ gcloud compute tpus tpu-vm attach-disk example-tpu --disk=example-disk --mode=read-only --zone=us-central1-a
attaches the disk named 'example-disk' to a TPU VM named
'example-tpu' in read-only mode in zone ``us-central1-a''.
""",
'EXAMPLES':
"""
To attach a disk named 'my-disk' for read-only access to a TPU named
'my-tpu', run:
$ {command} my-tpu --disk=my-disk --mode=read-only
To attach a disk named 'my-read-write-disk' for read-write access to
a TPU named 'my-tpu', run:
$ {command} my-tpu --disk=my-read-write-disk
To attach a regional disk named for read-write access to a TPU named
'my-tpu', run:
$ {command} my-tpu --disk=projects/tpu-test-env-one-vm/region/us-central1/disks/example-disk
""",
}
def AddTPUResourceArg(parser, verb):
"""Adds a TPU Name resource argument.
NOTE: May be used only if it's the only resource arg in the command.
Args:
parser: the argparse parser for the command.
verb: str, the verb to describe the resource, such as 'to attach'.
"""
concept_parsers.ConceptParser.ForResource(
'tpu',
resource_args.GetTPUResourceSpec('TPU'),
'The TPU function name {}.'.format(verb),
required=True).AddToParser(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AttachDisk(base.Command):
"""Attach disk to TPU VM."""
@staticmethod
def Args(parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
parser.add_argument(
'--disk',
help='The name of the disk to attach to the TPU VM.',
required=True)
parser.add_argument(
'--mode',
choices=MODE_OPTIONS,
default='read-write',
help='Specifies the mode of the disk.')
AddTPUResourceArg(parser, 'to attach disk')
def Run(self, args):
# If zone is not set, retrieve the one from the config.
if args.zone is None:
args.zone = properties.VALUES.compute.zone.Get(required=True)
# Retrieve the TPU node.
tpu_name_ref = args.CONCEPTS.tpu.Parse()
tpu = tpu_utils.TPUNode(self.ReleaseTrack())
node = tpu.Get(tpu_name_ref.Name(), args.zone)
if not tpu_utils.IsTPUVMNode(node):
raise exceptions.BadArgumentException(
'TPU',
'this command is only available for Cloud TPU VM nodes. To access '
'this node, please see '
'https://cloud.google.com/tpu/docs/creating-deleting-tpus.')
if args.mode == 'read-write':
args.mode = tpu.messages.AttachedDisk.ModeValueValuesEnum.READ_WRITE
elif args.mode == 'read-only':
args.mode = tpu.messages.AttachedDisk.ModeValueValuesEnum.READ_ONLY
else:
raise exceptions.BadArgumentException(
'mode', 'can only attach disks in read-write or read-only mode.'
)
source_path_match = re.match(r'projects/.+/(zones|regions)/.+/disks/.+',
args.disk)
if source_path_match:
source_path = args.disk
else:
project = properties.VALUES.core.project.Get(required=True)
source_path = (
'projects/' + project + '/zones/' + args.zone + '/disks/' + args.disk
)
if not node.dataDisks:
disk_to_attach = tpu.messages.AttachedDisk(
mode=args.mode,
sourceDisk=source_path
)
node.dataDisks.append(disk_to_attach)
else:
source_disk_list = []
for disk in node.dataDisks:
source_disk_list.append(disk.sourceDisk)
if source_path not in source_disk_list:
disk_to_attach = tpu.messages.AttachedDisk(
mode=args.mode,
sourceDisk=source_path
)
node.dataDisks.append(disk_to_attach)
else:
raise exceptions.BadArgumentException(
'TPU', 'disk is already attached to the TPU VM.')
return tpu.UpdateNode(
name=tpu_name_ref.Name(),
zone=args.zone,
node=node,
update_mask='data_disks',
poller_message='Attaching disk to TPU VM',
)
AttachDisk.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,103 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Create a new Cloud TPU VM node.
description: Create a new Cloud TPU VM node.
examples: |
To create a TPU VM node with ID `my-tpu` in the default user project, network and
compute/zone (with other defaults supplied by API), run:
$ {command} my-tpu
To create a TPU VM node in a specific network, run:
$ {command} my-tpu --zone=us-central1-a --network=my-tf-network --description='My TPU VM' --version='v2-alpha'
To create a small TPU VM v2 pod, run:
$ {command} my-tpu --zone=us-central1-a --accelerator-type='v2-32' --description='My TPU VM' --version='v2-alpha'
request:
_COMMON_: create_request
ALPHA:
api_version: v2alpha1
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:MergeMetadata:api_version=v2alpha1
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:ParseBootDiskConfigurations:api_version=v2alpha1
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:SetImage:api_version=v2alpha1
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:CreateReservationName
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:SetProvisioningModel:api_version=v2alpha1
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:RemoveConflictingDefaults
- googlecloudsdk.command_lib.util.hooks.request_modifiers:SetParentRequestHook
GA:
api_version: v2
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:MergeMetadata:api_version=v2
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:ParseBootDiskConfigurations:api_version=v2
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:RemoveConflictingDefaults
- googlecloudsdk.command_lib.util.hooks.request_modifiers:SetParentRequestHook
async:
collection: tpu.projects.locations.operations
result_attribute: response
extract_resource_result: false
arguments:
resource:
help_text: Name of the Cloud TPU VM node to create.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu
params:
- group:
help_text: Specify a TPU node in either chips or cores
required: false
mutex: true
params:
- group:
help_text: Core based TPU configuration
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:accelerator_type
- group:
help_text: Chip based TPU configuration
required: false
mutex: false
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:type
api_field: node.acceleratorConfig.type
required: true
release_tracks: [ALPHA]
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:ga-type
api_field: node.acceleratorConfig.type
required: true
release_tracks: [GA]
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:topology
api_field: node.acceleratorConfig.topology
required: true
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:description
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:network
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:subnetwork
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:enable_external_ips
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:queue_count
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:version
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:preemptible
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:spot
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:reserved
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:range
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:service_account
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:service_account_scopes
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:labels
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:metadata
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:metadata_from_file
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:tags
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:data_disks
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:enable_secure_boot
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:boot_disk
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:image
release_tracks: [ALPHA]
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:autocheckpoint_enabled
release_tracks: [ALPHA]
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:reservation
release_tracks: [ALPHA]
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:provisioning_model
release_tracks: [ALPHA]

View File

@@ -0,0 +1,28 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Delete a Cloud TPU VM node.
description: Delete a Cloud TPU VM node.
examples: |
To delete a TPU VM with ID `my-tpu` in zone `us-central1-b`, run:
$ {command} my-tpu --zone=us-central1-b
request:
collection: tpu.projects.locations.nodes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
async:
collection: tpu.projects.locations.operations
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
extract_resource_result: false
arguments:
resource:
help_text: Name of the Cloud TPU VM node to delete.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu

View File

@@ -0,0 +1,24 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Describe a Cloud TPU VM node.
description: Describe a Cloud TPU VM node.
examples: |
To describe a Cloud TPU VM node with ID `my-tpu` in zone `us-central1-b`, run:
$ {command} my-tpu --zone=us-central1-b
request:
collection: tpu.projects.locations.nodes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
response:
modify_response_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:CheckTPUVMNode
arguments:
resource:
help_text: Name of the Cloud TPU VM node to describe.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu

View File

@@ -0,0 +1,149 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for detaching a persistent disk to a TPU VM.
Allows TPU VM users to detach persistent disks to TPUs
in a form that is decoupled from the Create and Delete
lifecycle of the actual TPU VM.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import re
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute.tpus.tpu_vm import resource_args
from googlecloudsdk.command_lib.compute.tpus.tpu_vm import util as tpu_utils
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import properties
DETAILED_HELP = {
'DESCRIPTION':
"""
*{command}* is used to detach a disk from a TPU VM. For example,
$ gcloud compute tpus tpu-vm detach-disk example-tpu --disk=example-disk --zone=us-central1-a
detaches the disk named `example-disk` from the TPU VM named
`example-tpu` in zone ``us-central1-a''.
""",
'EXAMPLES':
"""
To detach a disk named `my-disk` from a TPU named `my-tpu`, run:
$ {command} my-tpu --disk=my-disk
To detach a regional disk with the below path from a TPU named `my-tpu`, run:
$ {command} my-tpu --disk=projects/tpu-test-env-one-vm/region/us-central1/disks/example-disk
""",
}
def AddTPUResourceArg(parser, verb):
"""Adds a TPU Name resource argument.
NOTE: May be used only if it's the only resource arg in the command.
Args:
parser: the argparse parser for the command.
verb: str, the verb to describe the resource, such as 'to detach'.
"""
concept_parsers.ConceptParser.ForResource(
'tpu',
resource_args.GetTPUResourceSpec('TPU'),
'The TPU {} from.'.format(verb),
required=True).AddToParser(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DetachDisk(base.Command):
"""Detach a disk from an instance."""
@staticmethod
def Args(parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
parser.add_argument(
'--disk',
help='Name of the disk to detach from the TPU VM.',
required=True)
AddTPUResourceArg(parser, 'to detach disk')
def Run(self, args):
# If zone is not set, retrieve the one from the config.
if args.zone is None:
args.zone = properties.VALUES.compute.zone.Get(required=True)
# Retrieve the TPU node.
tpu_name_ref = args.CONCEPTS.tpu.Parse()
tpu = tpu_utils.TPUNode(self.ReleaseTrack())
node = tpu.Get(tpu_name_ref.Name(), args.zone)
if not tpu_utils.IsTPUVMNode(node):
raise exceptions.BadArgumentException(
'TPU',
'this command is only available for Cloud TPU VM nodes. To access '
'this node, please see '
'https://cloud.google.com/tpu/docs/creating-deleting-tpus.')
if not node.dataDisks:
raise exceptions.BadArgumentException(
'TPU', 'no data disks to detach from current TPU VM.')
source_path_match = re.match(r'projects/.+/(zones|regions)/.+/disks/.+',
args.disk)
if source_path_match:
source_path = args.disk
else:
project = properties.VALUES.core.project.Get(required=True)
source_path = (
'projects/' + project + '/zones/' + args.zone + '/disks/' + args.disk
)
source_disk_list = []
for disk in node.dataDisks:
source_disk_list.append(disk.sourceDisk)
for i, source_disk in enumerate(source_disk_list):
if source_path != source_disk:
continue
if source_path == source_disk:
del node.dataDisks[i]
break
else:
raise exceptions.BadArgumentException(
'TPU',
'error: specified data disk is not currently attached to the TPU VM.',
)
return tpu.UpdateNode(
tpu_name_ref.Name(),
args.zone,
node,
'data_disks',
'Detaching disk from TPU VM',
)
DetachDisk.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,54 @@
- release_tracks: [GA, ALPHA]
command_type: LIST
help_text:
brief: Retrieve the Guest Attributes for a Cloud TPU VM.
description: Retrieve the Guest Attributes for a Cloud TPU VM.
examples: |
To retrieve the guest attributes, run:
$ {command} my-tpu --zone=us-central1-b
To select only a specific query path, use the --query-path flag:
$ {command} my-tpu --zone=us-central1-b --query-path=lifecycle/event
To only display the guest attributes for one of the workers in a TPU pod, use the --filter
flag:
$ {command} my-tpu --zone=us-central1-b --filter="worker_id:3"
where 3 is an example of the worker ID (0-indexed).
request:
collection: tpu.projects.locations.nodes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
method: getGuestAttributes
response:
modify_response_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:TransformGuestAttributes
arguments:
resource:
help_text: Name of the Cloud TPU VM.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu
params:
- arg_name: query-path
api_field: getGuestAttributesRequest.queryPath
required: false
help_text: |
Attribute path to query. Can be empty string or of the form `<namespace>/` or
`<namespace>/<key>`. Default is the empty string.
output:
format: |
table(
namespace,
key,
worker_id,
value
)

View File

@@ -0,0 +1,45 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: List Cloud TPU VM nodes.
description: List Cloud TPU VM nodes.
examples: |
To list the Cloud TPU VM nodes in zone `us-central1-b`, run:
$ {command} --zone=us-central1-b
request:
collection: tpu.projects.locations.nodes
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
response:
id_field: name
modify_response_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:FilterTPUVMNodes
arguments:
resource:
help_text: |
Zone of the Cloud TPU VM node.
If not specified, will use the value of the [compute/zone] property in the current
gcloud configuration. To find a list of compute zones available for Cloud TPUs in your
project, run `{grandparent_command} locations list`.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:location
is_positional: false
output:
format: |
table(
name.basename(),
name.segment(-3):label=ZONE,
acceleratorType.basename():label=ACCELERATOR_TYPE,
acceleratorConfig.type.basename():label=TYPE,
acceleratorConfig.topology.basename():label=TOPOLOGY,
networkConfig.network.basename():label=NETWORK,
cidrBlock:label=RANGE,
state:label=STATUS
)

View File

@@ -0,0 +1,24 @@
- release_tracks: [ALPHA]
request:
collection: tpu.projects.locations.nodes
api_version: v2alpha1
method: performMaintenance
help_text:
brief: perform maintenance on a Cloud TPU VM.
description: perform maintenance on a Cloud TPU VM.
examples: |
The following example command performs maintenance on a Cloud TPU named "my-tpu" in the zone
"us-central1-b" of the default project.
$ {command} my-tpu --zone=us-central1-b
arguments:
resource:
help_text: The Cloud TPU on which to perform maintenance.
spec: !REF googlecloudsdk.command_lib.compute.tpus.resources:tpu
async:
collection: tpu.projects.locations.operations
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
extract_resource_result: false

View File

@@ -0,0 +1,152 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to SCP to/from a Cloud TPU VM Node."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from argcomplete.completers import FilesCompleter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags
from googlecloudsdk.command_lib.compute import ssh_utils
from googlecloudsdk.command_lib.compute.tpus.tpu_vm import ssh as tpu_ssh_utils
from googlecloudsdk.command_lib.util.ssh import ssh
from googlecloudsdk.core import properties
def AddSCPArgs(parser):
"""Additional flags and positional args to be passed to *scp(1)*."""
parser.add_argument(
'--scp-flag',
action='append',
help="""\
Additional flags to be passed to *scp(1)*. This flag may be repeated.
""")
parser.add_argument(
'sources',
completer=FilesCompleter,
help='Specifies the files to copy.',
metavar='[[USER@]INSTANCE:]SRC',
nargs='+')
parser.add_argument(
'destination',
help='Specifies a destination for the source files.',
metavar='[[USER@]INSTANCE:]DEST')
parser.add_argument(
'--recurse', action='store_true', help='Upload directories recursively.')
parser.add_argument(
'--compress', action='store_true', help='Enable compression.')
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Scp(base.Command):
"""Copy files to and from a Cloud TPU VM via SCP."""
# IAP and Batching are not available for GA.
_ENABLE_IAP = False
_ENABLE_BATCHING = False
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
ssh_utils.BaseSSHCLIHelper.Args(parser)
tpu_ssh_utils.AddTPUSSHArgs(parser, cls._ENABLE_IAP, cls._ENABLE_BATCHING)
AddSCPArgs(parser)
flags.AddZoneFlag(parser, resource_type='tpu', operation_type='scp')
def Run(self, args):
dst = ssh.FileReference.FromPath(args.destination)
srcs = [ssh.FileReference.FromPath(src) for src in args.sources]
ssh.SCPCommand.Verify(srcs, dst, single_remote=True)
remote = dst.remote or srcs[0].remote
tpu_name = remote.host
if not dst.remote: # Make sure all remotes point to the same ref.
for src in srcs:
src.remote = remote
username_requested = True
if not remote.user:
username_requested = False
remote.user = ssh.GetDefaultSshUsername(warn_on_account_user=True)
# If zone is not set, retrieve the one from the config.
if args.zone is None:
args.zone = properties.VALUES.compute.zone.Get(required=True)
prepped_node = [None]
tpu_ssh_utils.PrepareNodeForSCP(
tpu_name,
args,
self.ReleaseTrack(),
self._ENABLE_BATCHING,
username_requested,
prepped_node,
0,
srcs,
dst,
remote,
)
scp_batch_size = 1
if self._ENABLE_BATCHING and prepped_node[0]:
scp_batch_size = tpu_ssh_utils.ParseBatchSize(
args.batch_size, len(prepped_node[0].worker_ips)
)
tpu_ssh_utils.SCPIntoPreppedNodes(prepped_node, args, scp_batch_size)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class ScpAlpha(Scp):
"""Copy files to and from a Cloud TPU VM via SCP (Alpha)."""
_ENABLE_IAP = True
_ENABLE_BATCHING = True
Scp.detailed_help = {
'brief':
'Copy files to and from a Cloud TPU VM via SCP.',
'EXAMPLES':
"""
To copy a file (for example, a text file in the local home directory) to
a Cloud TPU VM, run:
$ {command} ~/my-file my-tpu:
To copy a file into all workers in a Cloud TPU VM, run:
$ {command} ~/my-file my-tpu: --worker=all
To copy a file from a Cloud TPU VM to the home directory of the local
computer, run:
$ {command} my-tpu:~/my-file ~/
To copy all files in a folder to a Cloud TPU VM, run:
$ {command} ~/my-folder/ my-tpu: --recurse
"""
}

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Commands for Cloud TPU VM service identity."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class ServiceIdentity(base.Group):
"""Commands for Cloud TPU VM service identity."""

View File

@@ -0,0 +1,41 @@
- release_tracks: [GA, ALPHA]
command_type: GENERIC
help_text:
brief: Create a Cloud TPU VM service identity for a project.
description: |
Create a Cloud TPU VM service identity for a project.
The Cloud TPU VM creates a service identity (Google-owned service account) for management of
resources when the first Cloud TPU VM is created in a project after TPU service activation.
However, there are cases where the service identity may need to be created
beforehand to grant specific IAM permissions to it, like access to a Google Cloud Storage
bucket. This method generates the service account without need to first create a Cloud TPU
VM.
This command generates a service identity valid for Cloud TPU VMs across all zones in a
project. The zone is required (either set in the gcloud config defaults, as an environment
variable, or `--zone` flag), but the service identity generated will work across all Cloud
TPU VM zones.
examples: |
To generate a Cloud TPU VM service identity for a project (using zone `europe-west4-a`), run:
$ {command} --zone=europe-west4-a
request:
collection: tpu.projects.locations
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
method: generateServiceIdentity
arguments:
resource:
help_text: |
Zone to use for the request.
If not specified, will use the value of the [compute/zone] property in the current
gcloud configuration.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:location
is_positional: false

View File

@@ -0,0 +1,30 @@
- release_tracks: [ALPHA]
request:
collection: tpu.projects.locations.nodes
api_version: v2alpha1
method: simulateMaintenanceEvent
help_text:
brief: Simulates a maintenance event on a Cloud TPU VM.
description: For testing the resilience of applications build on top of Cloud TPUs.
examples: |
The following command simulates a maintenance event on workers 0 and 1 in the Cloud TPU
named "my-tpu" in zone "us-central1-b" of the default project.
$ {command} my-tpu --zone=us-central1-b --workers=0,1
arguments:
resource:
help_text: The Cloud TPU on which to simulate maintenance.
spec: !REF googlecloudsdk.command_lib.compute.tpus.resources:tpu
params:
- api_field: simulateMaintenanceEventRequest.workerIds
arg_name: workers
help_text: |
The zero-based ID(s) of workers on which to simulate maintenance. By default, only
the first (ID 0) worker VM is flagged for maintenance.
async:
collection: tpu.projects.locations.operations
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
extract_resource_result: false

View File

@@ -0,0 +1,204 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to SSH into a Cloud TPU VM Node."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import argparse
import os.path
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute import completers
from googlecloudsdk.command_lib.compute import flags
from googlecloudsdk.command_lib.compute import ssh_utils
from googlecloudsdk.command_lib.compute.tpus.tpu_vm import ssh as tpu_ssh_utils
from googlecloudsdk.core import properties
def AddCommandArgGroup(parser):
"""Argument group for running commands using SSH."""
command_group = parser.add_argument_group(
help='These arguments are used to run commands using SSH.')
command_group.add_argument(
'--command',
help="""\
Command to run on the Cloud TPU VM.
Runs the command on the target Cloud TPU VM and then exits.
Note: in the case of a TPU Pod, it will only run the command in the
workers specified with the `--worker` flag (defaults to worker 0 if not
set).
""")
command_group.add_argument(
'--output-directory',
help="""\
Path to the directory to output the logs of the commands.
The path can be relative or absolute. The directory must already exist.
If not specified, standard output will be used.
The logs will be written in files named {WORKER_ID}.log. For example:
"2.log".
""")
def AddSSHArgs(parser):
"""Additional flags and positional args to be passed to *ssh(1)*."""
parser.add_argument(
'--ssh-flag',
action='append',
help="""\
Additional flags to be passed to *ssh(1)*. It is recommended that flags
be passed using an assignment operator and quotes. Example:
$ {command} example-instance --zone=us-central1-a --ssh-flag="-vvv" --ssh-flag="-L 80:localhost:80"
This flag will replace occurences of ``%USER%'' and ``%TPU%'' with
their dereferenced values. For example, passing ``80:%TPU%:80`` into
the flag is equivalent to passing ``80:162.222.181.197:80'' to *ssh(1)*
if the external IP address of 'example-instance' is 162.222.181.197.
If connecting to the instance's external IP, then %TPU% is replaced
with that, otherwise it is replaced with the internal IP.
""")
parser.add_argument(
'user_tpu',
completer=completers.InstancesCompleter,
metavar='[USER@]TPU',
help="""\
Specifies the Cloud TPU VM to SSH into.
``USER'' specifies the username with which to SSH. If omitted, the user
login name is used.
``TPU'' specifies the name of the Cloud TPU VM to SSH into.
""")
parser.add_argument(
'ssh_args',
nargs=argparse.REMAINDER,
help="""\
Flags and positionals passed to the underlying ssh implementation.
""",
example="""\
$ {command} example-instance --zone=us-central1-a -- -vvv -L 80:%TPU%:80
""")
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Ssh(base.Command):
"""SSH into a Cloud TPU VM."""
# IAP and Batching are not available for GA.
_ENABLE_IAP = False
_ENABLE_BATCHING = False
@classmethod
def Args(cls, parser):
"""Set up arguments for this command.
Args:
parser: An argparse.ArgumentParser.
"""
ssh_utils.BaseSSHCLIHelper.Args(parser)
AddSSHArgs(parser)
tpu_ssh_utils.AddTPUSSHArgs(parser, enable_iap=cls._ENABLE_IAP,
enable_batching=cls._ENABLE_BATCHING)
AddCommandArgGroup(parser)
flags.AddZoneFlag(parser, resource_type='tpu', operation_type='ssh')
def Run(self, args):
user, tpu_name = ssh_utils.GetUserAndInstance(args.user_tpu)
# If zone is not set, retrieve the one from the config.
if args.zone is None:
args.zone = properties.VALUES.compute.zone.Get(required=True)
# Validate the output path.
if args.output_directory:
if not args.command:
raise exceptions.InvalidArgumentException(
'--output_directory', 'cannot be specified without the `--command` '
'flag. Please specify the `--command` flag or remove the '
'--output-directory flag.')
output_directory_path = os.path.abspath(
os.path.expandvars(os.path.expanduser(args.output_directory)))
if not os.path.isdir(output_directory_path):
raise exceptions.InvalidArgumentException(
'--output_directory', 'Failed to find directory {}. Please create '
'it or specify another directory'.format(output_directory_path))
username_requested = '@' in args.user_tpu
prepped_node = [None]
tpu_ssh_utils.PrepareNodeForSSH(
tpu_name,
user,
args,
self.ReleaseTrack(),
self._ENABLE_BATCHING,
username_requested,
prepped_node,
0,
)
ssh_batch_size = 1
if self._ENABLE_BATCHING and prepped_node[0]:
ssh_batch_size = tpu_ssh_utils.ParseBatchSize(
args.batch_size, len(prepped_node[0].worker_ips)
)
tpu_ssh_utils.SSHIntoPreppedNodes(
prepped_node,
args,
ssh_batch_size,
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class SshAlpha(Ssh):
"""SSH into a Cloud TPU VM (Alpha)."""
_ENABLE_IAP = True
_ENABLE_BATCHING = True
Ssh.detailed_help = {
'brief':
'SSH into a Cloud TPU VM.',
'EXAMPLES':
"""
To SSH into a Cloud TPU VM, run:
$ {command} my-tpu
To SSH into worker 1 on a Cloud TPU VM Pod, run:
$ {command} my-tpu --worker=1
To run an SSH command in a Cloud TPU VM (for example, to print the
time since last boot), run:
$ {command} my-tpu --command="last boot"
To run the same command in all workers in a Cloud TPU VM simultaneously,
run:
$ {command} my-tpu --command="last boot" --worker=all
"""
}

View File

@@ -0,0 +1,33 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Start a Cloud TPU VM node.
description: Start a Cloud TPU VM node.
examples: |
To start a Cloud TPU VM node with ID `my-tpu` in zone `us-central1-b`, run:
$ {command} my-tpu --zone=us-central1-b
request:
collection: tpu.projects.locations.nodes
method: start
ALPHA:
api_version: v2alpha1
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:StartRequestHook:api_version=v2alpha1
GA:
api_version: v2
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:StartRequestHook:api_version=v2
async:
collection: tpu.projects.locations.operations
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
extract_resource_result: false
arguments:
resource:
help_text: Name of the Cloud TPU VM node to start.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu

View File

@@ -0,0 +1,33 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Stop a Cloud TPU VM node.
description: Stop a Cloud TPU VM node.
examples: |
To stop a Cloud TPU VM node with ID `my-tpu` in zone `us-central1-b`, run:
$ {command} my-tpu --zone=us-central1-b
request:
collection: tpu.projects.locations.nodes
method: stop
ALPHA:
api_version: v2alpha1
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:StopRequestHook:api_version=v2alpha1
GA:
api_version: v2
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:StopRequestHook:api_version=v2
async:
collection: tpu.projects.locations.operations
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
extract_resource_result: false
arguments:
resource:
help_text: Name of the Cloud TPU VM node to stop.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu

View File

@@ -0,0 +1,98 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Update a Cloud TPU VM node.
description: Update a Cloud TPU VM node.
examples: |
To modify a TPU VM node with ID `my-tpu` in the default user project and compute/zone by
updating the description to "A new description", run:
$ {command} my-tpu --description="A new description"
To modify a TPU VM node with ID `my-tpu` in the default user project, network and compute/zone
(with other defaults supplied by API) by adding labels `k0`, with value `value0` and label
`k1` with value `value1` and removing labels with key `k2`, run:
$ {command} my-tpu --update-labels=k0=value0,k1=value1 --remove-labels=k2
Labels can be used to identify the TPU VM node. To list TPU VM nodes with the `k1:value1`
label, run:
$ {parent_command} list --filter='labels.k1=value1'
To list only the labels when describing a resource, use `--format` to filter the result:
$ {parent_command} describe my-tpu --format="default(labels)"
request:
collection: tpu.projects.locations.nodes
ALPHA:
api_version: v2alpha1
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:GenerateUpdateMask:api_version=v2alpha1
GA:
api_version: v2
modify_request_hooks:
- googlecloudsdk.command_lib.compute.tpus.tpu_vm.util:GenerateUpdateMask:api_version=v2
async:
collection: tpu.projects.locations.operations
extract_resource_result: false
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
arguments:
resource:
help_text: Name of the Cloud TPU VM node to update.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:tpu
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:description
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:enable_external_ips
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:update_labels
- group:
required: false
mutex: true
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:clear_labels
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:remove_labels
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:add_tags
- group:
required: false
mutex: true
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:clear_tags
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:remove_tags
- group:
required: false
mutex: true
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:metadata_from_file
- group:
required: false
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:update_metadata
- group:
required: false
mutex: true
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:clear_metadata
- _REF_: googlecloudsdk.command_lib.compute.tpus.flags:remove_metadata
- group:
required: false
params:
- group:
mutex: true
params:
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:attach_disk
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:detach_disk
- _REF_: googlecloudsdk.command_lib.compute.tpus.tpu_vm.flags:worker
release_tracks: [ALPHA]
update:
read_modify_update: true
disable_auto_field_mask: true
output:
format: none

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The RuntimeVersions command group for the Cloud TPU CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Versions(base.Group):
"""Explore available runtime versions for Cloud TPU VM nodes."""

View File

@@ -0,0 +1,21 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: Describe a runtime version available for Cloud TPU VM nodes.
description: Get details on a runtime version.
examples: |
To describe the TensorFlow `1.15` runtime version in zone `us-central1-b`, run:
$ {command} 1.15 --zone=us-central1-b
request:
collection: tpu.projects.locations.runtimeVersions
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
arguments:
resource:
help_text: Name of the runtime version to describe.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:runtimeversion

View File

@@ -0,0 +1,23 @@
- release_tracks: [GA, ALPHA]
help_text:
brief: List available runtime versions for Cloud TPU VM nodes.
description: List runtime versions available for Cloud TPU VM nodes.
examples: |
To list all of the runtime versions available in zone `us-central1-b`, run:
$ {command} --zone=us-central1-b
request:
collection: tpu.projects.locations.runtimeVersions
ALPHA:
api_version: v2alpha1
GA:
api_version: v2
arguments:
resource:
help_text: Zone to list runtime versions for.
spec: !REF googlecloudsdk.command_lib.compute.tpus.tpu_vm.resources:location
output:
format: table(version:label=RUNTIME_VERSION:sort=1)