feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 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 gcloud anthos config command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class AnthosConfig(base.Group):
"""Anthos configuration command group."""
category = base.ANTHOS_CLI_CATEGORY

View File

@@ -0,0 +1,29 @@
# -*- 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 gcloud anthos config controller command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class AnthosConfig(base.Group):
"""Manage Anthos Config Controller instances.
Commands for managing Anthos Config Controller Instances.
"""

View File

@@ -0,0 +1,123 @@
# -*- 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.
"""Command to create new Config Controller instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container import util as container_util
from googlecloudsdk.api_lib.krmapihosting import util as krmapihosting_api
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos.config.controller import create_utils
from googlecloudsdk.command_lib.anthos.config.controller import flags
from googlecloudsdk.command_lib.anthos.config.controller import utils
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create Anthos Config Controller instances."""
_API_VERSION = "v1"
detailed_help = {
"DESCRIPTION":
"Create an Anthos Config Controller instance.",
"EXAMPLES": ("""
To create an Anthos Config Controller instance with the name ``acc-default'', run:
$ {command} acc-default --location=us-central1
""")
}
@staticmethod
def Args(parser):
utils.AddInstanceResourceArg(parser, Create._API_VERSION)
flags.AddAsyncFlag(parser)
flags.AddMasterIPv4CIDRBlock(parser)
flags.AddNetworkFlag(parser)
flags.AddSubnetFlag(parser)
flags.AddManBlockFlagDeprecated(parser)
flags.AddManBlocksFlag(parser)
flags.AddClusterIPv4CIDRBlock(parser)
flags.AddServicesIPv4CIDRBlack(parser)
flags.AddClusterNamedRangeFlag(parser)
flags.AddServicesNamedRange(parser)
flags.AddUsePrivateEndpoint(parser)
flags.AddFullManagement(parser)
def Run(self, args):
client = krmapihosting_api.GetClientInstance(api_version=self._API_VERSION)
instance_ref = args.CONCEPTS.name.Parse()
release_track = args.calliope_command.ReleaseTrack()
op_ref = client.projects_locations_krmApiHosts.Create(
create_utils.CreateUpdateRequest(release_track, instance_ref, args))
log.status.Print("Create request issued for: [{}]".format(
instance_ref.krmApiHostsId))
if args.async_:
ops = op_ref.name.split("/")
log.status.Print("Check operation [{}] for status.\n"
"To describe the operation, run:\n\n"
"$ gcloud anthos config operations describe {} "
"--location {}"
.format(op_ref.name, ops[-1], args.location))
return op_ref
op_resource = resources.REGISTRY.ParseRelativeName(
op_ref.name, collection="krmapihosting.projects.locations.operations",
api_version=self._API_VERSION)
poller = waiter.CloudOperationPoller(client.projects_locations_krmApiHosts,
client.projects_locations_operations)
result = waiter.WaitFor(
poller, op_resource,
"Waiting for operation [{}] to complete".format(op_ref.name))
log.status.Print("Created instance [{}].".format(
instance_ref.krmApiHostsId))
container_util.CheckKubectlInstalled()
cluster, cluster_ref = utils.GetGKECluster(instance_ref.krmApiHostsId,
instance_ref.locationsId)
container_util.ClusterConfig.Persist(cluster, cluster_ref.projectId)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(Create):
"""Create Anthos Config Controller instances."""
_API_VERSION = "v1alpha1"
@staticmethod
def Args(parser):
utils.AddInstanceResourceArg(parser, CreateAlpha._API_VERSION)
flags.AddAsyncFlag(parser)
flags.AddMasterIPv4CIDRBlock(parser)
flags.AddNetworkFlag(parser)
flags.AddSubnetFlag(parser)
flags.AddManBlockFlagDeprecated(parser)
flags.AddManBlocksFlag(parser)
flags.AddClusterIPv4CIDRBlock(parser)
flags.AddServicesIPv4CIDRBlack(parser)
flags.AddClusterNamedRangeFlag(parser)
flags.AddServicesNamedRange(parser)
flags.AddFullManagement(parser)
flags.AddUsePrivateEndpoint(parser)
flags.AddExperimentalFeaturesFlag(parser)

