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,36 @@
# -*- 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 for Cloud Monitoring snoozes."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Snoozes(base.Group):
"""Manage Cloud Monitoring snoozes."""
detailed_help = {
'DESCRIPTION': """\
Manage Monitoring snoozes.
More information can be found here:
https://cloud.google.com/monitoring/api/v3/
"""
}

View File

@@ -0,0 +1,92 @@
# -*- 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.
"""`gcloud monitoring snoozes cancel` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import snoozes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.monitoring import resource_args
from googlecloudsdk.command_lib.monitoring import util
from googlecloudsdk.core import log
from googlecloudsdk.core.util import times
class Cancel(base.UpdateCommand):
"""Cancels a snooze."""
detailed_help = {
'DESCRIPTION': """\
Cancel a snooze.
If the start time is in the future, then
this command is equivalent to:
* update --start-time="+PT1S" --end-time="+PT1S
Otherwise, if the start time is past and the ending time is in the
future, then this command is equivalent to:
* update --end-time="+PT1S
For information about the JSON/YAML format of a snooze:
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.snoozes
""",
'EXAMPLES': """\
To cancel a snooze, run:
$ {command} MY-SNOOZE
To cancel a snooze contained within a specific project, run:
$ {command} MY-SNOOZE --project=MY-PROJECT
To cancel a snooze with a fully qualified snooze ID, run:
$ {command} projects/MY-PROJECT/snoozes/MY-SNOOZE
"""
}
@staticmethod
def Args(parser):
resources = [
resource_args.CreateSnoozeResourceArg('to be canceled.')]
resource_args.AddResourceArgs(parser, resources)
def Run(self, args):
client = snoozes.SnoozeClient()
messages = client.messages
snooze_ref = args.CONCEPTS.snooze.Parse()
# TODO(b/271427290): Replace 500 with 404 in api
snooze = client.Get(snooze_ref)
start_time = times.ParseDateTime(snooze.interval.startTime)
end_time = times.ParseDateTime('+PT1S')
if start_time > times.Now():
start_time = end_time
util.ModifySnooze(
snooze,
messages,
start_time=start_time,
end_time=end_time)
result = client.Update(snooze_ref, snooze, None)
log.UpdatedResource(result.name, 'snooze')
return result

View File

@@ -0,0 +1,84 @@
# -*- 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.
"""`gcloud monitoring snoozes create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import snoozes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.monitoring import flags
from googlecloudsdk.command_lib.monitoring import util
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
@base.DefaultUniverseOnly
class Create(base.CreateCommand):
"""Create a new snooze."""
detailed_help = {
'DESCRIPTION': """\
Creates a new snooze. A snooze can be specified as a JSON/YAML value
passed in as a file through the `--snooze-from-file` flag. A snooze
can also be specified through command line flags. If a snooze is
specified through `--snooze-from-file`, and additional flags are
supplied, the flags will override the snooze's settings.
For information about the JSON/YAML format of a snooze:
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.snoozes
""",
'EXAMPLES': """\
To create a snooze with command-line options, run:
$ {command} --criteria-policies=LIST_OF_POLICIES
--criteria-filter=FILTER
--display-name=DISPLAY_NAME --start-time=START_TIME
--end-time=END_TIME
To create a snooze with a file, run:
$ {command} --snooze-from-file=MY-FILE
Sample contents of MY-FILE:
criteria:
policies:
- projects/MY-PROJECT/alertPolicies/MY-POLICY
filter: 'resource.labels.zone="us-central1-a" AND resource.labels.instance_id="1234567890"'
interval:
startTime: '2024-03-01T08:00:00Z'
endTime: '2024-03-08T04:59:59.500Z'
displayName: New Snooze
""",
}
@staticmethod
def Args(parser):
flags.AddFileMessageFlag(parser, 'snooze')
flags.AddSnoozeSettingsFlags(parser)
def Run(self, args):
client = snoozes.SnoozeClient()
snooze = util.CreateSnoozeFromArgs(args, client.messages)
project_ref = (
projects_util.ParseProject(properties.VALUES.core.project.Get()))
result = client.Create(project_ref, snooze)
log.CreatedResource(result.name, 'snooze')
return result

View File

@@ -0,0 +1,61 @@
# -*- 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.
"""`gcloud monitoring snoozes describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import snoozes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.monitoring import resource_args
class Describe(base.DescribeCommand):
"""Describe a snooze."""
detailed_help = {
'EXAMPLES': """\
To describe a snooze, run:
$ {command} MY-SNOOZE
To describe a snooze in JSON, run:
$ {command} MY-SNOOZE --format=json
To describe a snooze contained within a specific project, run:
$ {command} MY-SNOOZE --project=MY-PROJECT
To describe a snooze with a fully qualified snooze ID, run:
$ {command} projects/MY-PROJECT/snoozes/MY-SNOOZE
"""
}
@staticmethod
def Args(parser):
resources = [
resource_args.CreateSnoozeResourceArg('to be described.')]
resource_args.AddResourceArgs(parser, resources)
def Run(self, args):
client = snoozes.SnoozeClient()
snooze_ref = args.CONCEPTS.snooze.Parse()
# TODO(b/271427290): Replace 500 with 404 in api
result = client.Get(snooze_ref)
return result

