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,14 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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.

View File

@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for describe Memorystore Memcache instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import six
def FormatResponse(response, _):
"""Hook to modify gcloud describe output for maintenance windows."""
modified_response = {}
if response.authorizedNetwork:
modified_response['authorizedNetwork'] = response.authorizedNetwork
if response.createTime:
modified_response['createTime'] = response.createTime
if response.discoveryEndpoint:
modified_response['discoveryEndpoint'] = response.discoveryEndpoint
if response.displayName:
modified_response['displayName'] = response.displayName
if response.maintenanceSchedule:
modified_response['maintenanceSchedule'] = response.maintenanceSchedule
if response.memcacheFullVersion:
modified_response['memcacheFullVersion'] = response.memcacheFullVersion
if response.memcacheNodes:
modified_response['memcacheNodes'] = response.memcacheNodes
if response.memcacheVersion:
modified_response['memcacheVersion'] = response.memcacheVersion
if response.name:
modified_response['name'] = response.name
if response.nodeConfig:
modified_response['nodeConfig'] = response.nodeConfig
if response.nodeCount:
modified_response['nodeCount'] = response.nodeCount
if response.parameters:
modified_response['parameters'] = response.parameters
if response.state:
modified_response['state'] = response.state
if response.updateTime:
modified_response['updateTime'] = response.updateTime
if response.zones:
modified_response['zones'] = response.zones
if response.tags:
modified_response['tags'] = response.tags
if response.maintenancePolicy:
modified_mw_policy = {}
modified_mw_policy['createTime'] = response.maintenancePolicy.createTime
modified_mw_policy['updateTime'] = response.maintenancePolicy.updateTime
mwlist = response.maintenancePolicy.weeklyMaintenanceWindow
modified_mwlist = []
for mw in mwlist:
item = {}
# convert seconds to minutes
duration_secs = int(mw.duration[:-1])
duration_mins = int(duration_secs / 60)
item['day'] = mw.day
item['hour'] = mw.startTime.hours
item['duration'] = six.text_type(duration_mins) + ' minutes'
modified_mwlist.append(item)
modified_mw_policy['maintenanceWindow'] = modified_mwlist
modified_response['maintenancePolicy'] = modified_mw_policy
if response.satisfiesPzs is not None:
modified_response['satisfiesPzs'] = response.satisfiesPzs
if response.satisfiesPzi is not None:
modified_response['satisfiesPzi'] = response.satisfiesPzi
return modified_response

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for reschedule Memcache instances maintenance window."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
class Error(Exception):
"""Exceptions for this module."""
class NoScheduleTimeSpecifiedError(Error):
"""Error for calling update command with no args that represent fields."""
def CheckSpecificTimeField(unused_instance_ref, args, patch_request):
"""Hook to check specific time field of the request."""
if args.IsSpecified('reschedule_type'):
if args.reschedule_type.lower() == 'specific-time':
if args.IsSpecified('schedule_time'):
return patch_request
else:
raise NoScheduleTimeSpecifiedError('Must specify schedule time')
return patch_request

View File

