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 2022 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group `gcloud container bare-metal clusters`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Clusters(base.Group):
"""Create and manage Anthos clusters on bare metal."""

View File

@@ -0,0 +1,253 @@
# -*- 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 create an Anthos cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from typing import Optional
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as bare_metal_flags
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.gkeonprem import flags
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkeonprem.v1 import gkeonprem_v1_messages as messages
_EXAMPLES = """
To create a cluster named ``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the create command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT
)
bare_metal_flags.AddClusterResourceArg(
parser, verb='to create', positional=True
)
bare_metal_flags.AddAdminClusterMembershipResourceArg(
parser, positional=False
)
base.ASYNC_FLAG.AddToParser(parser)
bare_metal_flags.AddValidationOnly(parser)
bare_metal_flags.AddDescription(parser)
bare_metal_flags.AddAnnotations(parser)
bare_metal_flags.AddVersion(parser)
bare_metal_flags.AddNetworkConfig(parser)
bare_metal_flags.AddLoadBalancerConfig(parser)
bare_metal_flags.AddStorageConfig(parser)
bare_metal_flags.AddControlPlaneConfig(parser)
bare_metal_flags.AddProxyConfig(parser)
bare_metal_flags.AddClusterOperationsConfig(parser)
bare_metal_flags.AddMaintenanceConfig(parser)
bare_metal_flags.AddWorkloadNodeConfig(parser)
bare_metal_flags.AddSecurityConfig(parser)
bare_metal_flags.AddNodeAccessConfig(parser)
flags.AddBinauthzEvaluationMode(parser)
def Run(self, args) -> Optional[messages.Operation]:
"""Runs the create command.
Args:
args: The arguments received from command line.
Returns:
The return value depends on the command arguments. If `--async` is
specified, it returns an operation; otherwise, it returns the created
resource. If `--validate-only` is specified, it returns None or any
possible error.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
operation = cluster_client.Create(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.CreatedResource(
cluster_ref, 'Anthos cluster on bare metal', args.async_
)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(base.CreateCommand):
"""Create an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the create command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT
)
bare_metal_flags.AddClusterResourceArg(
parser, verb='to create', positional=True
)
bare_metal_flags.AddAdminClusterMembershipResourceArg(
parser, positional=False
)
base.ASYNC_FLAG.AddToParser(parser)
bare_metal_flags.AddValidationOnly(parser)
bare_metal_flags.AddDescription(parser)
bare_metal_flags.AddAnnotations(parser)
bare_metal_flags.AddVersion(parser)
bare_metal_flags.AddNetworkConfig(parser)
bare_metal_flags.AddLoadBalancerConfig(parser)
bare_metal_flags.AddStorageConfig(parser)
bare_metal_flags.AddControlPlaneConfig(parser)
bare_metal_flags.AddProxyConfig(parser)
bare_metal_flags.AddClusterOperationsConfig(parser)
bare_metal_flags.AddMaintenanceConfig(parser)
bare_metal_flags.AddWorkloadNodeConfig(parser)
bare_metal_flags.AddSecurityConfig(parser)
bare_metal_flags.AddNodeAccessConfig(parser)
flags.AddBinauthzEvaluationMode(parser)
def Run(self, args) -> Optional[messages.Operation]:
"""Runs the create command.
Args:
args: The arguments received from command line.
Returns:
The return value depends on the command arguments. If `--async` is
specified, it returns an operation; otherwise, it returns the created
resource. If `--validate-only` is specified, it returns None or any
possible error.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
operation = cluster_client.Create(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.CreatedResource(
cluster_ref, 'Anthos cluster on bare metal', args.async_
)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(base.CreateCommand):
"""Create an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(
parser: parser_arguments.ArgumentInterceptor,
) -> None:
"""Gathers command line arguments for the create command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT
)
bare_metal_flags.AddClusterResourceArg(
parser, verb='to create', positional=True
)
bare_metal_flags.AddAdminClusterMembershipResourceArg(
parser, positional=False
)
base.ASYNC_FLAG.AddToParser(parser)
bare_metal_flags.AddValidationOnly(parser)
bare_metal_flags.AddDescription(parser)
bare_metal_flags.AddAnnotations(parser)
bare_metal_flags.AddVersion(parser)
bare_metal_flags.AddNetworkConfig(parser)
bare_metal_flags.AddLoadBalancerConfig(parser)
bare_metal_flags.AddStorageConfig(parser)
bare_metal_flags.AddControlPlaneConfig(parser)
bare_metal_flags.AddProxyConfig(parser)
bare_metal_flags.AddClusterOperationsConfig(parser)
bare_metal_flags.AddMaintenanceConfig(parser)
bare_metal_flags.AddWorkloadNodeConfig(parser)
bare_metal_flags.AddSecurityConfig(parser)
bare_metal_flags.AddNodeAccessConfig(parser)
flags.AddBinauthzEvaluationMode(parser)
bare_metal_flags.AddUpgradePolicy(parser)
def Run(self, args) -> Optional[messages.Operation]:
"""Runs the create command.
Args:
args: The arguments received from command line.
Returns:
The return value depends on the command arguments. If `--async` is
specified, it returns an operation; otherwise, it returns the created
resource. If `--validate-only` is specified, it returns None or any
possible error.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
operation = cluster_client.Create(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.CreatedResource(cluster_ref, 'Anthos cluster on bare metal',
args.async_)
return operation_response

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.
"""Command to delete an Anthos cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as flags
from googlecloudsdk.core import log
_EXAMPLES = """
To delete a cluster named ``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Delete(base.DeleteCommand):
"""Delete an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddClusterResourceArg(parser, verb='to delete')
flags.AddValidationOnly(parser)
flags.AddForceCluster(parser)
flags.AddAllowMissingCluster(parser)
flags.AddIgnoreErrors(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Runs the delete command."""
cluster_ref = args.CONCEPTS.cluster.Parse()
client = apis.ClustersClient()
operation = client.Delete(args)
if args.validate_only:
return
if operation.name is None:
return operation
if args.async_:
log.DeletedResource(cluster_ref, 'Anthos Cluster on bare metal',
args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
log.DeletedResource(cluster_ref, 'Anthos Cluster on bare metal',
args.async_)
return response

View File

@@ -0,0 +1,51 @@
# -*- 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 describe an Anthos cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as flags
_EXAMPLES = """
To describe a cluster named ``my-cluster'' managed in location ``us-west1'',
run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Describe(base.DescribeCommand):
"""Describe an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
flags.AddClusterResourceArg(parser, verb='to describe')
def Run(self, args):
"""Runs the describe command."""
cluster_ref = args.CONCEPTS.cluster.Parse()
client = apis.ClustersClient()
return client.Describe(cluster_ref)

View File

@@ -0,0 +1,73 @@
# -*- 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 enroll a cluster in an Anthos cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as bare_metal_flags
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To enroll a cluster named ``my-cluster'' managed in location ``us-west1''
with admin cluster membership of
``projects/my-project/locations/us-west1/memberships/my-admin-cluster-membership'',
run:
$ {command} my-cluster --location=us-west1 --admin-cluster-membership=projects/my-project/locations/us-west1/memberships/my-admin-cluster-membership
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Enroll(base.Command):
"""Enroll an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT
)
bare_metal_flags.AddAdminClusterMembershipResourceArg(
parser, positional=False
)
bare_metal_flags.AddClusterResourceArg(parser, verb='to enroll')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
cluster_client = apis.ClustersClient()
cluster_ref = args.CONCEPTS.cluster.Parse()
operation = cluster_client.Enroll(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
operations.log_enroll(cluster_ref, args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
operations.log_enroll(cluster_ref, args.async_)
return operation_response

View File

@@ -0,0 +1,78 @@
# -*- 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.
"""Command to export an Anthos clusters on bare metal API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core.util import files
_EXAMPLES = """
A cluster can be exported to a file by running:
$ {command} NAME --destination=<path-to-file>
A cluster can also be exported to stdout by running:
$ {command} NAME
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.Hidden
class Export(base.Command):
"""Export an Anthos on bare metal user cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def GetSchemaPath(for_help=False):
return export_util.GetSchemaPath(
'gkeonprem', 'v1', 'BareMetalCluster', for_help=for_help
)
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
cluster_flags.AddClusterResourceArg(parser, verb='to export')
export_util.AddExportFlags(
parser, schema_path=Export.GetSchemaPath(for_help=True)
)
def Run(self, args):
cluster_ref = args.CONCEPTS.cluster.Parse()
client = apis.ClustersClient()
user_cluster = client.Describe(cluster_ref)
if args.destination:
with files.FileWriter(args.destination) as stream:
export_util.Export(
message=user_cluster,
stream=stream,
schema_path=self.GetSchemaPath(),
)
else:
export_util.Export(
message=user_cluster,
stream=sys.stdout,
schema_path=self.GetSchemaPath(),
)

View File

@@ -0,0 +1,94 @@
# -*- 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.
"""Command to import an Anthos clusters on bare metal API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
from googlecloudsdk.generated_clients.apis.gkeonprem.v1 import gkeonprem_v1_messages as messages
_EXAMPLES = """
A cluster can be imported by running:
$ {command} NAME --source=<path-to-file>
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.Hidden
class Import(base.Command):
"""Import an Anthos on bare metal user cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def GetSchemaPath(for_help=False):
return export_util.GetSchemaPath(
'gkeonprem', 'v1', 'BareMetalCluster', for_help=for_help
)
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
cluster_flags.AddClusterResourceArg(parser, 'to import')
export_util.AddImportFlags(
parser, schema_path=Import.GetSchemaPath(for_help=True)
)
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddValidationOnly(parser)
def Run(self, args):
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)
bare_metal_cluster = export_util.Import(
message_type=messages.BareMetalCluster,
stream=data,
schema_path=Import.GetSchemaPath(),
)
operation = cluster_client.CreateFromImport(
args, bare_metal_cluster, cluster_ref
)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.validate_only:
return
if args.async_:
log.CreatedResource(
cluster_ref, 'Anthos Cluster on bare metal', args.async_
)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.CreatedResource(
cluster_ref, 'Anthos Cluster on bare metal', args.async_
)
return operation_response

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.
"""Command to list all clusters in the Anthos on bare metal API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as flags
from googlecloudsdk.command_lib.container.bare_metal import constants
_EXAMPLES = """
To lists all clusters managed in location ``us-west1'', run:
$ {command} --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class List(base.ListCommand):
"""List Anthos clusters on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the list command."""
flags.AddLocationResourceArg(parser, verb='to list')
parser.display_info.AddFormat(constants.BARE_METAL_CLUSTERS_FORMAT)
def Run(self, args):
"""Runs the list command.
Args:
args: Arguments received from command line.
Returns:
The resources listed by the service.
"""
client = bare_metal_clusters.ClustersClient()
return client.List(args)

View File

@@ -0,0 +1,61 @@
# -*- 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 query Anthos on bare metal version configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as flags
_EXAMPLES = """
To query all available versions in location `us-west1`, run:
$ {command} --location=us-west1
To query versions for creating a cluster with an admin cluster membership named
`my-admin-cluster-membership` managed in project `my-admin-cluster-project` and
location `us-west`, run:
$ {command} --location=us-west1 --admin-cluster-membership=my-admin-cluster-membership --admin-cluster-membership-project=my-admin-cluster-project
To query versions for upgrading a user cluster named `my-user-cluster` in
location `us-west1`, run:
$ {command} --location=us-west1 --cluster=my-user-cluster
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class QueryVersionConfig(base.Command):
"""Query versions for creating or upgrading an Anthos on bare metal user cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
flags.AddLocationResourceArg(parser, verb='to query versions')
flags.AddConfigType(parser)
def Run(self, args):
"""Runs the query-version-config command."""
client = apis.ClustersClient()
return client.QueryVersionConfig(args)

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.
"""Command to unenroll an Anthos cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as flags
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To unenroll a cluster named `my-cluster` managed in location `us-west1`,
run:
$ {command} my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Unenroll(base.Command):
"""Unenroll an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT
)
flags.AddClusterResourceArg(parser, verb='to unenroll')
flags.AddForceCluster(parser)
flags.AddAllowMissingCluster(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Runs the unenroll command."""
cluster_client = apis.ClustersClient()
cluster_ref = args.CONCEPTS.cluster.Parse()
operation = cluster_client.Unenroll(args)
# if a resource does not exist, --allow-missing returns an
# operation with an empty name. Early return to avoid polling error.
if operation.name is None:
return
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
operations.log_unenroll(cluster_ref, args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
operations.log_unenroll(cluster_ref, args.async_)
return operation_response

View File

@@ -0,0 +1,227 @@
# -*- 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 cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from typing import Optional
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags as flags
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.gkeonprem import flags as common_flags
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkeonprem.v1 import gkeonprem_v1_messages as messages
_EXAMPLES = """
To update a cluster named ``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Gathers command line arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT
)
flags.AddClusterResourceArg(parser, verb='to update', positional=True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateCluster(parser)
flags.AddLoadBalancerConfig(parser, is_update=True)
flags.AddControlPlaneConfig(parser, is_update=True)
flags.AddVersion(parser, is_update=True)
flags.AddSecurityConfig(parser, is_update=True)
flags.AddMaintenanceConfig(parser, is_update=True)
flags.AddNetworkConfig(parser, is_update=True)
flags.AddDescription(parser)
flags.AddClusterOperationsConfig(parser)
flags.AddNodeAccessConfig(parser)
flags.AddUpdateAnnotations(parser)
common_flags.AddBinauthzEvaluationMode(parser)
def Run(self, args):
"""Runs the update command.
Args:
args: The arguments received from command line.
Returns:
The return value depends on the command arguments. If `--async` is
specified, it returns an operation; otherwise, it returns the updated
resource. If `--validate-only` is specified, it returns operation or any
possible error.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
operation = cluster_client.Update(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.UpdatedResource(
cluster_ref, 'Anthos cluster on bare metal', args.async_
)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(base.UpdateCommand):
"""Update an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Gathers command line arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, verb='to update', positional=True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateCluster(parser)
flags.AddLoadBalancerConfig(parser, is_update=True)
flags.AddControlPlaneConfig(parser, is_update=True)
flags.AddVersion(parser, is_update=True)
flags.AddSecurityConfig(parser, is_update=True)
flags.AddMaintenanceConfig(parser, is_update=True)
flags.AddNetworkConfig(parser, is_update=True)
flags.AddDescription(parser)
flags.AddClusterOperationsConfig(parser)
flags.AddNodeAccessConfig(parser)
flags.AddUpdateAnnotations(parser)
common_flags.AddBinauthzEvaluationMode(parser)
def Run(self, args):
"""Runs the update command.
Args:
args: The arguments received from command line.
Returns:
The return value depends on the command arguments. If `--async` is
specified, it returns an operation; otherwise, it returns the updated
resource. If `--validate-only` is specified, it returns operation or any
possible error.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
operation = cluster_client.Update(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.UpdatedResource(cluster_ref, 'Anthos cluster on bare metal',
args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(base.UpdateCommand):
"""Update an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Gathers command line arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, verb='to update', positional=True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateCluster(parser)
flags.AddLoadBalancerConfig(parser, is_update=True)
flags.AddControlPlaneConfig(parser, is_update=True)
flags.AddVersion(parser, is_update=True)
flags.AddSecurityConfig(parser, is_update=True)
flags.AddMaintenanceConfig(parser, is_update=True)
flags.AddNetworkConfig(parser, is_update=True)
flags.AddDescription(parser)
flags.AddClusterOperationsConfig(parser)
flags.AddNodeAccessConfig(parser)
flags.AddUpdateAnnotations(parser)
common_flags.AddBinauthzEvaluationMode(parser)
flags.AddUpgradePolicy(parser)
def Run(self, args) -> Optional[messages.Operation]:
"""Runs the update command.
Args:
args: The arguments received from command line.
Returns:
The return value depends on the command arguments. If `--async` is
specified, it returns an operation; otherwise, it returns the updated
resource. If `--validate-only` is specified, it returns operation or any
possible error.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
operation = cluster_client.Update(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.UpdatedResource(cluster_ref, 'Anthos cluster on bare metal',
args.async_)
return operation_response

View File

@@ -0,0 +1,95 @@
# -*- 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.
"""Command to import and update an Anthos clusters on bare metal API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_clusters as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import cluster_flags
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
from googlecloudsdk.generated_clients.apis.gkeonprem.v1 import gkeonprem_v1_messages as messages
_EXAMPLES = """
A cluster can be imported by running:
$ {command} NAME --source=<path-to-file>
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.Hidden
class UpdateFromFile(base.Command):
"""Update an Anthos on bare metal user cluster using a configuration file."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def GetSchemaPath(for_help=False):
return export_util.GetSchemaPath(
'gkeonprem', 'v1', 'BareMetalCluster', for_help=for_help
)
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_CLUSTERS_FORMAT)
cluster_flags.AddClusterResourceArg(parser, 'to import and update')
export_util.AddImportFlags(
parser, UpdateFromFile.GetSchemaPath(for_help=True)
)
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddValidationOnly(parser)
def Run(self, args):
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = apis.ClustersClient()
data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)
bare_metal_cluster = export_util.Import(
message_type=messages.BareMetalCluster,
stream=data,
schema_path=UpdateFromFile.GetSchemaPath(),
)
operation = cluster_client.UpdateFromFile(args, bare_metal_cluster)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.validate_only:
return
if args.async_:
log.UpdatedResource(
cluster_ref, 'Anthos Cluster on bare metal', args.async_
)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.UpdatedResource(
cluster_ref, 'Anthos Cluster on bare metal', args.async_
)
return operation_response