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,31 @@
# -*- 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 vmware 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
from googlecloudsdk.command_lib.projects import util
from googlecloudsdk.core import log
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Clusters(base.Group):
"""Create and manage Anthos clusters on VMware."""

View File

@@ -0,0 +1,248 @@
# -*- 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 VMware."""
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 operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.vmware import constants as vmware_constants
from googlecloudsdk.command_lib.container.vmware import flags as vmware_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.ALPHA)
class CreateAlpha(base.CreateCommand):
"""Create an Anthos cluster on VMware."""
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(vmware_constants.VMWARE_CLUSTERS_FORMAT)
vmware_flags.AddClusterResourceArg(parser, 'to create', True)
vmware_flags.AddAdminClusterMembershipResourceArg(parser, positional=False)
base.ASYNC_FLAG.AddToParser(parser)
vmware_flags.AddValidationOnly(parser)
vmware_flags.AddDescription(parser)
vmware_flags.AddVersion(parser, required=True)
vmware_flags.AddClusterAnnotations(parser)
vmware_flags.AddVmwareControlPlaneNodeConfig(
parser, release_track=base.ReleaseTrack.ALPHA
)
vmware_flags.AddVmwareAAGConfig(parser)
vmware_flags.AddVmwareStorageConfig(parser)
vmware_flags.AddVmwareNetworkConfig(parser)
vmware_flags.AddVmwareLoadBalancerConfig(parser)
vmware_flags.AddVCenterConfig(parser)
vmware_flags.AddVmwareDataplaneV2Config(parser)
vmware_flags.AddEnableVmwareTracking(parser)
vmware_flags.AddVmwareAutoRepairConfig(parser)
vmware_flags.AddAuthorization(parser)
vmware_flags.AddEnableControlPlaneV2(parser)
vmware_flags.AddUpgradePolicy(parser)
def Run(
self, args: parser_extensions.Namespace
) -> 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 to be polled; otherwise, it returns a
completed operation. 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.validate_only:
return None
if args.async_:
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(base.CreateCommand):
"""Create an Anthos cluster on VMware."""
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(vmware_constants.VMWARE_CLUSTERS_FORMAT)
vmware_flags.AddClusterResourceArg(parser, 'to create', True)
vmware_flags.AddAdminClusterMembershipResourceArg(parser, positional=False)
base.ASYNC_FLAG.AddToParser(parser)
vmware_flags.AddValidationOnly(parser)
vmware_flags.AddDescription(parser)
vmware_flags.AddVersion(parser, required=True)
vmware_flags.AddClusterAnnotations(parser)
vmware_flags.AddVmwareControlPlaneNodeConfig(parser)
vmware_flags.AddVmwareAAGConfig(parser)
vmware_flags.AddVmwareStorageConfig(parser)
vmware_flags.AddVmwareNetworkConfig(parser)
vmware_flags.AddVmwareLoadBalancerConfig(parser)
vmware_flags.AddVCenterConfig(parser)
vmware_flags.AddVmwareDataplaneV2Config(parser)
vmware_flags.AddEnableVmwareTracking(parser)
vmware_flags.AddVmwareAutoRepairConfig(parser)
vmware_flags.AddAuthorization(parser)
vmware_flags.AddEnableControlPlaneV2(parser)
vmware_flags.AddUpgradePolicy(parser)
def Run(
self, args: parser_extensions.Namespace
) -> 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 to be polled; otherwise, it returns a
completed operation. 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.validate_only:
return None
if args.async_:
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create an Anthos cluster on VMware."""
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(vmware_constants.VMWARE_CLUSTERS_FORMAT)
vmware_flags.AddClusterResourceArg(parser, 'to create', True)
vmware_flags.AddAdminClusterMembershipResourceArg(parser, positional=False)
base.ASYNC_FLAG.AddToParser(parser)
vmware_flags.AddValidationOnly(parser)
vmware_flags.AddDescription(parser)
vmware_flags.AddVersion(parser, required=True)
vmware_flags.AddClusterAnnotations(parser)
vmware_flags.AddVmwareControlPlaneNodeConfig(parser)
vmware_flags.AddVmwareAAGConfig(parser)
vmware_flags.AddVmwareStorageConfig(parser)
vmware_flags.AddVmwareNetworkConfig(parser)
vmware_flags.AddVmwareLoadBalancerConfig(parser)
vmware_flags.AddVCenterConfig(parser)
vmware_flags.AddVmwareDataplaneV2Config(parser)
vmware_flags.AddEnableVmwareTracking(parser)
vmware_flags.AddVmwareAutoRepairConfig(parser)
vmware_flags.AddAuthorization(parser)
vmware_flags.AddEnableControlPlaneV2(parser)
vmware_flags.AddUpgradePolicy(parser)
def Run(
self, args: parser_extensions.Namespace
) -> 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 to be polled; otherwise, it returns a
completed operation. 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.validate_only:
return None
if args.async_:
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response

View File

@@ -0,0 +1,80 @@
# -*- 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 VMware."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.vmware import command_util
from googlecloudsdk.command_lib.container.vmware import 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 VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddClusterResourceArg(parser, 'to delete', True)
flags.AddValidationOnly(parser)
flags.AddForceDeleteCluster(parser)
flags.AddAllowMissingDeleteCluster(parser)
flags.AddIgnoreErrors(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Runs the delete command."""
cluster_ref = args.CONCEPTS.cluster.Parse()
items = [command_util.ClusterMessage(name=cluster_ref.vmwareClustersId)]
if not args.validate_only:
command_util.ConfirmationPrompt('cluster', items, 'deleted')
client = apis.ClustersClient()
operation = client.Delete(args)
if args.validate_only:
return None
# when using --allow-missing without --async on a non-existing resource,
# it would return an operation object with an empty name.
# return early to avoid potential polling error.
if operation.name is None:
return None
if args.async_:
log.DeletedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
log.DeletedResource(cluster_ref, 'Anthos Cluster on VMware', 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 VMware."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.vmware import 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 VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
flags.AddClusterResourceArg(parser, '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,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 enroll a cluster in an Anthos cluster on VMware."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.vmware import constants as vmware_constants
from googlecloudsdk.command_lib.container.vmware import flags as vmware_flags
_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 VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(vmware_constants.VMWARE_CLUSTERS_FORMAT)
vmware_flags.AddClusterResourceArg(parser, verb='to enroll')
vmware_flags.AddAdminClusterMembershipResourceArg(parser, positional=False)
base.ASYNC_FLAG.AddToParser(parser)
vmware_flags.AddValidationOnly(parser)
vmware_flags.AddUserClusterLocalName(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.validate_only:
return None
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 VMware API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.vmware import 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 VMware user cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def GetSchemaPath(for_help=False):
return export_util.GetSchemaPath(
'gkeonprem', 'v1', 'VmwareCluster', for_help=for_help
)
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddClusterResourceArg(parser, '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,90 @@
# -*- 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 VMware API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.vmware import flags
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 VMware user cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def GetSchemaPath(for_help=False):
return export_util.GetSchemaPath(
'gkeonprem', 'v1', 'VmwareCluster', for_help=for_help
)
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddClusterResourceArg(parser, 'to import')
export_util.AddImportFlags(
parser, schema_path=Import.GetSchemaPath(for_help=True)
)
base.ASYNC_FLAG.AddToParser(parser)
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)
vmware_cluster = export_util.Import(
message_type=messages.VmwareCluster,
stream=data,
schema_path=Import.GetSchemaPath(),
)
operation = cluster_client.CreateFromImport(
args, vmware_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 VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.CreatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response

View File

@@ -0,0 +1,62 @@
# -*- 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 clusters on VMware API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.vmware import constants
from googlecloudsdk.command_lib.container.vmware import flags
_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 VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the list command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(constants.VMWARE_CLUSTERS_FORMAT)
flags.AddLocationResourceArg(parser, 'to list Anthos on VMware clusters')
def Run(self, args):
"""Runs the list command.
Args:
args: Arguments received from command line.
Returns:
protorpc.message.Message, The resources listed by the service.
"""
client = apis.ClustersClient()
return client.List(args)

View File

@@ -0,0 +1,84 @@
# -*- 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 VMware version configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.vmware import flags
from googlecloudsdk.core import log
import six
_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
"""
_EPILOG = """
An Anthos version must be made available on the admin cluster ahead of the user
cluster creation or upgrade. Versions annotated with isInstalled=true are
installed on the admin cluster for the purpose of user cluster creation or
upgrade whereas other version are released and will be available for upgrade
once dependencies are resolved.
To install the version in the admin cluster, run:
$ {} container vmware admin-clusters update my-admin-cluster --required-platform-version=VERSION
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class QueryVersionConfig(base.Command):
"""Query versions for creating or upgrading an Anthos on VMware user cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
flags.AddLocationResourceArg(parser, 'to query versions')
flags.AddConfigType(parser)
def Run(self, args):
"""Runs the query-version-config command."""
client = apis.ClustersClient()
return client.QueryVersionConfig(args)
def Epilog(self, resources_were_displayed):
super(QueryVersionConfig, self).Epilog(resources_were_displayed)
command_base = 'gcloud'
if (
self.ReleaseTrack() is base.ReleaseTrack.BETA
or self.ReleaseTrack() is base.ReleaseTrack.ALPHA
):
command_base += ' ' + six.text_type(self.ReleaseTrack()).lower()
log.status.Print(_EPILOG.format(command_base))

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.
"""Command to unenroll an Anthos cluster on VMware."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.vmware import constants as vmware_constants
from googlecloudsdk.command_lib.container.vmware import flags
_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 VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
parser.display_info.AddFormat(vmware_constants.VMWARE_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, 'to unenroll')
flags.AddForceUnenrollCluster(parser)
flags.AddAllowMissingUnenrollCluster(parser)
flags.AddValidationOnly(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 args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.validate_only:
return
# When using --allow-missing without --async on a non-existing resource,
# the server would return an empty operation object.
# return early to avoid potential polling error.
if operation and operation.name is None:
return
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,229 @@
# -*- 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 VMware."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.vmware import constants as vmware_constants
from googlecloudsdk.command_lib.container.vmware import flags
from googlecloudsdk.core import log
_EXAMPLES = """
To update a cluster named ``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(base.UpdateCommand):
"""Update an Anthos cluster on VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(vmware_constants.VMWARE_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, 'to update', True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateCluster(parser)
flags.AddDescription(parser)
flags.AddVersion(parser)
flags.AddVmwareControlPlaneNodeConfig(parser, for_update=True)
flags.AddVmwareAAGConfig(parser, for_update=True)
flags.AddVmwareStorageConfig(parser, for_update=True)
flags.AddVmwareNetworkConfig(parser, for_update=True)
flags.AddVmwareLoadBalancerConfig(parser, for_update=True)
flags.AddVmwareDataplaneV2Config(parser, for_update=True)
flags.AddEnableVmwareTracking(parser, for_update=True)
flags.AddVmwareAutoRepairConfig(parser, for_update=True)
flags.AddAuthorization(parser)
flags.AddUpdateAnnotations(parser)
flags.AddUpgradePolicy(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 None 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.validate_only:
return
if args.async_:
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(base.UpdateCommand):
"""Update an Anthos cluster on VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(vmware_constants.VMWARE_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, 'to update', True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateCluster(parser)
flags.AddDescription(parser)
flags.AddVersion(parser)
flags.AddVmwareControlPlaneNodeConfig(parser, for_update=True)
flags.AddVmwareAAGConfig(parser, for_update=True)
flags.AddVmwareStorageConfig(parser, for_update=True)
flags.AddVmwareNetworkConfig(parser, for_update=True)
flags.AddVmwareLoadBalancerConfig(parser, for_update=True)
flags.AddVmwareDataplaneV2Config(parser, for_update=True)
flags.AddEnableVmwareTracking(parser, for_update=True)
flags.AddVmwareAutoRepairConfig(parser, for_update=True)
flags.AddAuthorization(parser)
flags.AddUpdateAnnotations(parser)
flags.AddUpgradePolicy(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 None 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.validate_only:
return
if args.async_:
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update an Anthos cluster on VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(vmware_constants.VMWARE_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, 'to update', True)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateCluster(parser)
flags.AddDescription(parser)
flags.AddVersion(parser)
flags.AddVmwareControlPlaneNodeConfig(parser, for_update=True)
flags.AddVmwareAAGConfig(parser, for_update=True)
flags.AddVmwareStorageConfig(parser, for_update=True)
flags.AddVmwareNetworkConfig(parser, for_update=True)
flags.AddVmwareLoadBalancerConfig(parser, for_update=True)
flags.AddVmwareDataplaneV2Config(parser, for_update=True)
flags.AddEnableVmwareTracking(parser, for_update=True)
flags.AddVmwareAutoRepairConfig(parser, for_update=True)
flags.AddAuthorization(parser)
flags.AddUpdateAnnotations(parser)
flags.AddUpgradePolicy(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 None 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.validate_only:
return
if args.async_:
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response

View File

@@ -0,0 +1,88 @@
# -*- 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 VMware API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.vmware import flags
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 VMware user cluster using a configuration file."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def GetSchemaPath(for_help=False):
return export_util.GetSchemaPath(
'gkeonprem', 'v1', 'VmwareCluster', for_help=for_help
)
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddClusterResourceArg(parser, 'to import and update')
export_util.AddImportFlags(
parser, UpdateFromFile.GetSchemaPath(for_help=True)
)
base.ASYNC_FLAG.AddToParser(parser)
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)
vmware_cluster = export_util.Import(
message_type=messages.VmwareCluster,
stream=data,
schema_path=UpdateFromFile.GetSchemaPath(),
)
operation = cluster_client.UpdateFromFile(args, vmware_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 VMware', args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.UpdatedResource(cluster_ref, 'Anthos Cluster on VMware', args.async_)
return operation_response

View File

@@ -0,0 +1,132 @@
# -*- 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 centrally upgrade an Anthos cluster on VMware."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.api_lib.container.gkeonprem import vmware_admin_clusters
from googlecloudsdk.api_lib.container.gkeonprem import vmware_clusters
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.gkeonprem import flags as common_flags
from googlecloudsdk.command_lib.container.vmware import constants
from googlecloudsdk.command_lib.container.vmware import errors
from googlecloudsdk.command_lib.container.vmware import flags
from googlecloudsdk.core import log
from googlecloudsdk.core.util import semver
_EXAMPLES = """
To upgrade a cluster named ``my-cluster'' managed in location ``us-west1'' to
version ``1.13.0-gke.1000'', run:
$ {command} my-cluster --location=us-west1 --version=1.13.0-gke.1000
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
@base.DefaultUniverseOnly
class Upgrade(base.Command):
"""Centrally upgrade an Anthos cluster on VMware."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers command line arguments for the upgrade command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(constants.VMWARE_CLUSTERS_FORMAT)
flags.AddClusterResourceArg(parser, 'to upgrade')
flags.AddVersion(parser, required=True)
def Run(self, args):
"""Runs the upgrade command.
Args:
args: The arguments received from command line.
Returns:
The operation response.
"""
cluster_ref = args.CONCEPTS.cluster.Parse()
cluster_client = vmware_clusters.ClustersClient()
cluster = cluster_client.Describe(cluster_ref)
self._validate_version(cluster, cluster_ref)
admin_cluster_name = cluster.adminClusterName
if admin_cluster_name is None:
operation_response = self._enroll_admin_cluster(
args, cluster_ref, cluster.adminClusterMembership)
res = encoding.MessageToPyValue(operation_response)
admin_cluster_name = res.get('name')
admin_cluster_ref = flags.GetAdminClusterResource(admin_cluster_name)
self._update_platform(args, admin_cluster_ref)
return self._upgrade(args, cluster_ref)
def _validate_version(self, cluster, cluster_ref):
if cluster.onPremVersion is None:
raise errors.MissingClusterField(cluster_ref.RelativeName(),
'onPremVersion')
if semver.SemVer(cluster.onPremVersion) < semver.SemVer('1.13.0-gke.1'):
raise errors.UnsupportedClusterVersion(
'Central upgrade is only supported in cluster version 1.13.0 '
'and newer. Cluster is at version {}.'.format(cluster.onPremVersion))
def _enroll_admin_cluster(self, args, cluster_ref, admin_cluster_membership):
admin_cluster_membership_ref = common_flags.GetAdminClusterMembershipResource(
admin_cluster_membership)
log.status.Print('Admin cluster is not enrolled. '
'Enrolling admin cluster with membership [{}]'.format(
admin_cluster_membership))
admin_cluster_client = vmware_admin_clusters.AdminClustersClient()
operation_client = operations.OperationsClient()
operation = admin_cluster_client.Enroll(
args,
parent=cluster_ref.Parent().RelativeName(),
membership=admin_cluster_membership,
vmware_admin_cluster_id=admin_cluster_membership_ref.Name())
operation_response = operation_client.Wait(operation)
return operation_response
def _update_platform(self, args, admin_cluster_ref):
log.status.Print('Preparing version {} for upgrade'.format(args.version))
admin_cluster_client = vmware_admin_clusters.AdminClustersClient()
operation_client = operations.OperationsClient()
operation = admin_cluster_client.Update(
args, admin_cluster_ref, is_user_cluster_upgrade=True)
operation_response = operation_client.Wait(operation)
log.UpdatedResource(admin_cluster_ref, 'Anthos on VMware admin cluster')
return operation_response
def _upgrade(self, args, cluster_ref):
log.status.Print(
'Upgrading Anthos on VMware user cluster [{}]'.format(cluster_ref))
cluster_client = vmware_clusters.ClustersClient()
operation_client = operations.OperationsClient()
operation = cluster_client.Update(args)
operation_response = operation_client.Wait(operation)
log.UpdatedResource(cluster_ref, 'Anthos on VMware user cluster')
return operation_response