@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google Inc. 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.
"""Utilities for `gcloud memcache instances update` commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
from googlecloudsdk.api_lib import memcache
def ChooseUpdateMethod(unused_ref, args):
if args.IsSpecified('parameters'):
return 'updateParameters'
return 'patch'
def AddFieldToUpdateMask(update_mask, field):
if field not in update_mask:
update_mask.append(field)
def ModifyMaintenanceMask(unused_ref, args, req):
"""Update patch mask for maintenancePolicy.
Args:
unused_ref: The field resource reference.
args: The parsed arg namespace.
req: The auto-generated patch request.
Returns:
FirestoreProjectsDatabasesCollectionGroupsFieldsPatchRequest
"""
policy_is_updated = (
hasattr(req, 'instance') and
hasattr(req.instance, 'maintenancePolicy') and
req.instance.maintenancePolicy)
# By default the update mask has the full path that was update
# ie maintenancePolicy.weeklyMaintenanceWindow.day
if args.IsSpecified('maintenance_window_any') or policy_is_updated:
policy = 'maintenancePolicy'
mask = list(filter(
lambda m: m and policy not in m, req.updateMask.split(',')))
AddFieldToUpdateMask(mask, policy)
req.updateMask = ','.join(mask)
return req
# TODO(b/261326299): This hook is needed because the modify_method_hook does not
# determine the message until runtime. Update yaml translator to be able to map
# args to api fields when there is a dynamic method
def ModifyParams(ref, args, req):
"""Update patch request to include parameters.
Args:
ref: The field resource reference.
args: The parsed arg namespace.
req: The auto-generated patch request.
Returns:
FirestoreProjectsDatabasesCollectionGroupsFieldsPatchRequest
"""
if args.IsSpecified('parameters'):
messages = memcache.Messages(ref.GetCollectionInfo().api_version)
params = encoding.DictToMessage(args.parameters,
messages.MemcacheParameters.ParamsValue)
parameters = messages.MemcacheParameters(params=params)
param_req = messages.UpdateParametersRequest(
updateMask='params', parameters=parameters)
req.updateParametersRequest = param_req
return req
def _GetMaintenancePolicy(message_module):
"""Returns a maintenance policy of the appropriate version."""
if hasattr(message_module, 'GoogleCloudMemcacheV1beta2MaintenancePolicy'):
return message_module.GoogleCloudMemcacheV1beta2MaintenancePolicy()
elif hasattr(message_module, 'GoogleCloudMemcacheV1MaintenancePolicy'):
return message_module.GoogleCloudMemcacheV1MaintenancePolicy()
raise AttributeError('No MaintenancePolicy found for version V1 or V1beta2.')

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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.
"""Utilities for `gcloud memcache instances` commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
import six
MEMCACHE_EXTENDED_OPTIONS = ('track-sizes', 'watcher-logbuf-size',
'worker-logbuf-size', 'lru-crawler',
'idle-timeout', 'lru-maintainer', 'maxconns-fast',
'hash-algorithm')
class Error(Exception):
"""Exceptions for this module."""
class InvalidTimeOfDayError(Error):
"""Error for passing invalid time of day."""
def CheckMaintenanceWindowStartTimeField(maintenance_window_start_time):
if maintenance_window_start_time < 0 or maintenance_window_start_time > 23:
raise InvalidTimeOfDayError(
'A valid time of day must be specified (0, 23) hours.'
)
return maintenance_window_start_time
def ConvertDurationToJsonFormat(maintenance_window_duration):
duration_in_seconds = maintenance_window_duration * 3600
return six.text_type(duration_in_seconds) + 's'
def NodeMemory(value):
"""Declarative command argument type for node-memory flag."""
size = arg_parsers.BinarySize(
suggested_binary_size_scales=['MB', 'GB'], default_unit='MB')
return int(size(value) / 1024 / 1024)
def Parameters(value):
"""Declarative command argument type for parameters flag."""
return arg_parsers.ArgDict(key_type=_FormatExtendedOptions)(value)
def _FormatExtendedOptions(key):
"""Replaces dash with underscore for extended options parameters."""
if key in MEMCACHE_EXTENDED_OPTIONS:
return key.replace('-', '_')
return key

View File

@@ -0,0 +1,45 @@
project:
name: project
collection: memcache.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: The project name.
property: core/project
region:
name: region
collection: memcache.projects.locations
attributes:
- &region
parameter_name: locationsId
attribute_name: region
help: |
The name of the Memcached region of the {resource}. Overrides the default
memcache/region property value for this command invocation.
property: memcache/region
disable_auto_completers: false
instance:
name: instance
collection: memcache.projects.locations.instances
request_id_field: instanceId
attributes:
- *region
- &instance
parameter_name: instancesId
attribute_name: instance
help: The name of the Memcached instance.
disable_auto_completers: false
operation:
name: operation
collection: memcache.projects.locations.operations
attributes:
- *region
- &operation
parameter_name: operationsId
attribute_name: operation
help: The name of the Memcached operation.
disable_auto_completers: false