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 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