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,28 @@
# -*- 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.
"""The nfs-shares command group for the Bare Metal Solution CLI."""
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.GA)
class NfsShares(base.Group):
"""Manage NFS shares in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,91 @@
# -*- 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.
"""Bare Metal Solution NFS share create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
DETAILED_HELP = {
'DESCRIPTION':
"""
Create a Bare Metal Solution NFS share.
""",
'EXAMPLES':
"""
To create an NFS share called ``my-share'' in region ``us-central1'', with
requested size of 256 Gib, SSD storage and 2 allowed clients, run:
$ {command} my-share --region=us-central1 --size-gib=256 --storage-type=SSD --allowed-client=network=my-network,network-project-id=some-other-project,cidr=10.130.240.24/29,mount-permissions=READ_ONLY,allow-dev=yes,allow-suid=no,enable-root-squash=yes --allowed-client=network=my-network2,cidr=10.130.240.26/28,mount-permissions=READ_WRITE,allow-dev=yes,allow-suid=yes,enable-root-squash=no
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Bare Metal Solution NFS share."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNfsShareArgToParser(parser, positional=True)
flags.AddNfsSizeGibArg(parser=parser)
flags.AddNfsStorageTypeArg(parser=parser)
flags.AddNfsAllowedClientArg(parser=parser)
labels_util.AddCreateLabelsFlags(parser=parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
nfs_share = args.CONCEPTS.nfs_share.Parse()
client = BmsClient()
labels = labels_util.ParseCreateArgs(
args=args, labels_cls=client.messages.NfsShare.LabelsValue)
op_ref = client.CreateNfsShare(
nfs_share_resource=nfs_share,
size_gib=args.size_gib,
storage_type=args.storage_type,
allowed_clients_dicts=args.allowed_client,
labels=labels)
if op_ref.done:
log.CreatedResource(nfs_share.Name(), kind='NFS share')
return op_ref
if args.async_:
log.status.Print('Create request issued for: [{}]\nCheck operation '
'[{}] for status.'.format(nfs_share.Name(),
op_ref.name))
return op_ref
op_resource = resources.REGISTRY.ParseRelativeName(
op_ref.name,
collection='baremetalsolution.projects.locations.operations',
api_version='v2')
poller = waiter.CloudOperationPollerNoResources(client.operation_service)
res = waiter.WaitFor(
poller, op_resource,
'Waiting for operation [{}] to complete'.format(op_ref.name))
log.CreatedResource(nfs_share.Name(), kind='NFS share')
return res
Create.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,79 @@
# -*- 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.
"""Bare Metal Solution NFS share delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
DETAILED_HELP = {
'DESCRIPTION':
"""
Delete a Bare Metal Solution NFS share.
""",
'EXAMPLES':
"""
To delete an NFS share called ``my-share'' in region
``us-central1'', run:
$ {command} my-share --region=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete a Bare Metal Solution NFS share."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNfsShareArgToParser(parser, positional=True)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
nfs_share = args.CONCEPTS.nfs_share.Parse()
client = BmsClient()
op_ref = client.DeleteNfsShare(nfs_share_resource=nfs_share)
if op_ref.done:
log.DeletedResource(nfs_share.Name(), kind='NFS share')
return op_ref
if args.async_:
log.status.Print('Delete request issued for: [{}]\nCheck operation '
'[{}] for status.'.format(nfs_share.Name(),
op_ref.name))
return op_ref
op_resource = resources.REGISTRY.ParseRelativeName(
op_ref.name,
collection='baremetalsolution.projects.locations.operations',
api_version='v2')
poller = waiter.CloudOperationPollerNoResources(client.operation_service)
res = waiter.WaitFor(
poller, op_resource,
'Waiting for operation [{}] to complete'.format(op_ref.name))
log.DeletedResource(nfs_share.Name(), kind='NFS share')
return res
Delete.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,55 @@
# -*- 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.
"""'Bare Metal Solution NFS shares describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
DETAILED_HELP = {
'DESCRIPTION':
"""
Describe a Bare Metal Solution NFS share.
""",
'EXAMPLES':
"""
To get a description of an NFS share called ``my-nfs-share'' in
project ``my-project'' and region ``us-central1'', run:
$ {command} my-nfs-share --project=my-project --region=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal solution NFS share."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNfsShareArgToParser(parser, positional=True)
def Run(self, args):
nfs_share = args.CONCEPTS.nfs_share.Parse()
client = BmsClient()
return client.GetNfsShare(nfs_share)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,74 @@
# -*- 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.
"""'Bare Metal Solution NFS shares list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.command_lib.bms import util
DETAILED_HELP = {
'DESCRIPTION':
"""
List Bare Metal Solution NFS shares in a project.
""",
'EXAMPLES':
"""
To list NFS shares within the project in the region ``us-central1'', run:
$ {command} --region=us-central1
Or:
To list all NFS shares in the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Bare Metal Solution NFS shares in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
# Remove unsupported default List flags.
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.SORT_BY_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
flags.AddRegionArgToParser(parser)
# The default format picks out the components of the relative name:
# given projects/myproject/locations/us-central1/nfs-shares/my-test
# it takes -1 (my-test), -3 (us-central1), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,nfsShareId:label=ID,'
'name.segment(-5):label=PROJECT,name.segment(-3):label=REGION,'
'volume.segment(-1):label=VOLUME_NAME,state,'
'allowedClients[].allowedClientsCidr.notnull().list():'
'label=ALLOWED_CIDRS)')
def Run(self, args):
region = util.FixParentPathWithGlobalRegion(args.CONCEPTS.region.Parse())
client = BmsClient()
return client.ListNfsShares(region, limit=args.limit)
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,61 @@
# -*- 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.
"""Bare Metal Solution nfs-share rename command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.core import log
DETAILED_HELP = {
'DESCRIPTION':
"""
Rename a Bare Metal Solution nfs-share.
""",
'EXAMPLES':
"""
To rename a nfs-share ``my-nfs-share'' to ``my-new-nfs-share-name'' in region ``us-central1'', run:
$ {command} my-nfs-share --new-name=my-new-nfs-share-name --region=us-central1 --project=bms-example-project
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Rename(base.UpdateCommand):
"""Rename a Bare Metal Solution nfs-share."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNfsShareArgToParser(parser, positional=True)
flags.AddNewNameArgToParser(parser, 'nfs-share')
def Run(self, args):
client = BmsClient()
old_name = args.CONCEPTS.nfs_share.Parse()
new_name = args.new_name
res = client.RenameNfsShare(old_name, new_name)
log.status.Print(
'Renamed {} to {} successfully'.format(old_name.Name(), new_name))
return res
Rename.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,151 @@
# -*- 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.
"""Bare Metal Solution NFS share update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.command_lib.bms import util
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
DETAILED_HELP = {
'DESCRIPTION':
"""
Update a Bare Metal Solution NFS share.
This call returns immediately, but the update operation may take
several minutes to complete. To check if the operation is complete,
use the `describe` command for the NFS share.
""",
'EXAMPLES':
"""
To update an NFS share called ``my-share'' in region ``us-central1'' with
a new label ``key1=value1'', run:
$ {command} my-share --region=us-central1 --update-labels=key1=value1
To clear all labels, run:
$ {command} my-share --region=us-central1 --clear-labels
To remove label ``key1'', run:
$ {command} my-share --region=us-central1 --remove-labels=key1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Bare Metal Solution NFS share."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNfsShareArgToParser(parser, positional=True)
labels_util.AddUpdateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddNfsUpdateAllowedClientArgs(parser=parser, hidden=False)
def Run(self, args):
labels_diff = labels_util.Diff.FromUpdateArgs(args)
nfs_share = args.CONCEPTS.nfs_share.Parse()
client = BmsClient()
orig_resource = client.GetNfsShare(nfs_share)
labels_update = labels_diff.Apply(client.messages.NfsShare.LabelsValue,
orig_resource.labels).GetOrNone()
updated_allowed_clients = _ApplyNFSAllowedClientsUpdates(
client=client,
args=args,
existing_nfs=orig_resource,
nfs_share_resource=nfs_share)
op_ref = client.UpdateNfsShare(nfs_share_resource=nfs_share,
labels=labels_update,
allowed_clients=updated_allowed_clients)
if op_ref.done:
log.UpdatedResource(nfs_share.Name(), kind='NFS share')
return op_ref
if args.async_:
log.status.Print('Update request issued for: [{}]\nCheck operation '
'[{}] for status.'.format(nfs_share.Name(),
op_ref.name))
return op_ref
op_resource = resources.REGISTRY.ParseRelativeName(
op_ref.name,
collection='baremetalsolution.projects.locations.operations',
api_version='v2')
poller = waiter.CloudOperationPollerNoResources(client.operation_service)
res = waiter.WaitFor(
poller, op_resource,
'Waiting for operation [{}] to complete'.format(op_ref.name))
log.UpdatedResource(nfs_share.Name(), kind='NFS share')
return res
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(Update):
"""Update a Bare Metal Solution NFS share."""
@staticmethod
def Args(parser):
# Flags which are only available in ALPHA should be added to parser here.
Update.Args(parser)
def _ApplyNFSAllowedClientsUpdates(client, args, existing_nfs,
nfs_share_resource):
"""Applies the changes in args to the allowed_clients in existing_nfs.
Returns None if no changes were to be applied.
Args:
client: BmsClient.
args: The arguments passed to the command.
existing_nfs: The existing nfs.
nfs_share_resource: The ref to the NFS share.
Returns:
List of allowed clients after applying updates or None if there are
no changes.
"""
if args.IsKnownAndSpecified(
'clear_allowed_clients') and args.clear_allowed_clients:
return []
if args.IsKnownAndSpecified('add_allowed_client'):
new_clients = client.ParseAllowedClientsDicts(
nfs_share_resource=nfs_share_resource,
allowed_clients_dicts=args.add_allowed_client)
return existing_nfs.allowedClients + new_clients
if args.IsKnownAndSpecified('remove_allowed_client'):
return util.RemoveAllowedClients(
nfs_share_resource=nfs_share_resource,
allowed_clients=existing_nfs.allowedClients,
remove_key_dicts=args.remove_allowed_client)
Update.detailed_help = DETAILED_HELP