View File

@@ -0,0 +1,19 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: Delete Anthos Config Controller instances
description: Delete an Anthos Config Controller instance.
examples: |
To delete an Anthos Config Controller instance, run:
$ {command} NAME --location=LOCATION
request:
collection: krmapihosting.projects.locations.krmApiHosts
method: delete
async:
collection: krmapihosting.projects.locations.operations
arguments:
resource:
help_text: The identifier for an Anthos Config Controller instance.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:instance

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: Describe Anthos Config Controller instances.
description: Describe an Anthos Config Controller instance.
examples: |
To describe an Anthos Config Controller instance named default in the location ``us-central1'', run:
$ {command} default --location=us-central1
request:
collection: krmapihosting.projects.locations.krmApiHosts
arguments:
resource:
help_text: The identifier for an Anthos Config Controller instance.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:instance

View File

@@ -0,0 +1,102 @@
# -*- 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.
"""Fetch default Config Connector identity."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import io
from googlecloudsdk.api_lib.container import util as container_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.composer import util as composer_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
def _BaseRun(args):
"""Base operations for `get-config-connector-identity` run command."""
container_util.CheckKubectlInstalled()
cluster_id = 'krmapihost-' + args.name
location = args.location
project_id = args.project or properties.VALUES.core.project.GetOrFail()
GetConfigConnectorIdentityForCluster(location, cluster_id, project_id)
def GetConfigConnectorIdentityForCluster(location, cluster_id, project_id):
"""Get Config Connector identity for the given cluster."""
with composer_util.TemporaryKubeconfig(location, cluster_id):
output = io.StringIO()
composer_util.RunKubectlCommand([
'get', 'ConfigConnectorContext', '-o',
'jsonpath="{.items[0].spec.googleServiceAccount}"'
],
out_func=output.write,
err_func=log.err.write,
namespace='config-control')
identity = output.getvalue().replace('"', '')
log.status.Print(
'Default Config Connector identity: [{identity}].\n'
'\n'
'For example, to give Config Connector permission to manage Google Cloud resources in the same project:\n'
'gcloud projects add-iam-policy-binding {project_id} \\\n'
' --member \"serviceAccount:{identity}\" \\\n'
' --role \"roles/owner\" \\\n'
' --project {project_id}\n'.format(
identity=identity, project_id=project_id))
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class GetConfigConnectorIdentity(base.Command):
"""Fetch default Config Connector identity.
{command} prints the default Config Connector Google Service Account in
a specific Anthos Config Controller.
"""
detailed_help = {
'EXAMPLES':
"""\
To print the default Config Connector identity used by your
Config Controller 'main' in the location 'us-central1', run:
$ {command} main --location=us-central1
""",
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
parser.add_argument('name', help='Name of the Anthos Config Controller.')
parser.add_argument(
'--location',
required=True,
help='The location (region) of the Anthos Config Controller.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
"""
_BaseRun(args)

View File

@@ -0,0 +1,91 @@
# -*- 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.
"""Fetch Config Controller credentials."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container import api_adapter as container_api_adapter
from googlecloudsdk.api_lib.container import util as container_util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
NOT_RUNNING_MSG = """\
Config Controller {0} is not running. The kubernetes API may not be available."""
def _BaseRun(args):
"""Base operations for `get-credentials` run command."""
container_util.CheckKubectlInstalled()
cluster_id = 'krmapihost-' + args.name
location_id = args.location
project = None
gke_api = container_api_adapter.NewAPIAdapter('v1')
log.status.Print('Fetching cluster endpoint and auth data.')
cluster_ref = gke_api.ParseCluster(cluster_id, location_id, project)
cluster = gke_api.GetCluster(cluster_ref)
if not gke_api.IsRunning(cluster):
log.warning(NOT_RUNNING_MSG.format(cluster_ref.clusterId))
return cluster, cluster_ref
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class GetCredentialsAlpha(base.Command):
"""Fetch credentials for a running Anthos Config Controller.
{command} updates a `kubeconfig` file with appropriate credentials and
endpoint information to point `kubectl` at a specific
Anthos Config Controller.
"""
detailed_help = {
'EXAMPLES':
"""\
To switch to working on your Config Controller 'main', run:
$ {command} main --location=us-central1
""",
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: An argparse.ArgumentParser-like object. It is mocked out in order
to capture some information, but behaves like an ArgumentParser.
"""
parser.add_argument('name', help='Name of the Anthos Config Controller.')
parser.add_argument(
'--location',
required=True,
help='The location (region) of the Anthos Config Controller.')
def Run(self, args):
"""This is what gets called when the user runs this command.
Args:
args: an argparse namespace. All the arguments that were provided to this
command invocation.
Raises:
container_util.Error: if the cluster is unreachable or not running.
"""
cluster, cluster_ref = _BaseRun(args)
container_util.ClusterConfig.Persist(cluster, cluster_ref.projectId)

