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 bare-metal`."""
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 BareMetal(base.Group):
"""Deploy and manage Anthos clusters on bare metal for running containers."""
category = base.COMPUTE_CATEGORY

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 bare-metal admin-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 AdminClusters(base.Group):
"""Create and manage admin clusters in Anthos on bare metal."""

View File

@@ -0,0 +1,106 @@
# -*- 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 create an Anthos on bare metal admin cluster."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_admin_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 admin_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
_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, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Create(base.CreateCommand):
"""Create an Anthos on bare metal admin cluster."""
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_ADMIN_CLUSTERS_FORMAT
)
bare_metal_flags.AddAdminClusterResourceArg(parser, 'to create', True)
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.AddAdminLoadBalancerConfig(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.AddAdminWorkloadNodeConfig(parser)
bare_metal_flags.AddNodeAccessConfig(parser)
bare_metal_flags.AddSecurityConfig(parser)
flags.AddBinauthzEvaluationMode(parser)
def Run(self, args):
"""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.admin_cluster.Parse()
cluster_client = apis.AdminClustersClient()
operation = cluster_client.Create(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
log.CreatedResource(
cluster_ref, 'Anthos on bare metal Admin Cluster', args.async_
)
return operation
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
if not args.validate_only:
log.CreatedResource(
cluster_ref, 'Anthos on bare metal Admin Cluster', args.async_
)
return operation_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 on bare metal admin cluster."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_admin_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import admin_cluster_flags as cluster_flags
_EXAMPLES = """
To describe an admin 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 on bare metal admin cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddAdminClusterResourceArg(parser, 'to describe')
def Run(self, args):
"""Runs the describe command."""
cluster_ref = args.CONCEPTS.admin_cluster.Parse()
client = apis.AdminClustersClient()
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 an admin 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_admin_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 admin_cluster_flags as 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.container.gkeonprem import 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 on bare metal admin cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_ADMIN_CLUSTERS_FORMAT
)
flags.AddAdminClusterMembershipResourceArg(parser, positional=False)
cluster_flags.AddAdminClusterResourceArg(parser, 'to enroll')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
cluster_client = apis.AdminClustersClient()
cluster_ref = args.CONCEPTS.admin_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,75 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to list all admin clusters in the 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_admin_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import admin_cluster_flags as cluster_flags
from googlecloudsdk.command_lib.container.bare_metal import constants
from googlecloudsdk.core import log
_EXAMPLES = """
To list all admin clusters managed in location ``us-west1'', run:
$ {command} --location=us-west1
"""
_EPILOG = """
To include admin clusters that are not enrolled with the Anthos On-Prem API, run:
$ gcloud container fleet memberships list --filter='endpoint.onPremCluster.adminCluster=true'
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class List(base.ListCommand):
"""List Anthos on bare metal admin clusters."""
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.BARE_METAL_ADMIN_CLUSTERS_FORMAT)
cluster_flags.AddLocationResourceArg(
parser, 'to list Anthos on bare metal admin 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.AdminClustersClient()
return client.List(args)
def Epilog(self, resources_were_displayed):
super(List, self).Epilog(resources_were_displayed)
log.status.Print(_EPILOG)

View File

@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to query Anthos on bare metal admin cluster 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_admin_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import admin_cluster_flags as flags
_EXAMPLES = """
To query versions for creating an admin cluster in location `us-west1`, run:
$ {command} --location=us-west1
To query versions for upgrading an admin cluster named `my-admin-cluster` in
location `us-west1`, run:
$ {command} --location=us-west1 --admin-cluster=my-admin-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 admin cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
flags.AddLocationResourceArg(parser, 'to query versions')
flags.AddAdminConfigType(parser)
def Run(self, args):
"""Runs the query-version-config command."""
client = apis.AdminClustersClient()
return client.QueryVersionConfig(args)

View File

@@ -0,0 +1,81 @@
# -*- 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 on bare metal admin cluster."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import bare_metal_admin_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 admin_cluster_flags as cluster_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 an admin 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 Unenroll(base.Command):
"""Unenroll an Anthos on bare metal admin cluster so that it is no longer managed by the Anthos On-Prem API."""
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_ADMIN_CLUSTERS_FORMAT
)
cluster_flags.AddAdminClusterResourceArg(parser, 'to unenroll')
cluster_flags.AddAllowMissingCluster(parser)
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddValidationOnly(parser)
cluster_flags.AddIgnoreErrors(parser)
def Run(self, args):
"""Runs the unenroll command."""
cluster_client = apis.AdminClustersClient()
cluster_ref = args.CONCEPTS.admin_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
# 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_:
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,97 @@
# -*- 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 bare_metal_admin_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 admin_cluster_flags as 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.container.gkeonprem 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, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Update(base.UpdateCommand):
"""Update an Anthos on bare metal admin cluster."""
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(
bare_metal_constants.BARE_METAL_ADMIN_CLUSTERS_FORMAT)
cluster_flags.AddAdminClusterResourceArg(parser, 'to update', True)
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddValidationOnly(parser)
cluster_flags.AddDescription(parser)
cluster_flags.AddVersion(parser, is_update=True)
cluster_flags.AddControlPlaneConfig(parser, is_update=True)
cluster_flags.AddProxyConfig(parser, is_update=True)
cluster_flags.AddClusterOperationsConfig(parser)
cluster_flags.AddMaintenanceConfig(parser, is_update=True)
cluster_flags.AddNetworkConfig(parser, is_update=True)
cluster_flags.AddAdminWorkloadNodeConfig(parser)
cluster_flags.AddNodeAccessConfig(parser)
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.
"""
cluster_ref = args.CONCEPTS.admin_cluster.Parse()
cluster_client = apis.AdminClustersClient()
operation = cluster_client.Update(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
log.UpdatedResource(cluster_ref, 'Anthos on bare metal Admin Cluster',
args.async_)
return operation
else:
operation_client = operations.OperationsClient()
operation_response = operation_client.Wait(operation)
log.UpdatedResource(cluster_ref, 'Anthos on bare metal Admin Cluster',
args.async_)
return operation_response

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

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 node-pools`."""
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 NodePools(base.Group):
"""Create and manage node pools in an Anthos cluster on bare metal."""

View File

@@ -0,0 +1,209 @@
# -*- 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 a node pool in 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_node_pools as apis
from googlecloudsdk.api_lib.container.gkeonprem import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
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.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkeonprem.v1 import gkeonprem_v1_messages as messages
_EXAMPLES = """
To create a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a node pool in 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_NODE_POOLS_FORMAT
)
node_pool_flags.AddNodePoolResourceArg(parser, 'to create')
cluster_flags.AddValidationOnly(parser)
base.ASYNC_FLAG.AddToParser(parser)
node_pool_flags.AddNodePoolAnnotations(parser)
node_pool_flags.AddNodePoolDisplayName(parser)
node_pool_flags.AddNodePoolConfig(parser)
def Run(self, args):
"""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.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = 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(
node_pool_ref,
'node pool in Anthos cluster on bare metal',
args.async_,
)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(base.CreateCommand):
"""Create a node pool in 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_NODE_POOLS_FORMAT)
node_pool_flags.AddNodePoolResourceArg(parser, 'to create')
cluster_flags.AddValidationOnly(parser)
base.ASYNC_FLAG.AddToParser(parser)
node_pool_flags.AddNodePoolAnnotations(parser)
node_pool_flags.AddNodePoolDisplayName(parser)
node_pool_flags.AddNodePoolConfig(parser)
def Run(self, args):
"""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.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = 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(node_pool_ref,
'node pool in Anthos cluster on bare metal',
args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(base.CreateCommand):
"""Create a node pool in 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_NODE_POOLS_FORMAT)
node_pool_flags.AddNodePoolResourceArg(parser, 'to create')
cluster_flags.AddValidationOnly(parser)
base.ASYNC_FLAG.AddToParser(parser)
node_pool_flags.AddNodePoolAnnotations(parser)
node_pool_flags.AddNodePoolDisplayName(parser)
node_pool_flags.AddNodePoolConfig(parser)
node_pool_flags.AddNodePoolVersion(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; otherwise, it returns the created
resource. If `--validate-only` is specified, it returns None or any
possible error.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = 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(node_pool_ref,
'node pool in Anthos cluster on bare metal',
args.async_)
return operation_response

View File

@@ -0,0 +1,77 @@
# -*- 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 a node pool 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_node_pools 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 node_pool_flags
from googlecloudsdk.core import log
_EXAMPLES = """
To delete a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Delete(base.DeleteCommand):
"""Delete a node pool in an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
node_pool_flags.AddNodePoolResourceArg(parser, 'to delete')
node_pool_flags.AddAllowMissingNodePool(parser)
cluster_flags.AddValidationOnly(parser)
base.ASYNC_FLAG.AddToParser(parser)
node_pool_flags.AddIgnoreErrors(parser)
def Run(self, args):
"""Runs the delete command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = client.Delete(args)
if args.validate_only:
return
if operation.name is None:
return operation
if args.async_:
log.DeletedResource(node_pool_ref,
'Node Pool in Anthos Cluster on bare metal',
args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
log.DeletedResource(node_pool_ref,
'Node Pool in 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 a node pool 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_node_pools as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import node_pool_flags as flags
_EXAMPLES = """
To describe a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Describe(base.DescribeCommand):
"""Describe a node pool in an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddNodePoolResourceArg(parser, 'to describe')
def Run(self, args):
"""Runs the describe command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
return client.Describe(node_pool_ref)

View File

@@ -0,0 +1,74 @@
# -*- 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 enroll a node pool from a user cluster in Anthos 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_node_pools 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.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To enroll a node pool named `my-node-pool` in a cluster named
`my-cluster` managed in location `us-west1`, run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Enroll(base.Command):
"""Enroll a node pool of a user cluster in Anthos on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT
)
node_pool_flags.AddNodePoolResourceArg(parser, 'to enroll')
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddValidationOnly(parser)
def Run(self, args):
"""Runs the enroll command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = client.Enroll(args)
if args.validate_only:
return
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
operations.log_enroll(node_pool_ref, args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
operations.log_enroll(node_pool_ref, args.async_)
return response

View File

@@ -0,0 +1,53 @@
# -*- 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 node pools 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_node_pools 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
from googlecloudsdk.command_lib.container.bare_metal import constants
_EXAMPLES = """
To list all node pools in a cluster named ``my-cluster''
managed in location ``us-west1'', run:
$ {command} --cluster=my-cluster --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class List(base.ListCommand):
"""List node pools in an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddClusterResourceArg(parser, 'to list', positional=False)
parser.display_info.AddFormat(constants.BARE_METAL_NODE_POOLS_FORMAT)
def Run(self, args):
"""Runs the list command."""
cluster_ref = args.CONCEPTS.cluster.Parse()
client = apis.NodePoolsClient()
return client.List(cluster_ref, args.page_size)

View File

@@ -0,0 +1,77 @@
# -*- 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 unenroll a node pool from a user cluster in Anthos 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_node_pools 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 constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To unenroll a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Unenroll(base.Command):
"""Unenroll a node pool from a user cluster in Anthos on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT
)
node_pool_flags.AddNodePoolResourceArg(parser, 'to unenroll')
base.ASYNC_FLAG.AddToParser(parser)
node_pool_flags.AddAllowMissingNodePool(parser)
node_pool_flags.AddValidationOnly(parser)
def Run(self, args):
"""Runs the unenroll command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = client.Unenroll(args)
if args.validate_only:
return
# using allow-missing returns an empty operation.
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(node_pool_ref, args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
operations.log_unenroll(node_pool_ref, args.async_)
return response

View File

@@ -0,0 +1,205 @@
# -*- 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 a node pool in 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_node_pools 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.bare_metal import node_pool_flags as flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkeonprem.v1 import gkeonprem_v1_messages as messages
_EXAMPLES = """
To update a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a node pool in an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers commandline arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT
)
flags.AddNodePoolResourceArg(parser, 'to update')
cluster_flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateNodePool(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddNodePoolConfig(parser, is_update=True)
flags.AddNodePoolDisplayName(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.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = 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(
node_pool_ref,
'Node pool in Anthos cluster on bare metal',
args.async_,
)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(base.UpdateCommand):
"""Update a node pool in an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers commandline arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT)
flags.AddNodePoolResourceArg(parser, 'to update')
cluster_flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateNodePool(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddNodePoolConfig(parser, is_update=True)
flags.AddNodePoolDisplayName(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.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = 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(node_pool_ref,
'Node pool in Anthos cluster on bare metal',
args.async_)
return operation_response
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(base.UpdateCommand):
"""Update a node pool in an Anthos cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers commandline arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT)
flags.AddNodePoolResourceArg(parser, 'to update')
cluster_flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateNodePool(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddNodePoolConfig(parser, is_update=True)
flags.AddNodePoolDisplayName(parser)
flags.AddNodePoolVersion(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 None or any
possible error.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.NodePoolsClient()
operation = 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(node_pool_ref,
'Node pool in Anthos cluster on bare metal',
args.async_)
return operation_response

View File

@@ -0,0 +1,35 @@
# -*- 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 operations`."""
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 Operations(base.Group):
"""Manage Anthos on bare metal long running operations."""
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
pass

View File

@@ -0,0 +1,50 @@
# -*- 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 operation."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
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
_EXAMPLES = """
To describe an operation in location ``us-west1'', run:
$ {command} OPERATION_ID --location=us-west1
"""
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Describe(base.DescribeCommand):
"""Describe an operation."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddOperationResourceArg(parser, 'to describe')
def Run(self, args):
"""Runs the describe command."""
operation_client = operations.OperationsClient()
operation_ref = args.CONCEPTS.operation_id.Parse()
return operation_client.Describe(operation_ref)

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 operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
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
_EXAMPLES = """
To list all operations 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 operations."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddLocationResourceArg(parser, 'to list operations')
parser.display_info.AddFormat(constants.OPERATIONS_FORMAT)
def Run(self, args):
"""Runs the list command."""
operation_client = operations.OperationsClient()
bare_metal_operation_predicate = (
'metadata.target ~ projects/.+/locations/.+/bareMetal')
if args.filter:
args.filter = bare_metal_operation_predicate + ' AND ' + args.filter
else:
args.filter = bare_metal_operation_predicate
return operation_client.List(args)

View File

@@ -0,0 +1,87 @@
# -*- 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 wait for an operation to complete."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
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
_EXAMPLES = """
To wait for an operation in location ``us-west1'' to complete, run:
$ {command} OPERATION_ID --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class WaitAlpha(base.Command):
"""Poll an operation for completion."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddOperationResourceArg(parser, 'to wait for completion')
cluster_flags.AddOperationTimeout(parser)
def Run(self, args):
"""Runs the wait command."""
operation_client = operations.OperationsClient()
operation_ref = args.CONCEPTS.operation_id.Parse()
return operation_client.Wait(
operation_ref=operation_ref, timeout=args.timeout
)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class WaitBeta(base.Command):
"""Poll an operation for completion."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddOperationResourceArg(parser, 'to wait for completion')
def Run(self, args):
"""Runs the wait command."""
operation_client = operations.OperationsClient()
operation_ref = args.CONCEPTS.operation_id.Parse()
return operation_client.Wait(operation_ref=operation_ref)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Wait(base.Command):
"""Poll an operation for completion."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddOperationResourceArg(parser, 'to wait for completion')
def Run(self, args):
"""Runs the wait command."""
operation_client = operations.OperationsClient()
operation_ref = args.CONCEPTS.operation_id.Parse()
return operation_client.Wait(operation_ref=operation_ref)

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group `gcloud container bare-metal standalone-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)
class StandaloneClusters(base.Group):
"""Create and manage standalone clusters in Anthos on bare metal."""

View File

@@ -0,0 +1,51 @@
# -*- 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 describe an Anthos on bare metal standalone cluster."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import standalone_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import standalone_cluster_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)
class Describe(base.DescribeCommand):
"""Describe an Anthos on bare metal standalone cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
standalone_cluster_flags.AddStandaloneClusterResourceArg(
parser, verb='to describe'
)
def Run(self, args):
"""Runs the describe command."""
cluster_ref = args.CONCEPTS.standalone_cluster.Parse()
client = apis.StandaloneClustersClient()
return client.Describe(cluster_ref)

View File

@@ -0,0 +1,74 @@
# -*- 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 enroll a standalone 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 operations
from googlecloudsdk.api_lib.container.gkeonprem import standalone_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import standalone_cluster_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To enroll a cluster named ``my-cluster'' managed in location ``us-west1''
with cluster membership of
``projects/my-project/locations/us-west1/memberships/my-membership'',
run:
$ {command} my-cluster --location=us-west1 --membership=projects/my-project/locations/us-west1/memberships/my-membership
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Enroll(base.Command):
"""Enroll an Anthos on bare metal standalone cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Parses args for enrolling an Anthos on bare metal standalone cluster."""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_STANDALONE_CLUSTERS_FORMAT
)
standalone_cluster_flags.AddStandaloneClusterMembershipResourceArg(
parser, positional=False, required=True
)
standalone_cluster_flags.AddStandaloneClusterResourceArg(
parser, verb='to enroll'
)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
cluster_client = apis.StandaloneClustersClient()
cluster_ref = args.CONCEPTS.standalone_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,59 @@
# -*- 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 list all clusters in the Anthos on bare metal standalone API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import standalone_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)
class List(base.ListCommand):
"""List Anthos on bare metal standalone clusters."""
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_STANDALONE_CLUSTERS_FORMAT
)
def Run(self, args):
"""Runs the list command.
Args:
args: Arguments received from command line.
Returns:
The resources listed by the service.
"""
location_ref = args.CONCEPTS.location.Parse()
client = standalone_clusters.StandaloneClustersClient()
return client.List(location_ref, limit=args.limit, page_size=args.page_size)

View File

@@ -0,0 +1,50 @@
# -*- 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 query Anthos on bare metal standalone cluster version configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.gkeonprem import standalone_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.container.bare_metal import standalone_cluster_flags as flags
_EXAMPLES = """
To query versions for upgrading a standalone cluster named `my-cluster` in
location `us-west1`, run:
$ {command} --location=us-west1 --cluster=my-cluster
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class QueryVersionConfig(base.Command):
"""Query versions for upgrading an Anthos on bare metal standalone cluster."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Registers flags for this command."""
cluster_flags.AddLocationResourceArg(parser, 'to query versions')
flags.AddStandaloneConfigType(parser)
def Run(self, args):
"""Runs the query-version-config command."""
client = apis.StandaloneClustersClient()
return client.QueryVersionConfig(args)

View File

@@ -0,0 +1,75 @@
# -*- 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 unenroll an Anthos on bare metal standalone cluster."""
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 standalone_clusters as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import standalone_cluster_flags as cluster_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To unenroll a standalone cluster named `my-cluster` managed in location `us-west1`,
run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Unenroll(base.Command):
"""Unenroll an Anthos on bare metal standalone cluster."""
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_STANDALONE_CLUSTERS_FORMAT
)
cluster_flags.AddStandaloneClusterResourceArg(parser, 'to unenroll')
cluster_flags.AddAllowMissingStandaloneCluster(parser)
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddIgnoreErrors(parser)
def Run(self, args):
"""Runs the unenroll command."""
cluster_client = apis.StandaloneClustersClient()
cluster_ref = args.CONCEPTS.standalone_cluster.Parse()
operation = cluster_client.Unenroll(args)
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
# 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_:
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,101 @@
# -*- 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 update an Anthos on bare metal standalone cluster."""
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 standalone_clusters
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import standalone_cluster_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.command_lib.container.gkeonprem import flags
from googlecloudsdk.core import log
_EXAMPLES = """
To update a standalone cluster named ``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-cluster --location=us-west1
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Update an Anthos on bare metal standalone cluster."""
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(
bare_metal_constants.BARE_METAL_STANDALONE_CLUSTERS_FORMAT
)
standalone_cluster_flags.AddStandaloneClusterResourceArg(
parser, verb='to update', positional=True
)
base.ASYNC_FLAG.AddToParser(parser)
standalone_cluster_flags.AddValidationOnly(parser)
standalone_cluster_flags.AddAllowMissingUpdateStandaloneCluster(parser)
standalone_cluster_flags.AddControlPlaneConfig(parser, is_update=True)
standalone_cluster_flags.AddVersion(parser, is_update=True)
standalone_cluster_flags.AddSecurityConfig(parser, is_update=True)
standalone_cluster_flags.AddMaintenanceConfig(parser, is_update=True)
standalone_cluster_flags.AddNetworkConfig(parser, is_update=True)
standalone_cluster_flags.AddLoadBalancerConfig(parser, is_update=True)
standalone_cluster_flags.AddDescription(parser)
standalone_cluster_flags.AddClusterOperationsConfig(parser)
standalone_cluster_flags.AddNodeAccessConfig(parser)
standalone_cluster_flags.AddUpdateAnnotations(parser)
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.standalone_cluster.Parse()
cluster_client = standalone_clusters.StandaloneClustersClient()
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 on bare metal standalone cluster',
args.async_)
return operation_response

View File

@@ -0,0 +1,28 @@
# -*- 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 group `gcloud container bare-metal standalone-node-pools`."""
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.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class StandaloneNodePools(base.Group):
"""Create and manage node pools in an Anthos standalone cluster on bare metal."""

View File

@@ -0,0 +1,93 @@
# -*- 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 create a node pool in an Anthos standalone 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 operations
from googlecloudsdk.api_lib.container.gkeonprem import standalone_node_pools
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.bare_metal import standalone_node_pool_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.core import log
_EXAMPLES = """
To create a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
"""Create a node pool in an Anthos standalone 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_NODE_POOLS_FORMAT)
standalone_node_pool_flags.AddNodePoolResourceArg(parser, 'to create')
node_pool_flags.AddValidationOnly(parser)
base.ASYNC_FLAG.AddToParser(parser)
standalone_node_pool_flags.AddNodePoolAnnotations(parser)
standalone_node_pool_flags.AddNodePoolDisplayName(parser)
standalone_node_pool_flags.AddNodePoolConfig(parser)
def Run(self, args):
"""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.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = standalone_node_pools.StandaloneNodePoolsClient()
operation = 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(
node_pool_ref,
'node pool in Anthos standalone cluster on bare metal',
args.async_,
)
return operation_response

View File

@@ -0,0 +1,80 @@
# -*- 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 delete a node pool in an Anthos standalone 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 operations
from googlecloudsdk.api_lib.container.gkeonprem import standalone_node_pools as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.bare_metal import standalone_node_pool_flags
from googlecloudsdk.core import log
_EXAMPLES = """
To delete a node pool named ``my-node-pool'' in a standalone cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Delete(base.DeleteCommand):
"""Delete a node pool in an Anthos standalone cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
standalone_node_pool_flags.AddNodePoolResourceArg(parser, 'to delete')
standalone_node_pool_flags.AddAllowMissingNodePoolFlag(parser)
node_pool_flags.AddValidationOnly(parser)
base.ASYNC_FLAG.AddToParser(parser)
standalone_node_pool_flags.AddIgnoreErrors(parser)
def Run(self, args):
"""Runs the delete command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.StandaloneNodePoolsClient()
operation = client.Delete(args)
if args.validate_only:
return
if operation.name is None:
return operation
if args.async_:
log.DeletedResource(
node_pool_ref,
'Node Pool in Anthos Standalone Cluster on bare metal',
args.async_,
)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
log.DeletedResource(
node_pool_ref,
'Node Pool in Anthos Standalone Cluster on bare metal',
args.async_,
)
return response

View File

@@ -0,0 +1,50 @@
# -*- 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 describe a node pool in an Anthos standalone 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 standalone_node_pools as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import standalone_node_pool_flags as flags
_EXAMPLES = """
To describe a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --standalone-cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Describe(base.DescribeCommand):
"""Describe a node pool in an Anthos standalone cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
flags.AddNodePoolResourceArg(parser, 'to describe')
def Run(self, args):
"""Runs the describe command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.StandaloneNodePoolsClient()
return client.Describe(node_pool_ref)

View File

@@ -0,0 +1,73 @@
# -*- 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 enroll a node pool from a standalone cluster in Anthos on bare metal."""
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 standalone_node_pools 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.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import standalone_node_pool_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To enroll a node pool named `my-node-pool` in a cluster named
`my-cluster` managed in location `us-west1`, run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Enroll(base.Command):
"""Enroll a node pool of a standalone cluster in Anthos on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT
)
standalone_node_pool_flags.AddNodePoolResourceArg(parser, 'to enroll')
base.ASYNC_FLAG.AddToParser(parser)
cluster_flags.AddValidationOnly(parser)
def Run(self, args):
"""Runs the enroll command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.StandaloneNodePoolsClient()
operation = client.Enroll(args)
if args.validate_only:
return
if args.async_ and not args.IsSpecified('format'):
args.format = constants.OPERATIONS_FORMAT
if args.async_:
operations.log_enroll(node_pool_ref, args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
operations.log_enroll(node_pool_ref, args.async_)
return response

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to list node pools in an Anthos standalone cluster on bare metal."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.protorpclite import messages as protorpc_message
from googlecloudsdk.api_lib.container.gkeonprem import standalone_node_pools as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.bare_metal import constants
from googlecloudsdk.command_lib.container.bare_metal import standalone_cluster_flags
_EXAMPLES = """
To list all node pools in a cluster named ``my-cluster''
managed in location ``us-west1'', run:
$ {command} --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""List node pools in an Anthos standalone cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
standalone_cluster_flags.AddStandaloneClusterResourceArg(
parser, 'to list', positional=False
)
parser.display_info.AddFormat(constants.BARE_METAL_NODE_POOLS_FORMAT)
def Run(self, args: parser_extensions.Namespace) -> protorpc_message.Message:
"""Runs the list command."""
cluster_ref = args.CONCEPTS.cluster.Parse()
client = apis.StandaloneNodePoolsClient()
return client.List(cluster_ref, args.limit, args.page_size)

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 unenroll a node pool from a standalone cluster in Anthos on bare metal."""
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 standalone_node_pools as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.bare_metal import standalone_node_pool_flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
_EXAMPLES = """
To unenroll a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Unenroll(base.Command):
"""Unenroll a node pool from a standalone cluster in Anthos on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT
)
standalone_node_pool_flags.AddNodePoolResourceArg(parser, 'to unenroll')
base.ASYNC_FLAG.AddToParser(parser)
standalone_node_pool_flags.AddAllowMissingNodePoolFlag(parser)
node_pool_flags.AddValidationOnly(parser)
def Run(self, args):
"""Runs the unenroll command."""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.StandaloneNodePoolsClient()
operation = client.Unenroll(args)
if args.validate_only:
return
# using allow-missing returns an empty operation.
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(node_pool_ref, args.async_)
return operation
else:
operation_client = operations.OperationsClient()
response = operation_client.Wait(operation)
operations.log_unenroll(node_pool_ref, args.async_)
return response

View File

@@ -0,0 +1,93 @@
# -*- 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 update a node pool in an Anthos standalone 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 operations
from googlecloudsdk.api_lib.container.gkeonprem import standalone_node_pools as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.bare_metal import constants as bare_metal_constants
from googlecloudsdk.command_lib.container.bare_metal import node_pool_flags
from googlecloudsdk.command_lib.container.bare_metal import standalone_node_pool_flags as flags
from googlecloudsdk.command_lib.container.gkeonprem import constants
from googlecloudsdk.core import log
_EXAMPLES = """
To update a node pool named ``my-node-pool'' in a cluster named
``my-cluster'' managed in location ``us-west1'', run:
$ {command} my-node-pool --cluster=my-cluster --location=us-west1
"""
@base.Hidden
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Update a node pool in an Anthos standalone cluster on bare metal."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor):
"""Gathers commandline arguments for the update command.
Args:
parser: The argparse parser to add the flag to.
"""
parser.display_info.AddFormat(
bare_metal_constants.BARE_METAL_NODE_POOLS_FORMAT)
flags.AddNodePoolResourceArg(parser, 'to update')
node_pool_flags.AddValidationOnly(parser)
flags.AddAllowMissingUpdateNodePool(parser)
base.ASYNC_FLAG.AddToParser(parser)
flags.AddNodePoolConfig(parser, is_update=True)
flags.AddNodePoolDisplayName(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.
"""
node_pool_ref = args.CONCEPTS.node_pool.Parse()
client = apis.StandaloneNodePoolsClient()
operation = 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(
node_pool_ref,
'Node pool in Anthos standalone cluster on bare metal',
args.async_,
)
return operation_response