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,36 @@
# -*- 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.
"""Command group for Cloud NetApp Volume Snapshots."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Snapshots(base.Group):
"""Create and manage Cloud NetApp Volume Snapshots."""
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class SnapshotsBeta(Snapshots):
"""Create and manage Cloud NetApp Volume Snapshots."""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class SnapshotsAlpha(SnapshotsBeta):
"""Create and manage Cloud NetApp Volume Snapshots."""

View File

@@ -0,0 +1,97 @@
# -*- 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.
"""Create a Cloud NetApp Volume Snapshot."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.netapp.volumes.snapshots import client as snapshots_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.netapp.volumes.snapshots import flags as snapshots_flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.GA
detailed_help = {
'DESCRIPTION': """\
Create a Cloud NetApp Volume Snapshot.
""",
'EXAMPLES': """\
The following command creates a Snapshot named NAME using the required arguments:
$ {command} NAME --location=us-central1 --volume=vol1
""",
}
@staticmethod
def Args(parser):
snapshots_flags.AddSnapshotCreateArgs(parser)
def Run(self, args):
"""Create a Cloud NetApp Volume Snapshot in the current project."""
snapshot_ref = args.CONCEPTS.snapshot.Parse()
if args.CONCEPTS.volume.Parse() is None:
raise exceptions.RequiredArgumentException(
'--volume', 'Requires a volume to create snapshot of'
)
volume_ref = args.CONCEPTS.volume.Parse().RelativeName()
client = snapshots_client.SnapshotsClient(self._RELEASE_TRACK)
labels = labels_util.ParseCreateArgs(
args, client.messages.Snapshot.LabelsValue
)
snapshot = client.ParseSnapshotConfig(
name=snapshot_ref.RelativeName(),
description=args.description,
labels=labels,
)
result = client.CreateSnapshot(
snapshot_ref, volume_ref, args.async_, snapshot
)
if args.async_:
command = 'gcloud {} netapp volumes snapshots list'.format(
self.ReleaseTrack().prefix
)
log.status.Print(
'Check the status of the new snapshot by listing all snapshots:\n '
'$ {} '.format(command)
)
return result
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(Create):
"""Create a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.BETA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(CreateBeta):
"""Creates a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.ALPHA

View File

@@ -0,0 +1,92 @@
# -*- 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.
"""Delete a Cloud NetApp Volume Snapshot."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.netapp.volumes.snapshots import client as snapshots_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.netapp.volumes.snapshots import flags as snapshots_flags
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.GA
detailed_help = {
'DESCRIPTION': """\
Delete a Cloud NetApp Volume Snapshot.
""",
'EXAMPLES': """\
The following command deletes a Snapshot named NAME in the given location and volume:
$ {command} NAME --location=us-central1 --volume=vol1
To delete a Snapshot named NAME asynchronously, run the following command:
$ {command} NAME --location=us-central1 --volume=vol1 --async
""",
}
@staticmethod
def Args(parser):
snapshots_flags.AddSnapshotDeleteArgs(parser)
def Run(self, args):
"""Delete a Cloud NetApp Volume Snapshot in the current project."""
snapshot_ref = args.CONCEPTS.snapshot.Parse()
if args.CONCEPTS.volume.Parse() is None:
raise exceptions.RequiredArgumentException(
'--volume', 'Requires a volume to delete snapshot of')
if not args.quiet:
delete_warning = ('You are about to delete a Snapshot {}.\n'
'Are you sure?'.format(snapshot_ref.RelativeName()))
if not console_io.PromptContinue(message=delete_warning):
return None
client = snapshots_client.SnapshotsClient(self._RELEASE_TRACK)
result = client.DeleteSnapshot(snapshot_ref, args.async_)
if args.async_:
command = 'gcloud {} netapp volumes snapshots list'.format(
self.ReleaseTrack().prefix)
log.status.Print(
'Check the status of the deletion by listing all snapshots:\n '
'$ {} '.format(command))
return result
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class DeleteBeta(Delete):
"""Delete a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.BETA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DeleteAlpha(DeleteBeta):
"""Delete a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.ALPHA

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.
"""Describe a Cloud NetApp Volume Snapshot."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.netapp.volumes.snapshots import client as snapshots_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.netapp import flags
from googlecloudsdk.command_lib.netapp.volumes.snapshots import flags as snapshots_flags
from googlecloudsdk.command_lib.util.concepts import concept_parsers
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.GA
detailed_help = {
'DESCRIPTION': """\
Describe a Cloud NetApp Volume Snapshot.
""",
'EXAMPLES': """\
The following command describes a Snapshot named NAME in the given location and volume:
$ {command} NAME --location=us-central1 --volume=vol1
""",
}
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([flags.GetSnapshotPresentationSpec(
'The Snapshot to describe.')]).AddToParser(parser)
snapshots_flags.AddSnapshotVolumeArg(parser)
def Run(self, args):
"""Get a Cloud NetApp Volume Snapshot in the current project."""
snapshot_ref = args.CONCEPTS.snapshot.Parse()
if args.CONCEPTS.volume.Parse() is None:
raise exceptions.RequiredArgumentException(
'--volume', 'Requires a volume to describe snapshot of')
client = snapshots_client.SnapshotsClient(release_track=self._RELEASE_TRACK)
return client.GetSnapshot(snapshot_ref)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class DescribeBeta(Describe):
"""Describe a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.BETA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DescribeAlpha(DescribeBeta):
"""Describe a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.ALPHA

