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,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 gcloud notebooks instances command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Instances(base.Group):
"""Notebooks Instances command group."""

View File

@@ -0,0 +1,21 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Add IAM policy binding for an instance.
description: |
Adds a policy binding to the IAM policy of an instance, given an instance ID and the binding.
examples: |
To add an IAM policy binding for the role of ``roles/notebooks.admin'' for the user 'test-user@gmail.com'
on the instance 'instance-id', run:
$ {command} --member='user:test-user@gmail.com' --role='roles/notebooks.admin' example-instance --location=us-central1-a
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: notebooks.projects.locations.instances
api_version: v1
arguments:
resource:
help_text: The ID of the instance to add the IAM binding.
spec: !REF googlecloudsdk.command_lib.notebooks.resources:instance

View File

@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances create' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for creating notebook instances.
""",
'EXAMPLES':
"""
To create an instance from an environment, run:
$ {command} example-instance --environment=example-env --environment-location=us-central1-a --machine-type=n1-standard-4 --location=us-central1-b
To create an instance from a VmImage family, run:
$ {command} example-instance --vm-image-project=deeplearning-platform-release --vm-image-family=caffe1-latest-cpu-experimental --machine-type=n1-standard-4 --location=us-central1-b
To create an instance from a VmImage name, run:
$ {command} example-instance --vm-image-project=deeplearning-platform-release --vm-image-name=tf2-2-1-cu101-notebooks-20200110 --machine-type=n1-standard-4 --location=us-central1-b
To create an instance from a Container Repository, run:
$ {command} example-instance --container-repository=gcr.io/deeplearning-platform-release/base-cpu --container-tag=test-tag --machine-type=n1-standard-4 --location=us-central1-b
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Request for creating an instance."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddCreateInstanceFlags(api_version, parser)
def Run(self, args):
"""This is what gets called when the user runs this command."""
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Create(
instance_util.CreateInstanceCreateRequest(args, client, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.CREATE)
Create.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances delete' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for deleting notebook instances.
""",
'EXAMPLES':
"""
To delete an instance, run:
$ {command} example-instance --location=us-central1-b
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Request for deleting instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddDeleteInstanceFlags(api_version, parser)
def Run(self, args):
"""This is what gets called when the user runs this command."""
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Delete(
instance_util.CreateInstanceDeleteRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.DELETE)
Delete.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances describe' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for describing notebook instances.
""",
'EXAMPLES':
"""
To describe an instance, run:
$ {command} example-instance --location=us-central1-b
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Request for describing instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddDescribeInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
result = instance_service.Get(
instance_util.CreateInstanceDescribeRequest(args, messages))
return result
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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.
"""'notebooks instances diagnose' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for diagnose notebook instances.
""",
'EXAMPLES':
"""
To diagnose an instance, run:
$ {command} example-instance --location=us-west1-b --gcs-bucket=gs://example-bucket
To diagnose an instance with a relative path:
$ {command} example-instance --location=us-west1-b --gcs-bucket=gs://example-bucket --relative-path=logs
To diagnose an instance, with packet capture:
$ {command} example-instance --location=us-west1-b --gcs-bucket=gs://example-bucket --enable-packet-capture
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Diagnose(base.Command):
"""Request for diagnose instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddDiagnoseInstanceFlags(api_version, parser)
def Run(self, args):
"""This is what gets called when the user runs this command."""
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Diagnose(
instance_util.CreateInstanceDiagnoseRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
Diagnose.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,60 @@
# -*- 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.
"""'notebooks instances get-health' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for checking if a notebook instance is healthy.
""",
'EXAMPLES':
"""
To check if an instance is healthy, run:
$ {command} example-instance --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class GetHealth(base.DescribeCommand):
"""Request for checking if a notebook instance is healthy."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddGetHealthInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
result = instance_service.GetInstanceHealth(
instance_util.CreateInstanceGetHealthRequest(args, messages))
return result
GetHealth.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,22 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get IAM policy for an instance.
description: |
*{command}* displays the IAM policy associated with an instance.
If formatted as JSON, the output can be edited and used as
a policy file for *set-iam-policy*. The output includes an "etag"
field identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given folder, run:
$ {command} my-instance --location=us-central1-a
request:
collection: notebooks.projects.locations.instances
api_version: v1
arguments:
resource:
help_text: The ID of the instance for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.notebooks.resources:instance

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances is-upgradeable' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for checking if a notebook instance is upgradeable.
""",
'EXAMPLES':
"""
To check if an instance can be upgraded, run:
$ {command} example-instance --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class IsUpgradeable(base.DescribeCommand):
"""Request for checking if a notebook instance is upgradeable."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddIsUpgradeableInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
result = instance_service.IsUpgradeable(
instance_util.CreateInstanceIsUpgradeableRequest(args, messages))
return result
IsUpgradeable.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances list' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_errors
from googlecloudsdk.command_lib.notebooks import flags
from googlecloudsdk.core import properties
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for listing instances.
""",
'EXAMPLES':
"""
To list instances in a particular location, run:
$ {command} --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class List(base.ListCommand):
"""Request for listing instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
parser.display_info.AddFormat("""
table(name.segment(-1),
name.segment(-3):label=LOCATION,
name.segment(-5):label=PROJECT,
state,
machineType.segment(-1),
network.segment(-1),
subnet.segment(-1))
""")
parser.display_info.AddUriFunc(instance_util.GetInstanceURI)
flags.AddListInstanceFlags(parser)
def Run(self, args):
"""This is what gets called when the user runs this command."""
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
if (not args.IsSpecified('location')) and (
not properties.VALUES.notebooks.location.IsExplicitlySet()):
raise parser_errors.RequiredError(argument='--location')
instance_service = client.projects_locations_instances
return list_pager.YieldFromList(
instance_service,
instance_util.CreateInstanceListRequest(args, messages),
field='instances',
limit=args.limit,
batch_size_attribute='pageSize')
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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.
"""'notebooks instances migrate' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for migrating notebook instances.
""",
'EXAMPLES':
"""
To migrate an instance, run:
$ {command} example-instance --location=us-central1
To migrate an instance and reuse the post-startup script, run:
$ {command} example-instance --location=us-central1 --post-startup-script-option=POST_STARTUP_SCRIPT_OPTION_RERUN
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Migrate(base.Command):
"""Request for migrating instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddMigrateInstanceFlags(api_version, parser)
def Run(self, args):
"""This is what gets called when the user runs this command."""
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Migrate(
instance_util.CreateInstanceMigrateRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.MIGRATE)
Migrate.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances register' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for registering notebook instances.
""",
'EXAMPLES':
"""
To register an old type instance, run:
$ {command} example-instance --location=us-central1-b
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Register(base.Command):
"""Request for registering instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddRegisterInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Register(
instance_util.CreateInstanceRegisterRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
Register.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,21 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Remove IAM policy binding for an instance.
description: |
Removes a policy binding to the IAM policy of an instance, given an instance ID and the binding.
examples: |
To remove an IAM policy binding for the role of ``roles/editor'' for the user 'test-user@gmail.com'
on the instance 'instance-id', run:
$ {command} example-instance --member='user:test-user@gmail.com' --role='roles/editor' --location=us-central1-a
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: notebooks.projects.locations.instances
api_version: v1
arguments:
resource:
help_text: The ID of the instance to remove the IAM binding.
spec: !REF googlecloudsdk.command_lib.notebooks.resources:instance

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances reset' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for reseting notebook instances.
""",
'EXAMPLES':
"""
To reset an instance, run:
$ {command} example-instance --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Reset(base.Command):
"""Request for resetting instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddResetInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Reset(
instance_util.CreateInstanceResetRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.RESET)
Reset.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,66 @@
# -*- 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.
"""'notebooks instances rollback' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for rolling back notebook instances.
""",
'EXAMPLES':
"""
To rollback an instance, run:
$ {command} example-instance target-snapshot=projects/example-project/global/snapshots/aorlbjvpavvf --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Rollback(base.Command):
"""Request for rolling back instances."""
@classmethod
def Args(cls, parser):
"""Upgrade flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddRollbackInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
if args.IsSpecified('target_snapshot'):
operation = instance_service.Rollback(
instance_util.CreateInstanceRollbackRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.ROLLBACK)
Rollback.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,30 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Set the IAM policy for an Instance.
description: |
*{command}* sets the IAM policy for a Notebook instance given an
instance ID and a JSON or YAML file that describes the IAM policy.
Note: Setting the IAM policy for an Instance replaces existing IAM bindings for
that account.
examples: |
The following command reads an IAM policy defined in the JSON file
`policy.json` and sets it for Instance ID *my_instance* at the
specified locaiton:
$ {command} my_instance --location=us-central1-a policy.json
See https://cloud.google.com/iam/docs/managing-policies for policy file
format and content details.
request:
collection: notebooks.projects.locations.instances
api_version: v1
arguments:
resource:
help_text: The ID of the instance for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.notebooks.resources:instance

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances start' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for starting notebook instances.
""",
'EXAMPLES':
"""
To start an instance, run:
$ {command} example-instance --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Start(base.Command):
"""Request for starting instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddStartInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Start(
instance_util.CreateInstanceStartRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
Start.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances stop' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for stopping notebook instances.
""",
'EXAMPLES':
"""
To stop an instance, run:
$ {command} example-instance --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Stop(base.Command):
"""Request for stopping instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddStopInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Stop(
instance_util.CreateInstanceStopRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
Stop.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances update' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for updating notebook instances.
""",
'EXAMPLES':
"""
To update machine type for an instance, run:
$ {command} example-instance --machine-type=n1-standard-8 --location=us-central1-a
To update labels for an instance, run:
$ {command} example-instance --labels=k1=v1,k2=v2 --location=us-central1-a
To update labels and accelerator cores, run:
$ {command} example-instance --labels=k1=v1,k2=v2 --accelerator-core-count=2 --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Update(base.Command):
"""Request for updating instances."""
@classmethod
def Args(cls, parser):
"""Register flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddUpdateInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
if args.IsSpecified('accelerator_type') or args.IsSpecified(
'accelerator_core_count'):
operation = instance_service.SetAccelerator(
instance_util.CreateSetAcceleratorRequest(args, messages))
instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
if args.IsSpecified('labels'):
operation = instance_service.SetLabels(
instance_util.CreateSetLabelsRequest(args, messages))
instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
if args.IsSpecified('machine_type'):
operation = instance_service.SetMachineType(
instance_util.CreateSetMachineTypeRequest(args, messages))
instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPDATE)
Update.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""'notebooks instances register' command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.notebooks import instances as instance_util
from googlecloudsdk.api_lib.notebooks import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.notebooks import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Request for upgrading notebook instances.
""",
'EXAMPLES':
"""
To upgrade an instance, run:
$ {command} example-instance --location=us-central1-a
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Upgrade(base.Command):
"""Request for upgrading instances."""
@classmethod
def Args(cls, parser):
"""Upgrade flags for this command."""
api_version = util.ApiVersionSelector(cls.ReleaseTrack())
flags.AddUpgradeInstanceFlags(api_version, parser)
def Run(self, args):
release_track = self.ReleaseTrack()
client = util.GetClient(release_track)
messages = util.GetMessages(release_track)
instance_service = client.projects_locations_instances
operation = instance_service.Upgrade(
instance_util.CreateInstanceUpgradeRequest(args, messages))
return instance_util.HandleLRO(
operation,
args,
instance_service,
release_track,
operation_type=instance_util.OperationType.UPGRADE)
Upgrade.detailed_help = DETAILED_HELP