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,29 @@
# -*- 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 command group for the BMS 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 Bms(base.Group):
"""Manage Bare Metal Solution resources."""
category = base.COMPUTE_CATEGORY

View File

@@ -0,0 +1,29 @@
# -*- 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 instances 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 Instances(base.Group):
"""Manage bare metal instances in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,55 @@
# -*- 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 get instance auth-info 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':
"""
Get authentication information for a Bare Metal Solution instance.
""",
'EXAMPLES':
"""
To get authentication information for an instance called ``my-instance'' in
project ``my-project'' and region ``us-central1'', run:
$ {command} my-instance --project=my-project --region=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AuthInfo(base.DescribeCommand):
"""Get authentication information for a Bare Metal Solution instance."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddInstanceArgToParser(parser, positional=True)
def Run(self, args):
instance = args.CONCEPTS.instance.Parse()
client = BmsClient()
return client.LoadInstanceAuthInfo(instance)
AuthInfo.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,55 @@
# -*- 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.
"""'Bare Metal Solution instances 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 instance.
""",
'EXAMPLES':
"""
To get a description of an instance called ``my-instance'' in
project ``my-project'' and region ``us-central1'', run:
$ {command} my-instance --project=my-project --region=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal solution instance."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddInstanceArgToParser(parser, positional=True)
def Run(self, args):
instance = args.CONCEPTS.instance.Parse()
client = BmsClient()
return client.GetInstance(instance)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA]
help_text:
brief: |
Disable hyperthreading for a Bare Metal Solution instance.
description: |
Disables hyperthreading for a Bare Metal Solution instance.
examples: |
To disable hyperthreading for an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to disable hyperthreading for.
request:
method: disableHyperthreading
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Disable hyperthreading request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Disable interactive serial console for a Bare Metal Solution instance.
description: |
Disables interactive serial console for a Bare Metal Solution instance.
examples: |
To disable interactive serial console for an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to disable interactive serial console for.
request:
method: disableInteractiveSerialConsole
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Disable interactive serial console request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA]
help_text:
brief: |
Enable hyperthreading for a Bare Metal Solution instance.
description: |
Enables hyperthreading for a Bare Metal Solution instance.
examples: |
To enable hyperthreading for an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to enable hyperthreading for.
request:
method: enableHyperthreading
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Enable hyperthreading request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Enable interactive serial console for a Bare Metal Solution instance.
description: |
Enables interactive serial console for a Bare Metal Solution instance.
examples: |
To enable interactive serial console for an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to enable interactive serial console for.
request:
method: enableInteractiveSerialConsole
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Enable interactive serial console request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,121 @@
# -*- 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.
"""'Bare Metal Solution instances 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
from googlecloudsdk.core.resource import resource_projector
DETAILED_HELP = {
'DESCRIPTION':
"""
List Bare Metal Solution instances in a project.
""",
'EXAMPLES':
"""
To list instances in the region within the project ``us-central1'', run:
$ {command} --region=us-central1
Or:
To list all instances in the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Bare Metal Solution instances in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
# Remove unsupported default List flags.
base.FILTER_FLAG.RemoveFromParser(parser)
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.SORT_BY_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.AddRegionArgToParser(parser)
# The default format picks out the components of the relative name:
# given projects/myproject/locations/us-central1/instances/my-test
# it takes -1 (my-test), -3 (us-central1), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,id:label=ID,'
'name.segment(-5):label=PROJECT,'
'name.segment(-3):label=REGION,machineType,'
'clientNetworks[].ipAddress.notnull().list():label=CLIENT_IPS,'
'privateNetworks[].ipAddress.notnull().list():label=PRIVATE_IPS,'
'state)')
def Run(self, args):
region = util.FixParentPathWithGlobalRegion(args.CONCEPTS.region.Parse())
client = BmsClient()
for instance in client.ListInstances(region, limit=args.limit):
synthesized_instance = self.synthesizedInstance(instance, client)
yield synthesized_instance
def synthesizedInstance(self, instance, client):
"""Returns a synthesized Instance resource.
Synthesized Instance has additional lists of networks for client and
private.
Args:
instance: protorpc.messages.Message, The BMS instance.
client: BmsClient, BMS API client.
Returns:
Synthesized Instance resource.
"""
synthesized_instance = resource_projector.MakeSerializable(instance)
client_networks = []
private_networks = []
for network in instance.networks:
if client.IsClientNetwork(network):
client_networks.append(network)
elif client.IsPrivateNetwork(network):
private_networks.append(network)
# If the IPs are not available in networks, look up logical interfaces. This
# normally would only happen for new multi-vlan customers who use network
# templates other than the default bondaa-bondaa for their instances.
if (not client_networks and not private_networks and
instance.logicalInterfaces):
for logical_interface in instance.logicalInterfaces:
for logical_network_interface in logical_interface.logicalNetworkInterfaces:
if client.IsClientLogicalNetworkInterface(logical_network_interface):
client_networks.append(logical_network_interface)
elif client.IsPrivateLogicalNetworkInterface(
logical_network_interface):
private_networks.append(logical_network_interface)
synthesized_instance['clientNetworks'] = client_networks
synthesized_instance['privateNetworks'] = private_networks
return synthesized_instance
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 instance reimage 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': """
Reimage a Bare Metal Solution instance.
This call returns immediately, but the reimage operation may take
several minutes to complete. To check if the operation is complete,
use the `describe` command for the instance.
""",
'EXAMPLES': """
To reimage an instance called ``my-instance'' in region ``us-central1'' with
the OS image code ``RHEL9x'', run:
$ {command} my-instance --region=us-central1 --os-image=RHEL9x
To set KMS key and ssh keys in order to connect the instance.
Please use corresponding flags:
$ {command} my-instance --region=us-central1 --os-image=RHEL9x --ssh-keys=ssh-key-1,ssh-key-2 --kms-key-version=sample-kms-key-version
""",
}
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Reimage(base.UpdateCommand):
"""Reimage a Bare Metal Solution instance."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddInstanceArgToParser(parser, positional=True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddInstanceOsImageToParser(parser, hidden=False, required=True)
flags.AddKMSCryptoKeyVersionToParser(parser, hidden=False)
flags.AddSshKeyArgToParser(
parser, positional=False, required=False, plural=True
)
def Run(self, args):
client = BmsClient()
instance = args.CONCEPTS.instance.Parse()
op_ref = client.ReimageInstance(
instance,
os_image=args.os_image,
ssh_keys=args.CONCEPTS.ssh_keys.Parse(),
kms_crypto_key_version=getattr(args, 'kms_crypto_key_version', None),
)
if op_ref.done:
log.UpdatedResource(instance.Name(), kind='instance')
return op_ref
if args.async_:
log.status.Print(
f'Reimage request issued for: [{instance.Name()}]\n'
f'Check operation [{op_ref.name}] for status.'
)
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(instance.Name(), kind='instance')
return res
Reimage.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 instance 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 instance.
""",
'EXAMPLES':
"""
To rename an instance ``my-instance'' to ``my-new-instance-name'' in region ``us-central1'', run:
$ {command} my-instance --new-name=my-new-instance-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 instance."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddInstanceArgToParser(parser, positional=True)
flags.AddNewNameArgToParser(parser, 'instance')
def Run(self, args):
client = BmsClient()
old_name = args.CONCEPTS.instance.Parse()
new_name = args.new_name
res = client.RenameInstance(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,33 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Reset a Bare Metal Solution instance.
description: |
Perform a hard reset on a Bare Metal Solution instance.
This will not perform a clean shutdown of the OS on the instance.
examples: |
To reset an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to reset.
request:
method: reset
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Reset request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Start a Bare Metal Solution instance.
description: |
Starts up a Bare Metal Solution instance.
examples: |
To start an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to start.
request:
method: start
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Start request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Stop a Bare Metal Solution instance.
description: |
Stops a Bare Metal Solution instance.
examples: |
To stop an instance named ``test-instance'', run:
$ {command} test-instance
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:instance
help_text: |
Arguments and flags that specify the Bare Metal Solution instance you
want to stop.
request:
method: stop
collection: baremetalsolution.projects.locations.instances
output:
format: none
async:
api_version: v2
collection: baremetalsolution.projects.locations.operations
request_issued_message: |
Stop request issued for: [{__name__}]
extract_resource_result: false

View File

@@ -0,0 +1,129 @@
# -*- 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 instance 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.util.args import labels_util
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
DETAILED_HELP = {
'DESCRIPTION':
"""
Update a Bare Metal Solution instance.
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 instance.
""",
'EXAMPLES':
"""
To update an instance called ``my-instance'' in region ``us-central1'' with
a new label ``key1=value1'', run:
$ {command} my-instance --region=us-central1 --update-labels=key1=value1
To clear all labels, run:
$ {command} my-instance --region=us-central1 --clear-labels
""",
}
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Bare Metal Solution instance."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddInstanceArgToParser(parser, positional=True)
labels_util.AddUpdateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddInstanceOsImageToParser(parser, hidden=False, required=False)
flags.AddInstanceEnableHyperthreadingToParser(parser, hidden=False)
def GetRequestFields(self, args, client, instance):
labels_diff = labels_util.Diff.FromUpdateArgs(args)
orig_resource = client.GetInstance(instance)
labels_update = labels_diff.Apply(client.messages.Instance.LabelsValue,
orig_resource.labels).GetOrNone()
os_image = getattr(args, 'os_image', None)
enable_hyperthreading = getattr(args, 'enable_hyperthreading', None)
return {
'instance_resource': instance,
'labels': labels_update,
'os_image': os_image,
'enable_hyperthreading': enable_hyperthreading,
'ssh_keys': [],
'kms_key_version': None,
'clear_ssh_keys': False,
}
def Run(self, args):
client = BmsClient()
instance = args.CONCEPTS.instance.Parse()
op_ref = client.UpdateInstance(
**self.GetRequestFields(args, client, instance))
if op_ref.done:
log.UpdatedResource(instance.Name(), kind='instance')
return op_ref
if args.async_:
log.status.Print(
f'Update request issued for: [{instance.Name()}]\n'
f'Check operation [{op_ref.name}] for status.')
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(instance.Name(), kind='instance')
return res
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(Update):
"""Update a Bare Metal Solution instance."""
@staticmethod
def Args(parser):
flags.AddProvisioningSshKeyArgToParser(parser, required=False, plural=True)
flags.AddKMSCryptoKeyVersionToParser(parser, hidden=False)
# Flags which are only available in ALPHA should be added to parser here.
Update.Args(parser)
def GetRequestFields(self, args, client, instance):
return {
**super().GetRequestFields(args, client, instance),
'kms_key_version': args.kms_crypto_key_version,
'ssh_keys': args.CONCEPTS.ssh_keys.Parse(),
'clear_ssh_keys': getattr(args, 'clear_ssh_keys', False),
}
Update.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,28 @@
# -*- 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 networks 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 Networks(base.Group):
"""Manage networks in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,55 @@
# -*- 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.
"""'Bare Metal Solution networks 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 network.
""",
'EXAMPLES':
"""
To get a description of a network called ``my-network'' in project
``my-project'' and region ``us-central1'', run:
$ {command} my-network --project=my-project --region=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal solution network."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNetworkArgToParser(parser, positional=True)
def Run(self, args):
network = args.CONCEPTS.network.Parse()
client = BmsClient()
return client.GetNetwork(network)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,72 @@
# -*- 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.
"""'Bare Metal Solution networks 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 networks in a project.
""",
'EXAMPLES':
"""
To list networks in the region ``us-central1'', run:
$ {command} --region=us-central1
Or:
To list all networks in the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Bare Metal Solution networks 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/networks/my-test
# it takes -1 (my-test), -3 (us-central1), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,id:label=ID,'
'name.segment(-3):label=REGION,cidr:label=RANGE,type,vlanId)')
def Run(self, args):
region = util.FixParentPathWithGlobalRegion(args.CONCEPTS.region.Parse())
client = BmsClient()
return client.ListNetworks(region, limit=args.limit)
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,94 @@
# -*- 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 networks list-ip-reservations 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 IP range reservations for Bare Metal Solution networks
in a project.
""",
'EXAMPLES':
"""
To list IP range reservations for networks in the region
`us-central1`, run:
$ {command} --region=us-central1
Or:
To list all IP range reservations in the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List IP range reservations for Bare Metal Solution networks 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/networks/my-test
# it takes -1 (my-test), -3 (us-central1), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NETWORK_NAME,id:label=NETWORK_ID,'
'name.segment(-3):label=REGION,start_address:label=RESERVATION_'
'START_ADDRESS,end_address:label=RESERVATION_END_ADDRESS,note:'
'label=RESERVATION_NOTE)')
def Run(self, args):
region = util.FixParentPathWithGlobalRegion(args.CONCEPTS.region.Parse())
client = BmsClient()
networks_gen = client.ListNetworks(region, limit=args.limit)
for network in networks_gen:
for reservation in _ExtractReservations(network):
yield reservation
def _ExtractReservations(network):
"""Extracts reservations from network object."""
out = []
for res in network.reservations:
reservation_dict = {}
reservation_dict['name'] = network.name
reservation_dict['id'] = network.id
reservation_dict['start_address'] = res.startAddress
reservation_dict['end_address'] = res.endAddress
reservation_dict['note'] = res.note
out.append(reservation_dict)
return out
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 network 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 network.
""",
'EXAMPLES':
"""
To rename a network ``my-network'' to ``my-new-network-name'' in region ``us-central1'', run:
$ {command} my-network --new-name=my-new-network-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 network."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNetworkArgToParser(parser, positional=True)
flags.AddNewNameArgToParser(parser, 'network')
def Run(self, args):
client = BmsClient()
old_name = args.CONCEPTS.network.Parse()
new_name = args.new_name
res = client.RenameNetwork(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,173 @@
# -*- 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 network 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.bms.bms_client import IpRangeReservation
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import exceptions
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':
"""
Update a Bare Metal Solution network.
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 network.
""",
'EXAMPLES':
"""
To update an network called ``my-network'' in region ``us-central1'' with
a new label ``key1=value1'', run:
$ {command} my-network --region=us-central1 --update-labels=key1=value1
To clear all labels, run:
$ {command} my-network --region=us-central1 --clear-labels
""",
}
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Bare Metal Solution network."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddNetworkArgToParser(parser, positional=True)
labels_util.AddUpdateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddNetworkIpReservationToParser(parser, hidden=False)
def Run(self, args):
client = BmsClient()
network = args.CONCEPTS.network.Parse()
labels_update = None
labels_diff = labels_util.Diff.FromUpdateArgs(args)
orig_resource = client.GetNetwork(network)
labels_update = labels_diff.Apply(
client.messages.Network.LabelsValue,
orig_resource.labels).GetOrNone()
ip_reservations = _ApplyIpReservationsUpdates(args, orig_resource)
op_ref = client.UpdateNetwork(
network_resource=network, labels=labels_update,
ip_reservations=ip_reservations)
if op_ref.done:
log.UpdatedResource(network.Name(), kind='network')
return op_ref
if args.async_:
log.status.Print('Update request issued for: [{}]\nCheck operation '
'[{}] for status.'.format(network.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(network.Name(), kind='network')
return res
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(Update):
"""Update a Bare Metal Solution network."""
@staticmethod
def Args(parser):
# Flags which are only available in ALPHA should be added to parser here.
Update.Args(parser)
def _ApplyIpReservationsUpdates(args, existing_network):
"""Applies the changes in args to the reservations in existing_network.
Returns None if no changes were to be applied.
Args:
args: The arguments passed to the command.
existing_network: The existing network.
Returns:
List of IP range reservations after applying updates or None if there are
no changes.
"""
if _IsSpecified(args, 'clear_ip_range_reservations'):
return []
existing_reservations = [
IpRangeReservation(res.startAddress, res.endAddress, res.note)
for res in existing_network.reservations
]
if _IsSpecified(args, 'add_ip_range_reservation'):
res_dict = args.add_ip_range_reservation
_ValidateAgainstSpec(res_dict, flags.IP_RESERVATION_SPEC,
'add-ip-range-reservation')
return existing_reservations + [
IpRangeReservation(res_dict['start-address'], res_dict['end-address'],
res_dict['note'])
]
if _IsSpecified(args, 'remove_ip_range_reservation'):
return _RemoveReservation(existing_reservations,
args.remove_ip_range_reservation)
def _RemoveReservation(reservations, remove_key_dict):
_ValidateAgainstSpec(remove_key_dict, flags.IP_RESERVATION_KEY_SPEC,
'remove-ip-range-reservation')
start_address = remove_key_dict['start-address']
end_address = remove_key_dict['end-address']
for i, res in enumerate(reservations):
if res.start_address == start_address and res.end_address == end_address:
return reservations[:i] + reservations[i + 1:]
raise LookupError('Cannot find an IP range reservation with start-address'
' [{}] and end-address [{}]'.format(start_address,
end_address))
def _ValidateAgainstSpec(dict_to_validate, spec, flag_name):
for prop in spec.keys():
if prop not in dict_to_validate:
raise exceptions.MissingPropertyError(flag_name, prop)
def _IsSpecified(args, name):
"""Returns true if an arg is defined and specified, false otherwise."""
return args.IsKnownAndSpecified(name)
Update.detailed_help = DETAILED_HELP

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

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 operations 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.GA)
class Operations(base.Group):
"""Manage operations in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,23 @@
- release_tracks: [GA]
help_text:
brief: |
Show metadata for a Bare Metal Solution operation.
description: |
Display all metadata associated with a Bare Metal Solution operation given a valid
operation name.
examples: |
To display the metadata for an operation named `my-operation`,
run:
$ {command} my-operation
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:operation
help_text: |
Arguments and flags that specify the Bare Metal Solution operation you
want to describe.
request:
api_version: v2
collection: baremetalsolution.projects.locations.operations

View File

@@ -0,0 +1,25 @@
- release_tracks: [GA]
help_text:
brief: Poll a long-running Bare Metal Solution operation until it completes.
description: |
Poll a long-running Bare Metal Solution operation until it completes. When
the operation is complete, this command will display the results of the
operation.
examples: |
To poll a long-running Bare Metal Solution operation named 'my-operation' until it completes, run the following:
$ {command} my-operation
arguments:
resource:
spec: !REF googlecloudsdk.command_lib.bms.resources:operation
help_text: |
Arguments and flags that specify the Bare Metal Solution operation you
want to wait for.
request:
api_version: v2
collection: baremetalsolution.projects.locations.operations
async:
collection: baremetalsolution.projects.locations.operations

View File

@@ -0,0 +1,29 @@
# -*- 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.
"""The os images 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 OsImages(base.Group):
"""Manage bare metal os images in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,57 @@
# -*- 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 os images describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
from googlecloudsdk.api_lib.bms.bms_client import BmsClient
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.bms import flags
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
Describe Bare Metal Solution OS image in a project.
""",
'EXAMPLES':
"""
To describe given OS image within the project, run:
$ {command} my-os-image --project=my-project
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""Describe Bare Metal Solution OS images in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddOsImageArgToParser(parser, positional=True)
def Run(self, args):
client = BmsClient()
os_image_parent = args.CONCEPTS.os_image.Parse()
return client.GetOSImage(os_image_parent)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,70 @@
# -*- 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 os images list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
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
from googlecloudsdk.core import properties
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
List Bare Metal Solution OS images in a project.
""",
'EXAMPLES':
"""
To list all OS images within the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""List Bare Metal Solution OS images in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.LIMIT_FLAG_NO_SORTBY_DOC.AddToParser(parser)
parser.display_info.AddFormat('table(code, description)')
def Run(self, args):
client = BmsClient()
project = properties.VALUES.core.project.Get(required=True)
return client.ListOSImages(project_resource=project, limit=args.limit)
def Epilog(self, resources_were_displayed):
"""Called after resources are displayed if the default format was used.
Args:
resources_were_displayed: True if resources were displayed.
"""
if not resources_were_displayed:
log.status.Print('Listed 0 items.')
List.detailed_help = DETAILED_HELP

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 serial-console-ssh-keys 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)
class SerialConsoleSshKeys(base.Group):
"""Manage SSH keys for accessing the interactive serial console in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,75 @@
# -*- 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 interactive serial console SSH keys add 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.util import files
DETAILED_HELP = {
'DESCRIPTION':
"""
Add a public SSH key to the project for accessing the interactive serial console in Bare Metal Solution."
""",
'EXAMPLES':
"""
To add an SSH key called ``my-ssh-key'' in project ``my-project''
with a public key ``ABC6695''
$ {command} my-ssh-key --project=my-project --key=ABC6695
To add an SSH key called ``my-ssh-key'' in project ``my-project''
with a public key stored in /home/user/.ssh/id_rsa.pub
$ {command} my-ssh-key --project=my-project --key-file=/home/user/.ssh/id_rsa.pub
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Add(base.CreateCommand):
"""Add a public SSH key to the project for accessing the interactive serial console in Bare Metal Solution."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSerialConsoleSshKeyArgToParser(parser, positional=True)
key_arg = parser.add_mutually_exclusive_group(required=True)
key_arg.add_argument(
'--key',
help='The SSH public key to add for the interactive serial console')
key_arg.add_argument(
'--key-file',
help=('The path to a file containing an SSH public key to add for the '
'interactive serial console'))
def Run(self, args):
client = BmsClient()
if args.key_file:
public_key = files.ReadFileContents(args.key_file)
else:
public_key = args.key
return client.CreateSshKey(
resource=args.CONCEPTS.serial_console_ssh_key.Parse(),
public_key=public_key)
Add.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.
"""'Bare Metal Solution interactive serial console SSH keys list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
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
from googlecloudsdk.core import properties
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
List the SSH keys added to the project for accessing the interactive serial console in Bare Metal Solution.
""",
'EXAMPLES':
"""
To list all interactive serial console SSH keys within the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class List(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""List the SSH keys added to the project for accessing the interactive serial console in Bare Metal Solution."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.LIMIT_FLAG_NO_SORTBY_DOC.AddToParser(parser)
# The default format picks out the components of the relative name: given
# projects/myproject/locations/global/sshKeys/my-test
# it takes -1 (my-test), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,'
'name.segment(-5):label=PROJECT)')
def Run(self, args):
client = BmsClient()
project = properties.VALUES.core.project.Get(required=True)
return client.ListSshKeys(project_resource=project, limit=args.limit)
def Epilog(self, resources_were_displayed):
"""Called after resources are displayed if the default format was used.
Args:
resources_were_displayed: True if resources were displayed.
"""
if not resources_were_displayed:
log.status.Print('Listed 0 items.')
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,58 @@
# -*- 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 interactive serial console SSH keys remove 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.console import console_io
DETAILED_HELP = {
'DESCRIPTION':
"""
Remove an SSH key that is used to access the interactive serial console in Bare Metal Solution given its name.
""",
'EXAMPLES':
"""
To remove an SSH key called ``my-ssh-key'' run:
$ {command} my-ssh-key
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Remove(base.DeleteCommand):
"""Remove an SSH key that is used to access the interactive serial console in Bare Metal Solution given its name."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSerialConsoleSshKeyArgToParser(parser, positional=True)
def Run(self, args):
ssh_key = args.CONCEPTS.serial_console_ssh_key.Parse()
message = 'You are about to remove the SSH key [{}]'.format(ssh_key.Name())
console_io.PromptContinue(message=message, cancel_on_no=True)
client = BmsClient()
return client.DeleteSshKey(ssh_key)
Remove.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,29 @@
# -*- 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 snapshot-schedule-policies 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.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class SnapshotSchedulePolicies(base.Group):
"""Manage snapshot-schedule-policies in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,69 @@
# -*- 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.
"""Bare Metal Solution snapshot schedule policies 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.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.command_lib.util.args import labels_util
DETAILED_HELP = {
'DESCRIPTION':
"""
Create a Bare Metal Solution snapshot schedule policy.
""",
'EXAMPLES':
"""
To create a policy called ``my-policy'' in project ``my-project''
with description ``my-description'' a schedule that runs every 3
hours and labels 'key1=value1' and 'key2=value2', run:
$ {command} my-policy --project=my-project --description=my-description --schedule="crontab_spec=0 */3 * * *,retention_count=10,prefix=example" --labels=key1=value1,key2=value2
""",
}
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
"""Create a Bare Metal Solution snapshot schedule policy."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSnapshotSchedulePolicyArgToParser(
parser, positional=True)
flags.AddSnapshotScheduleArgListToParser(parser)
labels_util.AddCreateLabelsFlags(parser)
parser.add_argument('--description',
help='Description of the policy.')
def Run(self, args):
policy = args.CONCEPTS.snapshot_schedule_policy.Parse()
description = args.description
client = BmsClient()
return client.CreateSnapshotSchedulePolicy(
policy_resource=policy,
labels=labels_util.ParseCreateArgs(
args, client.messages.SnapshotSchedulePolicy.LabelsValue),
description=description,
schedules=args.schedule)
Create.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,64 @@
# -*- 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.
"""'Bare Metal Solution snapshot schedule policies 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.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.core.console import console_io
DETAILED_HELP = {
'DESCRIPTION':
"""
Delete a Bare Metal Solution snapshot schedule policy.
""",
'EXAMPLES':
"""
To delete a snapshot schedule policy called ``my-policy'' in project
``my-project'', run:
$ {command} my-policy --project=my-project
""",
}
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Delete(base.DeleteCommand):
"""Describe a Bare Metal solution snapshot schedule policy."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSnapshotSchedulePolicyArgToParser(parser, positional=True)
def Run(self, args):
policy = args.CONCEPTS.snapshot_schedule_policy.Parse()
console_io.PromptContinue(
message=('You are about to delete the snapshot schedule policy '
'[{0}]'.format(policy.Name())),
cancel_on_no=True)
client = BmsClient()
return client.DeleteSnapshotSchedulePolicy(policy)
Delete.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,56 @@
# -*- 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.
"""'Bare Metal Solution snapshot schedule policies 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 snapshot schedule policy.
""",
'EXAMPLES':
"""
To get a description of a snapshot schedule policy called
``my-policy'' in project ``my-project'', run:
$ {command} my-policy --project=my-project
""",
}
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal solution snapshot schedule policy."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSnapshotSchedulePolicyArgToParser(parser, positional=True)
def Run(self, args):
policy = args.CONCEPTS.snapshot_schedule_policy.Parse()
client = BmsClient()
return client.GetSnapshotSchedulePolicy(policy)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,78 @@
# -*- 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.
"""'Bare Metal Solution snapshot schedule policies list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
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
from googlecloudsdk.core import properties
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
List Bare Metal Solution snapshot schedule policies in a project.
""",
'EXAMPLES':
"""
To list all snapshot schedule policies within the project, run:
$ {command}
""",
}
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class List(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""List Bare Metal Solution snapshot schedule policies in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.LIMIT_FLAG_NO_SORTBY_DOC.AddToParser(parser)
# The default format picks out the components of the relative name: given
# projects/myproject/locations/global/snapshotSchedulePolicies/my-test
# it takes -1 (my-test), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,id:label=ID,'
'name.segment(-5):label=PROJECT,description)')
def Run(self, args):
client = BmsClient()
project = properties.VALUES.core.project.Get(required=True)
return client.ListSnapshotSchedulePolicies(project_resource=project,
limit=args.limit)
def Epilog(self, resources_were_displayed):
"""Called after resources are displayed if the default format was used.
Args:
resources_were_displayed: True if resources were displayed.
"""
if not resources_were_displayed:
log.status.Print('Listed 0 items.')
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,90 @@
# -*- 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.
"""'Bare Metal Solution snapshot schedule policies 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.calliope import base
from googlecloudsdk.command_lib.bms import exceptions
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.command_lib.util.args import labels_util
DETAILED_HELP = {
'DESCRIPTION':
"""
Update a Bare Metal Solution snapshot schedule policy.
""",
'EXAMPLES':
"""
To update an existing policy called ``my-policy'' with new description
``my-description'' and replace any existing schedules with one
that runs every 12 hours, run:
$ {command} my-policy --description=my-description --schedule="crontab_spec=0 */12 * * *,retention_count=10,prefix=example"
To add the label 'key1=value1' to a policy, run:
$ {command} my-policy --update-labels=key1=value1
To clear all labels, run:
$ {command} my-policy --clear-labels
""",
}
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Create a Bare Metal Solution snapshot schedule policy."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSnapshotSchedulePolicyArgToParser(parser, positional=True)
flags.AddSnapshotScheduleArgListToParser(parser, required=False)
labels_util.AddUpdateLabelsFlags(parser)
parser.add_argument('--description',
help='Textual description of the policy.')
def Run(self, args):
client = BmsClient()
policy = args.CONCEPTS.snapshot_schedule_policy.Parse()
description = args.description
schedules = args.schedule
labels_update = None
labels_diff = labels_util.Diff.FromUpdateArgs(args)
if labels_diff.MayHaveUpdates():
orig_resource = client.GetSnapshotSchedulePolicy(policy)
labels_update = labels_diff.Apply(
client.messages.SnapshotSchedulePolicy.LabelsValue,
orig_resource.labels).GetOrNone()
if not description and not schedules and not labels_diff.MayHaveUpdates():
raise exceptions.NoConfigurationChangeError(
'No configuration change was requested. Did you mean to include the '
'flags `--description` `--schedule` `--update-labels`'
'`--remove-labels` or `--clear-labels`?')
return client.UpdateSnapshotSchedulePolicy(policy_resource=policy,
labels=labels_update,
description=description,
schedules=schedules)
Update.detailed_help = DETAILED_HELP

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 ssh-keys 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 SshKeys(base.Group):
"""Manage SSH keys for Bare Metal Solution."""
pass

View File

@@ -0,0 +1,71 @@
# -*- 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 SSH keys add 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.util import files
DETAILED_HELP = {
'DESCRIPTION':
"""
Add a public SSH key to the project in Bare Metal Solution.
""",
'EXAMPLES':
"""
To add an SSH key called ``my-ssh-key'' in project ``my-project''
with a public key ``ABC6695''
$ {command} my-ssh-key --project=my-project --key=ABC6695
To add an SSH key called ``my-ssh-key'' in project ``my-project''
with a public key stored in /home/user/.ssh/id_rsa.pub
$ {command} my-ssh-key --project=my-project --key-file=/home/user/.ssh/id_rsa.pub
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Add(base.CreateCommand):
"""Add a public SSH key to the project in Bare Metal Solution."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSshKeyArgToParser(parser, positional=True)
key_arg = parser.add_mutually_exclusive_group(required=True)
key_arg.add_argument('--key', help='The SSH public key to add')
key_arg.add_argument(
'--key-file',
help=('The path to a file containing an SSH public key to add'))
def Run(self, args):
client = BmsClient()
if args.key_file:
public_key = files.ReadFileContents(args.key_file)
else:
public_key = args.key
return client.CreateSshKey(
resource=args.CONCEPTS.ssh_key.Parse(), public_key=public_key.strip())
Add.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.
"""'Bare Metal Solution SSH keys list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
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
from googlecloudsdk.core import properties
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
List the SSH keys added to the project in Bare Metal Solution.
""",
'EXAMPLES':
"""
To list all SSH keys within the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""List the SSH keys added to the project in Bare Metal Solution."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.LIMIT_FLAG_NO_SORTBY_DOC.AddToParser(parser)
# The default format picks out the components of the relative name: given
# projects/myproject/locations/global/sshKeys/my-test
# it takes -1 (my-test), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,'
'name.segment(-5):label=PROJECT)')
def Run(self, args):
client = BmsClient()
project = properties.VALUES.core.project.Get(required=True)
return client.ListSshKeys(project_resource=project, limit=args.limit)
def Epilog(self, resources_were_displayed):
"""Called after resources are displayed if the default format was used.
Args:
resources_were_displayed: True if resources were displayed.
"""
if not resources_were_displayed:
log.status.Print('Listed 0 items.')
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,58 @@
# -*- 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 SSH keys remove 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.console import console_io
DETAILED_HELP = {
'DESCRIPTION':
"""
Remove an SSH key in Bare Metal Solution given its name.
""",
'EXAMPLES':
"""
To remove an SSH key called ``my-ssh-key'' run:
$ {command} my-ssh-key
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Remove(base.DeleteCommand):
"""Remove an SSH key in Bare Metal Solution given its name."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddSshKeyArgToParser(parser, positional=True)
def Run(self, args):
ssh_key = args.CONCEPTS.ssh_key.Parse()
message = 'You are about to remove the SSH key [{}]'.format(ssh_key.Name())
console_io.PromptContinue(message=message, cancel_on_no=True)
client = BmsClient()
return client.DeleteSshKey(ssh_key)
Remove.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,29 @@
# -*- 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 volumes 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 Volumes(base.Group):
"""Manage bare metal volumes in Bare Metal Solution."""
pass

View File

@@ -0,0 +1,55 @@
# -*- 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.
"""'Bare Metal Solution volumes 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 volume.
""",
'EXAMPLES':
"""
To get a description of an volume called ``my-volume'' in
project ``my-project'' and region ``us-central1'', run:
$ {command} my-volume --project=my-project --region=us-central1
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal Solution volume."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeArgToParser(parser, positional=True)
def Run(self, args):
volume = args.CONCEPTS.volume.Parse()
client = BmsClient()
return client.GetVolume(volume)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,76 @@
# -*- 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.
"""'Bare Metal Solution volumes 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 volumes in a project.
""",
'EXAMPLES':
"""
To list volumes within the project in the region ``us-central1'', run:
$ {command} --region=us-central1
Or:
To list all volumes in the project, run:
$ {command}
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Bare Metal Solution volumes in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
# Remove unsupported default List flags.
base.FILTER_FLAG.RemoveFromParser(parser)
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.SORT_BY_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.AddRegionArgToParser(parser)
# The default format picks out the components of the relative name:
# given projects/myproject/locations/us-central1/volumes/my-test
# it takes -1 (my-test), -3 (us-central1), and -5 (myproject).
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,id:label=ID,'
'name.segment(-5):label=PROJECT,name.segment(-3):label=REGION,'
'requestedSizeGib,storageType,state)')
def Run(self, args):
region = util.FixParentPathWithGlobalRegion(args.CONCEPTS.region.Parse())
client = BmsClient()
return client.ListVolumes(region, limit=args.limit)
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,27 @@
# -*- 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 luns 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 LUNs(base.Group):
"""Manage bare metal logical unit numbers (LUNs) in Bare Metal Solution."""

View File

@@ -0,0 +1,55 @@
# -*- 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.
"""'Bare Metal Solution LUNs 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 logical unit number (LUN).
""",
'EXAMPLES':
"""
To get details about a LUN called ``my-lun'' on volume ``my-volume''
in region ``us-central1'', run:
$ {command} my-lun --region=us-central1 --volume=my-volume
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal Solution LUN."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddLunArgToParser(parser)
def Run(self, args):
lun = args.CONCEPTS.lun.Parse()
client = BmsClient()
return client.GetLUN(lun)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,80 @@
# -*- 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.
"""'Bare Metal Solution logical unit numbers (LUNs) list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
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
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
List Bare Metal Solution logical unit numbers (LUNs) for a volume.
""",
'EXAMPLES':
"""
To list all LUNs on volume ``my-volume'' in region ``us-central1'',
run:
$ {command} --region=us-central1 --volume=my-volume
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""List Bare Metal Solution LUNs in a project."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
# Remove unsupported default List flags.
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.LIMIT_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.AddVolumeArgToParser(parser)
# The default format picks out the components of the relative name: given
# projects/myproject/locations/us-central1/volumes/my-volume/snapshots/my-snapshot
# it takes -1 (my-snapshot), -3 (my-volume), -5 (us-central1), and
# -7 (myproject)
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,id:label=ID,'
'name.segment(-5):label=REGION,'
'name.segment(-3):label=VOLUME,sizeGb,state)')
def Run(self, args):
volume = args.CONCEPTS.volume.Parse()
client = BmsClient()
return client.ListLUNsForVolume(volume,
limit=args.limit)
def Epilog(self, resources_were_displayed):
"""Called after resources are displayed if the default format was used.
Args:
resources_were_displayed: True if resources were displayed.
"""
if not resources_were_displayed:
log.status.Print('Listed 0 items.')
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 volume 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 volume.
""",
'EXAMPLES':
"""
To rename a volume ``my-volume'' to ``my-new-volume-name'' in region ``us-central1'', run:
$ {command} my-volume --new-name=my-new-volume-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 volume."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeArgToParser(parser, positional=True)
flags.AddNewNameArgToParser(parser, 'volume')
def Run(self, args):
client = BmsClient()
old_name = args.CONCEPTS.volume.Parse()
new_name = args.new_name
res = client.RenameVolume(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,95 @@
# -*- 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.
"""'Bare Metal Solution boot volumes "restore" 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 properties
from googlecloudsdk.core import resources
DETAILED_HELP = {
'DESCRIPTION':
"""
Restore a Bare Metal Solution boot volume from an existing snapshot.
""",
'EXAMPLES':
"""
To restore a boot volume named ``my-boot-volume'' in region
``us-central1'' from snapshot named ``my-snapshot'', run:
$ {command} my-boot-volume --region=us-central1 --snapshot=my-snapshot
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Restore(base.UpdateCommand):
"""Restore a Bare Metal Solution boot volume from an existing snapshot."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeArgToParser(parser, positional=True)
parser.add_argument('--snapshot',
required=True,
help='Name of the snapshot to restore.')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
volume = args.CONCEPTS.volume.Parse()
client = BmsClient()
snapshot_ref = resources.REGISTRY.Parse(
args.snapshot,
params={
'projectsId': properties.VALUES.core.project.GetOrFail,
'locationsId': args.region,
'volumesId': args.volume,
},
collection='baremetalsolution.projects.locations.volumes.snapshots',
api_version='v2')
op_ref = client.RestoreVolumeSnapshot(
snapshot_name=snapshot_ref.RelativeName())
if op_ref.done:
log.RestoredResource(volume.Name(), kind='volume')
return op_ref
if args.async_:
log.status.Print('Restore request issued for [{}]\nCheck operation '
'[{}] for status.'.format(volume.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.RestoredResource(volume.Name(), kind='volume')
return res
Restore.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,81 @@
# -*- 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.
"""'Bare Metal Solution boot volumes "snapshot" 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
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
DETAILED_HELP = {
'DESCRIPTION':
"""
Create a snapshot of a Bare Metal Solution boot volume.
""",
'EXAMPLES':
"""
To create a snapshot of a boot volume named ``my-boot-volume'' in
region ``us-central1'' with the name ``my-snapshot'' and description
``my-description'', run:
$ {command} my-boot-volume --region=us-central1 --snapshot-name=my-snapshot
--description=my-description
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a snapshot of a Bare Metal Solution boot volume."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeArgToParser(parser, positional=True)
parser.add_argument('--snapshot-name',
help='Name to assign to the created snapshot.',
required=True)
parser.add_argument('--description',
help='Textual description of the created snapshot.',
required=True)
def Run(self, args):
volume = args.CONCEPTS.volume.Parse()
client = BmsClient()
snapshot_ref = resources.REGISTRY.Parse(
args.snapshot_name,
params={
'projectsId': properties.VALUES.core.project.GetOrFail,
'locationsId': args.region,
'volumesId': args.volume,
},
collection='baremetalsolution.projects.locations.volumes.snapshots',
api_version='v2')
res = client.CreateVolumeSnapshot(resource=volume,
name=snapshot_ref.RelativeName(),
description=args.description)
log.CreatedResource(res.name, 'snapshot')
return res
Create.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,28 @@
# -*- 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 snapshots 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 Snapshots(base.Group):
"""Manage snapshots for Bare Metal Solution volumes."""
pass

View File

@@ -0,0 +1,72 @@
# -*- 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.
"""'Bare Metal Solution boot volume snapshot 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.calliope import base
from googlecloudsdk.command_lib.bms import flags
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
DETAILED_HELP = {
'DESCRIPTION':
"""
Delete a Bare Metal Solution boot volume snapshot.
""",
'EXAMPLES':
"""
To delete a snapshot called ``my-snapshot'' on boot volume
``my-boot-volume'' in region ``us-central1'', run:
$ {command} my-snapshot --region=us-central1 --volume=my-boot-volume
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete a Bare Metal Solution boot volume snapshot."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeSnapshotArgToParser(parser, positional=True)
def Run(self, args):
snapshot = args.CONCEPTS.snapshot.Parse()
client = BmsClient()
snapshot_type = client.GetVolumeSnapshot(snapshot).type
if snapshot_type == client.messages.VolumeSnapshot.TypeValueValuesEnum.SCHEDULED:
console_io.PromptContinue(
message='Deleting a SCHEDULED snapshot of a boot volume '
'is unsafe and should only be done when necessary.',
prompt_string='Are you sure you want to delete snapshot {}'
.format(snapshot.Name()),
cancel_on_no=True)
else:
console_io.PromptContinue(
message=('You are about to delete the snapshot '
'[{0}]'.format(snapshot.Name())),
cancel_on_no=True)
res = client.DeleteVolumeSnapshot(snapshot)
log.DeletedResource(snapshot.Name(), 'snapshot')
return res
Delete.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,57 @@
# -*- 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.
"""'Bare Metal Solution snapshot 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 boot volume snapshot.
""",
'EXAMPLES':
"""
To get a description of a snapshot called ``my-snapshot'' on boot
volume ``my-boot-volume'' in region ``us-central1'',
run:
$ {command} my-snapshot --region=us-central1 --volume=my-boot-volume
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a Bare Metal Solution boot volume snapshot."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeSnapshotArgToParser(parser, positional=True)
def Run(self, args):
snapshot = args.CONCEPTS.snapshot.Parse()
client = BmsClient()
return client.GetVolumeSnapshot(snapshot)
Describe.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,84 @@
# -*- 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.
"""'Bare Metal Solution snapshots list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import abc
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
import six
DETAILED_HELP = {
'DESCRIPTION':
"""
List snapshots for a Bare Metal Solution boot volume.
""",
'EXAMPLES':
"""
To list snapshots on boot volume ``my-boot-volume'' in region
``us-central1'', run:
$ {command} --region=us-central1 --volume=my-boot-volume
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class List(six.with_metaclass(abc.ABCMeta, base.CacheCommand)):
"""List snapshots for a Bare Metal Solution boot volume."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
# Remove unsupported default List flags.
flags.FILTER_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.LIMIT_FLAG_NO_SORTBY_DOC.AddToParser(parser)
flags.AddVolumeArgToParser(
parser,
group_help_text='The Bare Metal Solution volume to list snapshots of.')
# The default format picks out the components of the relative name: given
# projects/myproject/locations/us-central1/volumes/my-volume/snapshots/my-snapshot
# it takes -1 (my-snapshot), -3 (my-volume), -5 (us-central1), and
# -7 (myproject)
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,id:label=ID,'
'name.segment(-5):label=REGION,'
'name.segment(-3):label=VOLUME,description,createTime,type)')
def Run(self, args):
volume = args.CONCEPTS.volume.Parse()
client = BmsClient()
return client.ListSnapshotsForVolume(volume,
limit=args.limit)
def Epilog(self, resources_were_displayed):
"""Called after resources are displayed if the default format was used.
Args:
resources_were_displayed: True if resources were displayed.
"""
if not resources_were_displayed:
log.status.Print('Listed 0 items.')
List.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,108 @@
# -*- 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.
"""Bare Metal Solution volumes 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 exceptions
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':
"""
Update a Bare Metal Solution volume.
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 volume.
""",
'EXAMPLES':
"""
To add the label 'key1=value1' to a policy, run:
$ {command} my-volume --update-labels=key1=value1
To clear all labels, run:
$ {command} my-volume --clear-labels
""",
}
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Bare Metal Solution volume."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddVolumeArgToParser(parser, positional=True)
labels_util.AddUpdateLabelsFlags(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
client = BmsClient()
volume = args.CONCEPTS.volume.Parse()
labels_update = None
labels_diff = labels_util.Diff.FromUpdateArgs(args)
if not labels_diff.MayHaveUpdates():
raise exceptions.NoConfigurationChangeError(
'No configuration change was requested. Did you mean to include the '
'flags `--update-labels`, `--remove-labels`, or `--clear-labels?`')
orig_resource = client.GetVolume(volume)
labels_update = labels_diff.Apply(
client.messages.Volume.LabelsValue,
orig_resource.labels).GetOrNone()
op_ref = client.UpdateVolume(
volume_resource=volume,
labels=labels_update,
snapshot_schedule_policy_resource=None,
remove_snapshot_schedule_policy=None,
snapshot_auto_delete=None)
if op_ref.done:
log.UpdatedResource(volume.Name(), kind='volume')
return op_ref
if args.async_:
log.status.Print('Update request issued for: [{}]\nCheck operation '
'[{}] for status.'.format(volume.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(volume.Name(), kind='volume')
return res
Update.detailed_help = DETAILED_HELP