View File

@@ -0,0 +1,82 @@
# -*- 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.
"""List Cloud NetApp Volume Snapshots."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.netapp.volumes.snapshots import client as snapshots_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.netapp import flags
from googlecloudsdk.command_lib.netapp.volumes.snapshots import flags as snapshots_flags
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import properties
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Cloud NetApp Volume Snapshots."""
_RELEASE_TRACK = base.ReleaseTrack.GA
detailed_help = {
'DESCRIPTION': """\
Lists Cloud NetApp Volume Snapshots.
""",
'EXAMPLES': """\
The following command lists all Snapshots in the given location and volume:
$ {command} --location=us-central1 --volume=vol1
""",
}
@staticmethod
def Args(parser):
concept_parsers.ConceptParser([
flags.GetResourceListingLocationPresentationSpec(
'The location in which to list Volume Snapshots.')
]).AddToParser(parser)
snapshots_flags.AddSnapshotVolumeArg(parser)
def Run(self, args):
"""Run the list command."""
# Ensure that project is set before parsing location resource.
properties.VALUES.core.project.GetOrFail()
if args.CONCEPTS.volume.Parse() is None:
raise exceptions.RequiredArgumentException(
'--volume', 'Requires a volume to list snapshots of')
volume_ref = args.CONCEPTS.volume.Parse().RelativeName()
client = snapshots_client.SnapshotsClient(release_track=self._RELEASE_TRACK)
return list(client.ListSnapshots(volume_ref, limit=args.limit))
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class ListBeta(List):
"""List Cloud NetApp Volume Snapshots."""
_RELEASE_TRACK = base.ReleaseTrack.BETA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class ListAlpha(ListBeta):
"""List Cloud NetApp Volume Snapshots."""
_RELEASE_TRACK = base.ReleaseTrack.ALPHA

View File

@@ -0,0 +1,113 @@
# -*- 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.
"""Update a Cloud NetApp Volume Snapshot."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.netapp.volumes.snapshots import client as snapshots_client
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.netapp.volumes.snapshots import flags as snapshots_flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.GA
detailed_help = {
'DESCRIPTION': """\
Update a Cloud NetApp Volume Snapshot and its specified parameters.
""",
'EXAMPLES': """\
The following command updates a Snapshot named NAME and its specified parameters:
$ {command} NAME --location=us-central1 --description="new" --update-labels=key2=val2 --volume=vol1
""",
}
@staticmethod
def Args(parser):
snapshots_flags.AddSnapshotUpdateArgs(parser)
def Run(self, args):
"""Update a Cloud NetApp Volume Snapshot in the current project."""
snapshot_ref = args.CONCEPTS.snapshot.Parse()
if args.CONCEPTS.volume.Parse() is None:
raise exceptions.RequiredArgumentException(
'--volume', 'Requires a volume to update snapshot of')
client = snapshots_client.SnapshotsClient(self._RELEASE_TRACK)
labels_diff = labels_util.Diff.FromUpdateArgs(args)
original_snapshot = client.GetSnapshot(snapshot_ref)
# Update labels
if labels_diff.MayHaveUpdates():
labels = labels_diff.Apply(
client.messages.Snapshot.LabelsValue, original_snapshot.labels
).GetOrNone()
else:
labels = None
snapshot = client.ParseUpdatedSnapshotConfig(
original_snapshot, description=args.description, labels=labels
)
updated_fields = []
# add possible updated snapshot fields
# TODO(b/243601146) add config mapping and separate config file for update
if args.IsSpecified('description'):
updated_fields.append('description')
if (
args.IsSpecified('update_labels')
or args.IsSpecified('remove_labels')
or args.IsSpecified('clear_labels')
):
updated_fields.append('labels')
update_mask = ','.join(updated_fields)
result = client.UpdateSnapshot(
snapshot_ref, snapshot, update_mask, args.async_
)
if args.async_:
command = 'gcloud {} netapp volumes snapshots list'.format(
self.ReleaseTrack().prefix
)
log.status.Print(
'Check the status of the updated snapshot by listing all snapshots:\n'
' $ {} '.format(command)
)
return result
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(Update):
"""Update a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.BETA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(UpdateBeta):
"""Update a Cloud NetApp Volume Snapshot."""
_RELEASE_TRACK = base.ReleaseTrack.ALPHA