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,40 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 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.
"""Package for the sole-tenancy CLI commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class SoleTenancy(base.Group):
"""Read and manage Compute Engine sole-tenancy resources."""
SoleTenancy.category = base.INSTANCES_CATEGORY
SoleTenancy.detailed_help = {
'DESCRIPTION': """
Read and manage Compute Engine sole-tenancy resources.
For more information about sole-tenancy resources, see the
[sole-tenancy documentation](https://cloud.google.com/compute/docs/nodes/).
""",
}

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Package for the sole tenant node groups CLI commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class SoleTenancyNodeGroups(base.Group):
"""Read Compute Engine sole-tenancy node groups."""

View File

@@ -0,0 +1,62 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Add IAM policy binding to a Compute Engine node group.
description: |
Add an IAM policy binding to a Compute Engine node group.
examples: |
To add an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node group 'my-node-group' and zone 'ZONE', run:
$ {command} my-node-group --zone=ZONE --member='user:test-user@gmail.com' --role='roles/compute.admin'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: compute.nodeGroups
use_relative_name: false
api_version: v1
BETA:
api_version: beta
ALPHA:
api_version: alpha
iam:
set_iam_policy_request_path: zoneSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeNodeGroupsSetIamPolicyRequest
ALPHA:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
BETA:
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
arguments:
resource:
help_text: The node group for which to add IAM policy binding to.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_group
ALPHA:
help_text:
brief: Add IAM policy binding to a Compute Engine node group.
description: |
Add an IAM policy binding to the IAM policy of a Compute Engine node group. One binding consists of a member,
a role, and an optional condition.
examples: |
To add an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node group 'my-node-group' and zone 'ZONE', run:
$ {command} my-node-group --zone=ZONE --member='user:test-user@gmail.com' --role='roles/compute.admin'
To add an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/compute.admin' and the user 'test-user@gmail.com' with node group 'my-node-group' and zone 'ZONE', run:
$ {command} my-node-group --zone=ZONE --member='user:test-user@gmail.com' --role='roles/compute.admin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.

View File

@@ -0,0 +1,108 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Create node group command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils as compute_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import util
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Create(base.CreateCommand):
"""Create a Compute Engine node group."""
detailed_help = {
'brief': 'Create a Compute Engine node group.',
'EXAMPLES': """
To create a node group, run:
$ {command} my-node-group --node-template=example-template --target-size=4
""",
}
@staticmethod
def Args(parser):
flags.MakeNodeGroupArg().AddArgument(parser)
flags.AddCreateArgsToParser(parser)
flags.AddAutoscalingPolicyArgToParser(parser, required_mode=True)
flags.AddMaintenanceWindowArgToParser(parser)
flags.AddLocationHintArgToParser(parser)
flags.AddShareSettingArgToParser(parser)
flags.AddMaintenanceIntervalArgToParser(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
messages = holder.client.messages
node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args, holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
node_template_ref = util.ParseNodeTemplate(
holder.resources,
args.node_template,
project=node_group_ref.project,
region=compute_utils.ZoneNameToRegionName(node_group_ref.zone))
node_group = messages.NodeGroup(
name=node_group_ref.Name(),
description=args.description,
nodeTemplate=node_template_ref.SelfLink())
if hasattr(args, 'maintenance_policy'):
mapper = flags.GetMaintenancePolicyEnumMapper(messages)
maintenance_policy = mapper.GetEnumForChoice(args.maintenance_policy)
node_group.maintenancePolicy = maintenance_policy
if hasattr(args, 'maintenance_interval'):
mapper = flags.GetMaintenanceIntervalEnumMapper(messages)
maintenance_interval = mapper.GetEnumForChoice(args.maintenance_interval)
node_group.maintenanceInterval = maintenance_interval
if hasattr(args, 'autoscaler_mode') and args.autoscaler_mode:
if args.autoscaler_mode != 'off' and args.max_nodes is None:
raise exceptions.RequiredArgumentException('--max-nodes',
'--autoscaler-mode is on')
autoscaling_policy = util.BuildAutoscaling(args, messages)
node_group.autoscalingPolicy = autoscaling_policy
if args.maintenance_window_start_time:
node_group.maintenanceWindow = messages.NodeGroupMaintenanceWindow(
startTime=args.maintenance_window_start_time)
if hasattr(args, 'location_hint') and args.location_hint:
node_group.locationHint = args.location_hint
if args.share_setting:
node_group.shareSettings = util.BuildShareSettings(messages, args)
request = messages.ComputeNodeGroupsInsertRequest(
nodeGroup=node_group,
initialNodeCount=args.target_size,
project=node_group_ref.project,
zone=node_group_ref.zone)
service = holder.client.apitools_client.nodeGroups
return client.MakeRequests([(service, 'Insert', request)])[0]

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Delete node group command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete a Compute Engine node group."""
detailed_help = {
'brief': 'Delete a Compute Engine node group.',
'EXAMPLES': """
To delete a node group, run:
$ {command} my-node-group
"""
}
@staticmethod
def Args(parser):
flags.MakeNodeGroupArg().AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args, holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
console_io.PromptContinue(
'You are about to delete node group: [{}]'.format(
node_group_ref.Name()),
throw_if_unattended=True, cancel_on_no=True)
messages = holder.client.messages
request = messages.ComputeNodeGroupsDeleteRequest(
nodeGroup=node_group_ref.Name(),
project=node_group_ref.project,
zone=node_group_ref.zone)
service = holder.client.apitools_client.nodeGroups
return client.MakeRequests([(service, 'Delete', request)])

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Describe node group command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine node group."""
detailed_help = {
'brief': 'Describe a Compute Engine node group.',
'EXAMPLES': """
To describe a node group, run:
$ {command} my-node-group
"""
}
@staticmethod
def Args(parser):
flags.MakeNodeGroupArg().AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args, holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
request = messages.ComputeNodeGroupsGetRequest(
nodeGroup=node_group_ref.Name(),
project=node_group_ref.project,
zone=node_group_ref.zone)
service = holder.client.apitools_client.nodeGroups
return client.MakeRequests([(service, 'Get', request)])[0]

View File

@@ -0,0 +1,33 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM policy for a Compute Engine node group.
description: |
*{command}* displays the IAM policy associated with a
Compute Engine node group in a zone. If formatted as JSON,
the output can be edited and used as a policy file for
set-iam-policy. The output includes an "etag" field
identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given node group, run:
$ {command} my-node-group --zone=ZONE
request:
collection: compute.nodeGroups
api_version: v1
use_relative_name: false
BETA:
api_version: beta
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=optionsRequestedPolicyVersion
ALPHA:
api_version: alpha
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=optionsRequestedPolicyVersion
arguments:
resource:
help_text: The node group for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_group

View File

@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""List node groups command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA,
base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List Compute Engine node groups."""
@staticmethod
def Args(parser):
flags.AddListingShareSettingsArgToParser(parser)
def Run(self, args):
if args.share_settings:
args.GetDisplayInfo().AddTransforms({
'description': _TransformShareSettings,
})
args.GetDisplayInfo().AddFormat("""\
table(
name,
zone.basename(),
description,
nodeTemplate.basename(),
size:label=NODES,
shareSettings.description()
)""")
else:
args.GetDisplayInfo().AddTransforms({
'description': _IsShared,
})
args.GetDisplayInfo().AddFormat("""\
table(
name,
zone.basename(),
description,
nodeTemplate.basename(),
size:label=NODES,
shareSettings.description():label=SHARED
)""")
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseMultiScopeFlags(args, holder.resources)
list_implementation = lister.MultiScopeLister(
client, aggregation_service=client.apitools_client.nodeGroups)
return lister.Invoke(request_data, list_implementation)
def _IsShared(share_setting):
""""Transforms share settings to simple share settings information."""
if share_setting and share_setting['shareType'] != 'LOCAL':
return 'true'
return 'false'
def _TransformShareSettings(share_setting):
""""Transforms share settings to detailed share settings information."""
if not share_setting or share_setting['shareType'] == 'LOCAL':
return 'local'
elif share_setting['shareType'] == 'SPECIFIC_PROJECTS':
projects = share_setting[
'projectMap'] if 'projectMap' in share_setting else []
return 'specific_project:' + ','.join(sorted(projects))
elif share_setting['shareType'] == 'ORGANIZATION':
return 'org'
return ''
List.detailed_help = base_classes.GetRegionalListerHelp('node groups')

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""List nodes command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import request_helper
from googlecloudsdk.api_lib.compute import utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
class ListNodes(base.ListCommand):
"""List Compute Engine sole-tenant nodes present in a node group."""
detailed_help = {
'brief':
'List Compute Engine sole-tenant nodes present in a node'
'group.',
'EXAMPLES':
"""
To list sole-tenant nodes present in a node group, run:
$ {command} my-node-group
"""
}
@staticmethod
def _Flags(parser):
"""Adds the flags for this command.
Removes the URI flag since nodes don't have URIs.
Args:
parser: The argparse parser.
"""
base.ListCommand._Flags(parser)
base.URI_FLAG.RemoveFromParser(parser)
@staticmethod
def Args(parser):
parser.display_info.AddFormat(
'table(name, status, nodeType.basename(),'
'instances.map().basename().list(), serverId)')
flags.MakeNodeGroupArg().AddArgument(parser)
def Run(self, args):
"""Retrieves response with nodes in the node group."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
request = client.messages.ComputeNodeGroupsListNodesRequest(
nodeGroup=group_ref.Name(),
zone=group_ref.zone,
project=group_ref.project)
errors = []
results = list(
request_helper.MakeRequests(
requests=[(client.apitools_client.nodeGroups, 'ListNodes', request)
],
http=client.apitools_client.http,
batch_url=client.batch_url,
errors=errors))
if errors:
utils.RaiseToolException(errors)
return self.getItems(results)
def getItems(self, results):
for result in results:
for item in getattr(result, 'items'):
yield item

View File

@@ -0,0 +1,86 @@
# -*- 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.
"""Perform maintenance command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
from googlecloudsdk.core import log
from googlecloudsdk.core.util import times
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class PerformMaintenance(base.UpdateCommand):
"""Perform maintenance on nodes in a Compute Engine node group."""
detailed_help = {
'brief': 'Perform maintenance on nodes in a Compute Engine node group.',
'EXAMPLES': """
To perform maintenance on nodes in a node group, run:
$ {command} my-node-group --nodes=node-1,node-2 --start-time=2023-05-01T00:00:00.000-08:00
""",
}
@staticmethod
def Args(parser):
flags.MakeNodeGroupArg().AddArgument(parser)
flags.AddPerformMaintenanceNodesArgToParser(parser)
flags.AddPerformMaintenanceStartTimeArgToParser(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
messages = holder.client.messages
node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
perform_maintenance = messages.NodeGroupsPerformMaintenanceRequest(
nodes=args.nodes
)
if args.start_time:
perform_maintenance.startTime = times.FormatDateTime(args.start_time)
request = messages.ComputeNodeGroupsPerformMaintenanceRequest(
nodeGroupsPerformMaintenanceRequest=perform_maintenance,
nodeGroup=node_group_ref.Name(),
project=node_group_ref.project,
zone=node_group_ref.zone)
service = holder.client.apitools_client.nodeGroups
operation = service.PerformMaintenance(request)
operation_ref = holder.resources.Parse(
operation.selfLink, collection='compute.zoneOperations')
log.status.Print(
'Perform maintenance call in progress for nodes [{}] in node group'
' [{}]: {}'.format(
args.nodes, node_group_ref.Name(), operation_ref.SelfLink()
)
)
log.status.Print(
'Use [gcloud compute operations describe URI] to check the status of'
' the operation(s).'
)
return operation

View File

@@ -0,0 +1,62 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Remove IAM policy binding from a Compute Engine node group.
description: |
Remove an IAM policy binding from a Compute Engine node group.
examples: |
To remove an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node group 'my-node-group' and zone 'ZONE', run:
$ {command} my-node-group --zone=ZONE --member='user:test-user@gmail.com' --role='roles/compute.admin'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: compute.nodeGroups
use_relative_name: false
api_version: v1
BETA:
api_version: beta
ALPHA:
api_version: alpha
iam:
set_iam_policy_request_path: zoneSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeNodeGroupsSetIamPolicyRequest
ALPHA:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
BETA:
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
arguments:
resource:
help_text: The node group for which to remove IAM policy binding from.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_group
ALPHA:
help_text:
brief: Remove IAM policy binding from a Compute Engine node group.
description: |
Remove an IAM policy binding from the IAM policy of a Compute Engine node group. One binding consists of a member,
a role, and an optional condition.
examples: |
To remove an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node group 'my-node-group' and zone 'ZONE', run:
$ {command} my-node-group --zone=ZONE --member='user:test-user@gmail.com' --role='roles/compute.admin'
To remove an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/compute.admin' and the user 'test-user@gmail.com' with node group 'my-node-group' and zone 'ZONE', run:
$ {command} my-node-group --zone=ZONE --member='user:test-user@gmail.com' --role='roles/compute.admin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.

View File

@@ -0,0 +1,37 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Set the IAM policy for a Compute Engine node group.
description: |
Sets the IAM policy for the given node group as defined in a JSON or YAML file.
examples: |
The following command will read am IAM policy defined in a JSON file
'policy.json' and set it for the node group `my-node-group`:
$ {command} my-node-group --zone=ZONE policy.json
See https://cloud.google.com/iam/docs/managing-policies for details of the
policy file format and contents.
request:
collection: compute.nodeGroups
api_version: v1
use_relative_name: false
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=zoneSetPolicyRequest.policy.version
BETA:
api_version: beta
ALPHA:
api_version: alpha
iam:
set_iam_policy_request_path: zoneSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeNodeGroupsSetIamPolicyRequest
arguments:
resource:
help_text: The node group to set the IAM policy for.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_group

View File

@@ -0,0 +1,85 @@
# -*- 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.
"""Simulate maintenance event command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute.operations import poller
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
from googlecloudsdk.core import log
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class SimulateMaintenanceEvent(base.UpdateCommand):
"""Simulate maintenance of a Compute Engine node group."""
detailed_help = {
'brief':
'Simulate maintenance of a Compute Engine node group.',
'EXAMPLES':
"""
To simulate maintenance of a node group, run:
$ {command} my-node-group --nodes=example-nodes
""",
}
@staticmethod
def Args(parser):
flags.MakeNodeGroupArg().AddArgument(parser)
flags.AddSimulateMaintenanceEventNodesArgToParser(parser)
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
messages = holder.client.messages
node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
request = messages.ComputeNodeGroupsSimulateMaintenanceEventRequest(
nodeGroupsSimulateMaintenanceEventRequest=messages
.NodeGroupsSimulateMaintenanceEventRequest(nodes=args.nodes),
nodeGroup=node_group_ref.Name(),
project=node_group_ref.project,
zone=node_group_ref.zone)
service = holder.client.apitools_client.nodeGroups
operation = service.SimulateMaintenanceEvent(request)
operation_ref = holder.resources.Parse(
operation.selfLink, collection='compute.zoneOperations')
if args.async_:
log.status.Print(
'Simulation Maintenance Event in progress for node group [{}]: {}'
.format(node_group_ref.Name(), operation_ref.SelfLink()))
log.status.Print('Use [gcloud compute operations describe URI] '
'to check the status of the operation(s).')
return operation
operation_poller = poller.Poller(service)
nodes_str = ','.join(map(str, args.nodes or []))
return waiter.WaitFor(
operation_poller, operation_ref,
'Simulation Maintenance Event for nodes [{}] in [{}].'.format(
nodes_str, node_group_ref.Name()))

View File

@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Update node group command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute.sole_tenancy import node_groups
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_groups import flags
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Compute Engine node group."""
detailed_help = {
'brief':
'Update a Compute Engine node group.',
'EXAMPLES':
"""
To update a node group to have two more nodes, run:
$ {command} my-node-group --add-nodes=2
"""
}
@staticmethod
def Args(parser):
flags.MakeNodeGroupArg().AddArgument(parser)
flags.AddUpdateArgsToParser(parser)
flags.AddAutoscalingPolicyArgToParser(parser)
flags.AddShareSettingArgToParser(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
messages = holder.client.messages
groups_client = node_groups.NodeGroupsClient(holder.client.apitools_client,
messages, holder.resources)
node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
autoscaling_policy = (hasattr(args, 'autoscaler_mode') and args.IsSpecified('autoscaler_mode')) or \
(hasattr(args, 'min_nodes') and args.IsSpecified('min_nodes')) or \
(hasattr(args, 'max_nodes') and args.IsSpecified('max_nodes'))
share_setting = (
args.IsSpecified('share_setting') or args.IsSpecified('share_with'))
return groups_client.Update(
node_group_ref,
node_template=args.node_template,
additional_node_count=args.add_nodes,
delete_nodes=args.delete_nodes,
autoscaling_policy_args=args if autoscaling_policy else None,
share_setting_args=args if share_setting else None)

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Package for the sole tenant node templates CLI commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class SoleTenancyNodeTemplates(base.Group):
"""Read and manage Compute Engine sole-tenancy node templates.
Node templates are used to create the nodes in node groups. Nodes are
Compute Engine servers that are dedicated to your workload. Node templates
define either the node type or the requirements for a node in terms of
vCPU, memory, and localSSD.
"""

View File

@@ -0,0 +1,62 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Add IAM policy binding to a Compute Engine node template.
description: |
Add an IAM policy binding to a Compute Engine node template.
examples: |
To add an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node template 'my-node-template' and region 'REGION', run:
$ {command} my-node-template --region=REGION --member='user:test-user@gmail.com' --role='roles/compute.admin'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: compute.nodeTemplates
use_relative_name: false
api_version: v1
BETA:
api_version: beta
ALPHA:
api_version: alpha
iam:
set_iam_policy_request_path: regionSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeNodeTemplatesSetIamPolicyRequest
ALPHA:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
BETA:
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
arguments:
resource:
help_text: The node template for which to add IAM policy binding to.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_template
ALPHA:
help_text:
brief: Add IAM policy binding to a Compute Engine node template.
description: |
Add an IAM policy binding to the IAM policy of a Compute Engine node template. One binding consists of a member,
a role, and an optional condition.
examples: |
To add an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node template 'my-node-template' and region 'REGION', run:
$ {command} my-node-template --region=REGION --member='user:test-user@gmail.com' --role='roles/compute.admin'
To add an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/compute.admin' and the user 'test-user@gmail.com' with node template 'my-node-template' and region 'REGION', run:
$ {command} my-node-template --region=REGION --member='user:test-user@gmail.com' --role='roles/compute.admin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.

View File

@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Create node template command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_templates import flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_templates import util
def _CommonArgs(parser, api_version):
"""Common arguments for each release track."""
messages = apis.GetMessagesModule('compute', api_version)
flags.MakeNodeTemplateArg().AddArgument(parser)
flags.AddCreateArgsToParser(parser)
flags.GetServerBindingMapperFlag(messages).choice_arg.AddToParser(parser)
flags.AddAcceleratorArgs(parser)
flags.AddDiskArgToParser(parser)
def _Run(args, track):
"""Creates a node template."""
holder = base_classes.ComputeApiHolder(track)
client = holder.client
node_template_ref = flags.MakeNodeTemplateArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
node_template = util.CreateNodeTemplate(
node_template_ref,
args,
messages=messages)
request = messages.ComputeNodeTemplatesInsertRequest(
nodeTemplate=node_template,
project=node_template_ref.project,
region=node_template_ref.region)
service = holder.client.apitools_client.nodeTemplates
return client.MakeRequests([(service, 'Insert', request)])[0]
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Compute Engine node template."""
detailed_help = {
'brief':
'Create a Compute Engine node template.',
'EXAMPLES':
"""
To create a node template of type `n1-node-96-624`, run:
$ {command} my-node-template --node-type=n1-node-96-624
"""
}
@staticmethod
def Args(parser):
_CommonArgs(parser, 'v1')
flags.AddCpuOvercommitTypeFlag(parser)
def Run(self, args):
return _Run(
args,
self.ReleaseTrack())
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(Create):
"""Create a Compute Engine node template."""
@staticmethod
def Args(parser):
_CommonArgs(parser, 'beta')
flags.AddCpuOvercommitTypeFlag(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(CreateBeta):
"""Create a Compute Engine node template."""
@staticmethod
def Args(parser):
_CommonArgs(parser, 'alpha')
flags.AddCpuOvercommitTypeFlag(parser)

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Delete node template command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_templates import flags
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete a Compute Engine node template."""
detailed_help = {
'brief': 'Delete a Compute Engine node template.',
'EXAMPLES': """
To delete a node template, run:
$ {command} my-node-template
"""
}
@staticmethod
def Args(parser):
flags.MakeNodeTemplateArg().AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
node_template_ref = flags.MakeNodeTemplateArg().ResolveAsResource(
args, holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
console_io.PromptContinue(
'You are about to delete node template: [{}]'.format(
node_template_ref.Name()),
throw_if_unattended=True, cancel_on_no=True)
messages = holder.client.messages
request = messages.ComputeNodeTemplatesDeleteRequest(
nodeTemplate=node_template_ref.Name(),
project=node_template_ref.project,
region=node_template_ref.region)
service = holder.client.apitools_client.nodeTemplates
return client.MakeRequests([(service, 'Delete', request)])

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Describe node template command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_templates import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine node template."""
detailed_help = {
'brief': 'Describe a Compute Engine node template.',
'EXAMPLES': """
To describe a node template, run:
$ {command} my-node-template
"""
}
@staticmethod
def Args(parser):
flags.MakeNodeTemplateArg().AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
node_template_ref = flags.MakeNodeTemplateArg().ResolveAsResource(
args, holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
request = messages.ComputeNodeTemplatesGetRequest(
nodeTemplate=node_template_ref.Name(),
project=node_template_ref.project,
region=node_template_ref.region)
service = holder.client.apitools_client.nodeTemplates
return client.MakeRequests([(service, 'Get', request)])[0]

View File

@@ -0,0 +1,33 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM Policy for a Compute Engine node template.
description: |
*{command}* displays the IAM policy associated with a
Compute Engine node template. If formatted as JSON,
the output can be edited and used as a policy file for
set-iam-policy. The output includes an "etag" field
identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given node template, run:
$ {command} my-node-template --region=REGION
request:
collection: compute.nodeTemplates
api_version: v1
use_relative_name: false
BETA:
api_version: beta
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=optionsRequestedPolicyVersion
ALPHA:
api_version: alpha
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=optionsRequestedPolicyVersion
arguments:
resource:
help_text: The node template for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_template

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""List node templates command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA,
base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""List Compute Engine node templates."""
detailed_help = {
'brief': 'List Compute Engine node templates.',
'EXAMPLES': """
To list node templates, run:
$ {command}
"""
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat("""\
table(
name,
region.basename(),
description,
nodeType,
nodeAffinityLabels.list(separator='\n'),
status
)""")
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseMultiScopeFlags(args, holder.resources)
list_implementation = lister.MultiScopeLister(
client, aggregation_service=client.apitools_client.nodeTemplates)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetRegionalListerHelp('node templates')

View File

@@ -0,0 +1,62 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Remove IAM policy binding from a Compute Engine node template.
description: |
Remove an IAM policy binding from a Compute Engine node template.
examples: |
To remove an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node template 'my-node-template' and region 'REGION', run:
$ {command} my-node-template --region=REGION --member='user:test-user@gmail.com' --role='roles/compute.admin'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: compute.nodeTemplates
use_relative_name: false
api_version: v1
BETA:
api_version: beta
ALPHA:
api_version: alpha
iam:
set_iam_policy_request_path: regionSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeNodeTemplatesSetIamPolicyRequest
ALPHA:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
BETA:
policy_version: 3
get_iam_policy_version_path: optionsRequestedPolicyVersion
arguments:
resource:
help_text: The node template for which to remove IAM policy binding from.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_template
ALPHA:
help_text:
brief: Remove IAM policy binding from a Compute Engine node template.
description: |
Remove an IAM policy binding from the IAM policy of a Compute Engine node template. One binding consists of a member,
a role, and an optional condition.
examples: |
To remove an IAM policy binding for the role of 'roles/compute.admin' for the user 'test-user@gmail.com'
with node template 'my-node-template' and region 'REGION', run:
$ {command} my-node-template --region=REGION --member='user:test-user@gmail.com' --role='roles/compute.admin'
To remove an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/compute.admin' and the user 'test-user@gmail.com' with node template 'my-node-template' and region 'REGION', run:
$ {command} my-node-template --region=REGION --member='user:test-user@gmail.com' --role='roles/compute.admin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.

View File

@@ -0,0 +1,37 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Set the IAM policy for a Compute Engine node template.
description: |
Sets the IAM policy for the given node template as defined in a JSON or YAML file.
examples: |
The following command will read am IAM policy defined in a JSON file
'policy.json' and set it for the node template `my-node-template`:
$ {command} my-node-template --region=REGION policy.json
See https://cloud.google.com/iam/docs/managing-policies for details of the
policy file format and contents.
request:
collection: compute.nodeTemplates
api_version: v1
use_relative_name: false
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=regionSetPolicyRequest.policy.version
BETA:
api_version: beta
ALPHA:
api_version: alpha
iam:
set_iam_policy_request_path: regionSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeNodeTemplatesSetIamPolicyRequest
arguments:
resource:
help_text: The node template to set the IAM policy for.
spec: !REF googlecloudsdk.command_lib.compute.resources:node_template

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Package for the sole tenant node types CLI commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class SoleTenancyNodeTypes(base.Group):
"""Read Compute Engine sole-tenancy node types.
Node types are the types of dedicated Compute Engine servers that
are used for nodes in node groups. Node types will differ in
the amount of vCPU, Memory, and local SSD space.
"""

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""Describe node type command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.sole_tenancy.node_types import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine node type."""
detailed_help = {
'brief': 'Describe a Compute Engine node type.',
'EXAMPLES': """
To describe a node type, run:
$ {command} example-node-type
"""
}
@staticmethod
def Args(parser):
flags.MakeNodeTypeArg().AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
node_type_ref = flags.MakeNodeTypeArg().ResolveAsResource(
args, holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
request = messages.ComputeNodeTypesGetRequest(
nodeType=node_type_ref.Name(),
project=node_type_ref.project,
zone=node_type_ref.zone)
service = holder.client.apitools_client.nodeTypes
return client.MakeRequests([(service, 'Get', request)])[0]

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""List node types command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA,
base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List Compute Engine node types."""
detailed_help = {
'brief':
'List Compute Engine node types.',
'EXAMPLES':
"""
To list node types, run:
$ {command}
"""
}
@staticmethod
def Args(parser):
parser.display_info.AddFormat("""\
table(
name,
zone.basename(),
guestCpus:label=CPUs,
memoryMb,
maxVms,
deprecated.state:label=DEPRECATED
)""")
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseMultiScopeFlags(args, holder.resources)
list_implementation = lister.MultiScopeLister(
client,
aggregation_service=client.apitools_client.nodeTypes)
return list(lister.Invoke(request_data, list_implementation))
List.detailed_help = base_classes.GetZonalListerHelp('node types')