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,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""The command group for os-config patch-jobs CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class OsconfigPatchJobs(base.Group):
"""Manage OS patches for Compute Engine VMs."""

View File

@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Implements command to cancel a given active OS patch job."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute.os_config import utils as osconfig_api_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.os_config import resource_args
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class Cancel(base.Command):
"""Cancel a specific OS patch job which must currently be active.
## EXAMPLES
To cancel the patch job `job1`, run:
$ {command} job1
"""
@staticmethod
def Args(parser):
resource_args.AddPatchJobResourceArg(parser, 'to cancel.')
def Run(self, args):
patch_job_ref = args.CONCEPTS.patch_job.Parse()
release_track = self.ReleaseTrack()
client = osconfig_api_utils.GetClientInstance(release_track)
messages = osconfig_api_utils.GetClientMessages(release_track)
request = messages.OsconfigProjectsPatchJobsCancelRequest(
cancelPatchJobRequest=None,
name=patch_job_ref.RelativeName(),
)
return client.projects_patchJobs.Cancel(request)

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Implements command to describe a given OS patch job."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute.os_config import utils as osconfig_api_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.os_config import resource_args
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describe a specified OS patch job.
## EXAMPLES
To check the status of the patch job `job1`, run:
$ {command} job1
"""
@staticmethod
def Args(parser):
resource_args.AddPatchJobResourceArg(parser, 'to describe.')
def Run(self, args):
patch_job_ref = args.CONCEPTS.patch_job.Parse()
release_track = self.ReleaseTrack()
client = osconfig_api_utils.GetClientInstance(release_track)
messages = osconfig_api_utils.GetClientMessages(release_track)
request = messages.OsconfigProjectsPatchJobsGetRequest(
name=patch_job_ref.RelativeName())
return client.projects_patchJobs.Get(request)

View File

@@ -0,0 +1,169 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Implements command to list ongoing and completed patch jobs."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.compute.os_config import utils as osconfig_api_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.os_config import utils as osconfig_command_utils
from googlecloudsdk.core import properties
_DEFAULT_LIMIT = 10
def _TransformPatchJobDisplayName(resource):
"""Returns the display name of a patch job."""
max_len = 15 # Show only the first 15 characters if display name is long.
if resource.get('displayName', ''):
name = resource['displayName']
elif resource.get('patchDeployment', ''):
name = osconfig_command_utils.GetResourceName(resource['patchDeployment'])
else:
name = ''
return (name[:max_len] + '..') if len(name) > max_len else name
def _TransformPatchJobDescription(resource):
max_len = 30 # Show only the first 30 characters if description is long.
description = resource.get('description', '')
return (description[:max_len] +
'..') if len(description) > max_len else description
def _TransformState(resource):
state = resource.get('state', '')
if 'instanceDetailsSummary' in resource:
num_instances_pending_reboot = int(resource['instanceDetailsSummary'].get(
'instancesSucceededRebootRequired', '0'))
if state == 'SUCCEEDED' and num_instances_pending_reboot > 0:
return 'SUCCEEDED_INSTANCES_PENDING_REBOOT'
return state
def _TransformNumInstances(resource):
"""Sums up number of instances in a patch job."""
if 'instanceDetailsSummary' not in resource:
return None
instance_details_summary = resource['instanceDetailsSummary']
num_instances = 0
for status in instance_details_summary:
num_instances += int(instance_details_summary.get(status, 0))
return num_instances
def _MakeGetUriFunc(registry):
"""Returns a transformation function from a patch job resource to an URI."""
def UriFunc(resource):
ref = registry.Parse(
resource.name,
params={
'projects': properties.VALUES.core.project.GetOrFail,
'patchJobs': resource.name
},
collection='osconfig.projects.patchJobs')
return ref.SelfLink()
return UriFunc
def _Args(parser, release_track):
"""Parses input flags and sets up output formats."""
base.LIMIT_FLAG.SetDefault(parser, _DEFAULT_LIMIT)
parser.display_info.AddFormat("""
table(
name.basename():label=ID,
display_name():label=NAME,
description(),
create_time,
update_time,
state(),
targeted_instances()
)
""")
parser.display_info.AddTransforms({
'display_name': _TransformPatchJobDisplayName,
'description': _TransformPatchJobDescription,
'state': _TransformState,
'targeted_instances': _TransformNumInstances,
})
registry = osconfig_api_utils.GetRegistry(release_track)
parser.display_info.AddUriFunc(_MakeGetUriFunc(registry))
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List ongoing and completed patch jobs.
## EXAMPLES
To list patch jobs in the current project, run:
$ {command}
"""
@staticmethod
def Args(parser):
_Args(parser, base.ReleaseTrack.GA)
def Run(self, args):
project = properties.VALUES.core.project.GetOrFail()
release_track = self.ReleaseTrack()
client = osconfig_api_utils.GetClientInstance(release_track)
messages = osconfig_api_utils.GetClientMessages(release_track)
request = messages.OsconfigProjectsPatchJobsListRequest(
pageSize=args.page_size,
parent=osconfig_command_utils.GetProjectUriPath(project))
return list_pager.YieldFromList(
client.projects_patchJobs,
request,
limit=args.limit,
batch_size=osconfig_command_utils.GetListBatchSize(args),
field='patchJobs',
batch_size_attribute='pageSize',
)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class ListBeta(List):
"""List ongoing and completed patch jobs.
## EXAMPLES
To list patch jobs in the current project, run:
$ {command}
"""
@staticmethod
def Args(parser):
_Args(parser, base.ReleaseTrack.BETA)

View File

@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Implements command to list the instance details for an OS patch job."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.compute.os_config import utils as osconfig_api_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.os_config import resource_args
from googlecloudsdk.core.resource import resource_projector
def _TransformFailureReason(resource):
max_len = 80 # Show the first 80 characters if failure reason is long.
message = resource.get('failureReason', '')
return (message[:max_len] + '..') if len(message) > max_len else message
def _PostProcessListResult(results):
# Inject a "zone" field into the output resources for easy filtering.
results_json = resource_projector.MakeSerializable(results)
for result in results_json:
result['zone'] = result['name'].split('/')[3]
return results_json
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class ListInstanceDetails(base.ListCommand):
"""List the instance details for an OS patch job.
## EXAMPLES
To list the instance details for each instance in the patch job `job1`, run:
$ {command} job1
"""
@staticmethod
def Args(parser):
base.URI_FLAG.RemoveFromParser(parser) # InstanceDetails have no URI.
resource_args.AddPatchJobResourceArg(parser, 'to list instance details.')
parser.display_info.AddFormat("""
table(
name.basename(),
zone,
state,
failure_reason()
)
""")
parser.display_info.AddTransforms(
{'failure_reason': _TransformFailureReason})
def Run(self, args):
patch_job_ref = args.CONCEPTS.patch_job.Parse()
release_track = self.ReleaseTrack()
client = osconfig_api_utils.GetClientInstance(release_track)
messages = osconfig_api_utils.GetClientMessages(release_track)
request = messages.OsconfigProjectsPatchJobsInstanceDetailsListRequest(
pageSize=args.page_size, parent=patch_job_ref.RelativeName())
results = list(
list_pager.YieldFromList(
client.projects_patchJobs_instanceDetails,
request,
limit=args.limit,
batch_size=args.page_size,
field='patchJobInstanceDetails',
batch_size_attribute='pageSize'),)
return _PostProcessListResult(results)