View File

@@ -0,0 +1,39 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: List Anthos Config Controller instances
description: List Anthos Config Controller instances.
examples: |
To list all Anthos Config Controller instances in the region 'us-central1', run:
$ {command} --location=us-central1
To list all Anthos Config Controller instances in all regions with their fully specified name, run:
$ {command} --full-name
To list all Anthos Config Controller instances in all regions, run:
$ {command}
request:
collection: krmapihosting.projects.locations.krmApiHosts
arguments:
resource:
help_text: List of Anthos Config Controller instances.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:instance-list
params:
- arg_name: full-name
action: store_true
default: false
disable_unused_arg_check: true
help_text: |
Print the fully specified name of the instance.
output:
format: table(
name.scope("krmApiHosts").if(NOT full_name),
name.if(full_name),
name.scope("locations").segment(0):label=LOCATION,
state)

View File

@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to update an Anthos Config Controller instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.krmapihosting import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.anthos.config.controller import flags
from googlecloudsdk.command_lib.anthos.config.controller import utils
# TODO(b/234495254): promote the update command to GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Update an Anthos Config Controller instance."""
_API_VERSION = "v1alpha1"
detailed_help = {
"DESCRIPTION":
"Update an Anthos Config Controller instance.",
"EXAMPLES":
"""
To update the master authorized network for an existing Anthos Config
Controller instance, run:
$ {command} sample-instance --man-block=MAN_BLOCK
"""
}
@staticmethod
def Args(parser):
utils.AddInstanceResourceArg(parser, Update._API_VERSION)
flags.AddAsyncFlag(parser)
flags.AddExperimentalFeaturesFlag(parser)
flags.AddManBlockFlag(parser)
def Run(self, args):
op = util.GetClientInstance(
api_version=self._API_VERSION).projects_locations_krmApiHosts.Patch(
utils.PatchRequest(args))
if args.async_:
return utils.AsyncLog(op)
return util.WaitForCreateKrmApiHostOperation(
op,
progress_message="Waiting for operation [{}] to complete".format(
op.name))

View File

@@ -0,0 +1,26 @@
# -*- 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 gcloud anthos config operations command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Operations(base.Group):
"""Get and list operations for Anthos Config Controller instances."""

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: Describe Anthos Config Controller operations.
description: Describe an Anthos Config Controller operation.
examples: |
To describe an Anthos Config Controller operation named my-operation in the location ``us-central1'', run:
$ {command} my-operation --location=us-central1
request:
collection: krmapihosting.projects.locations.operations
arguments:
resource:
help_text: The identifier for an Anthos Config Controller operation.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:operation

View File

@@ -0,0 +1,31 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: List Anthos Config Controller operations
description: List Anthos Config Controller operations.
examples: |
To list all Anthos Config Controller operations in the region 'us-central1', run:
$ {command} --location=us-central1
To list all Anthos Config Controller operations in all regions, run:
$ {command}
request:
collection: krmapihosting.projects.locations.operations
arguments:
resource:
help_text: List of Anthos Config Controller operations.
spec: !REF googlecloudsdk.command_lib.anthos.config.controller.resources:operation-list
output:
format: |
table(
name.scope("operations").segment(0),
name.scope("locations").segment(0):label=LOCATION,
done,
metadata.createTime.date(unit=1000, tz_default=UTC),
metadata.endTime.date(unit=1000, tz_default=UTC)
)