View File

@@ -0,0 +1,36 @@
- help_text:
brief: List snoozes.
description: List snoozes.
examples: |
To order your results first by the snooze's display name and then the end time:
$ {command} --sort-by=display_name,interval.end_time
To order your results in reverse order, you can add '~' in front of the field name:
$ {command} --sort-by="~display_name"
To return results with expired snoozes only:
$ {command} --filter="interval.end_time<+PT1S"
To return results whose display name contain the word 'cloud':
$ {command} --filter="display_name:(cloud)"
More information can be found at
https://cloud.google.com/sdk/gcloud/reference/topic/filters
request:
collection: monitoring.projects.snoozes
response:
id_field: name
arguments:
resource:
help_text: The Cloud Monitoring Workspace from which to list snoozes from.
spec: !REF googlecloudsdk.command_lib.monitoring.resources:project
output:
format: yaml

View File

@@ -0,0 +1,133 @@
# -*- 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.
"""`gcloud monitoring snoozes update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import snoozes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.monitoring import flags
from googlecloudsdk.command_lib.monitoring import resource_args
from googlecloudsdk.command_lib.monitoring import util
from googlecloudsdk.core import log
class Update(base.UpdateCommand):
"""Updates a snooze."""
detailed_help = {
'DESCRIPTION': """\
Update a snooze.
If `--snooze-from-file` is specified, then the update rules depend on
the value of the (optional) `--fields` flag:
* If `--fields` is specified, then only the specified fields of the
snooze are updated.
* Else, all fields of the snooze are replaced. The updated snooze
can be modified further using the flags from the Snooze
Settings group below.
Otherwise, the snooze will be updated with the values specified in
the flags from the Snooze Settings group.
For information about the JSON/YAML format of a snooze:
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.snoozes
""",
'EXAMPLES': """\
To update a snooze time interval with command-line options, run:
$ {command} MY-SNOOZE --start-time=START_TIME --end-time=END_TIME
To update a snooze display name with a file, run:
$ {command} --snooze-from-file=MY-FILE --fields=display_name
Sample contents of MY-FILE:
criteria:
policies:
- projects/MY-PROJECT/alertPolicies/MY-POLICY
interval:
startTime: '2024-03-01T08:00:00Z'
endTime: '2024-03-08T04:59:59.500Z'
displayName: New Snooze with New Display Name
"""
}
@staticmethod
def Args(parser):
resources = [
resource_args.CreateSnoozeResourceArg('to be updated.')]
resource_args.AddResourceArgs(parser, resources)
flags.AddFileMessageFlag(parser, 'snooze')
flags.AddFieldsFlagsWithMutuallyExclusiveSettings(
parser,
fields_help=('The list of fields to update. Must specify '
'`--snooze-from-file` if using this flag.'),
add_settings_func=flags.AddSnoozeSettingsFlags,
update=True)
def Run(self, args):
util.ValidateUpdateArgsSpecified(
args,
['snooze_from_file', 'display_name',
'start_time', 'end_time', 'fields'],
'snooze')
flags.ValidateSnoozeUpdateArgs(args)
client = snoozes.SnoozeClient()
messages = client.messages
passed_yaml_snooze = False
snooze_ref = args.CONCEPTS.snooze.Parse()
if args.snooze_from_file:
passed_yaml_snooze = True
snooze = util.GetBaseSnoozeMessageFromArgs(
args, messages.Snooze, update=True
)
else:
# If a full snooze isn't given, we want to do Read-Modify-Write.
# TODO(b/271427290): Replace 500 with 404 in api
snooze = client.Get(snooze_ref)
# And validate that the snooze reference is not Past/Canceled.
flags.ValidateSnoozeInterval(
snooze,
display_name=args.display_name,
start_time=args.start_time,
end_time=args.end_time,
)
if not args.fields:
fields = []
util.ModifySnooze(
snooze,
messages,
display_name=args.display_name,
start_time=args.start_time,
end_time=args.end_time,
field_masks=fields)
# For more robust concurrent updates, use update masks if we're not
# trying to replace the snooze using --snooze-from-file.
fields = None if passed_yaml_snooze else ','.join(sorted(fields))
else:
fields = ','.join(args.fields)
result = client.Update(snooze_ref, snooze, fields)
log.UpdatedResource(result.name, 'snooze')
return result