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,47 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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 Cloud Monitoring Alerts API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import util
class AlertsClient(object):
"""Client for the Alert service in the Stackdriver Monitoring API."""
def __init__(self, client=None, messages=None):
self.client = client or util.GetClientInstance()
self.messages = messages or self.client.MESSAGES_MODULE
self._service = self.client.projects_alerts
def Get(self, alert_ref):
"""Gets a Monitoring Alert."""
request = self.messages.MonitoringProjectsAlertsGetRequest(
name=alert_ref.RelativeName()
)
return self._service.Get(request)
def List(self, project_ref, a_filter=None, order_by=None, page_size=None):
"""Lists Monitoring Alerts."""
request = self.messages.MonitoringProjectsAlertsListRequest(
parent=project_ref.RelativeName(),
filter=a_filter,
orderBy=order_by,
pageSize=page_size,
)
return self._service.List(request)

View File

@@ -0,0 +1,59 @@
# -*- 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.
"""API Client for Cloud Monitoring Notification Channels."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
def GetClientInstance(no_http=False):
return apis.GetClientInstance('monitoring', 'v3', no_http=no_http)
def GetMessagesModule(client=None):
client = client or GetClientInstance()
return client.MESSAGES_MODULE
class NotificationChannelsClient(object):
"""Client for Notification Channels service in the Cloud Monitoring."""
def __init__(self, client=None, messages=None):
self.client = client or GetClientInstance()
self.messages = messages or GetMessagesModule(client)
self._service = self.client.projects_notificationChannels
def Create(self, project_ref, channel):
"""Creates an Monitoring Alert Policy."""
req = self.messages.MonitoringProjectsNotificationChannelsCreateRequest(
name=project_ref.RelativeName(),
notificationChannel=channel)
return self._service.Create(req)
def Get(self, channel_ref):
req = self.messages.MonitoringProjectsNotificationChannelsGetRequest(
name=channel_ref.RelativeName())
return self._service.Get(req)
def Update(self, channel_ref, channel, fields=None):
req = self.messages.MonitoringProjectsNotificationChannelsPatchRequest(
name=channel_ref.RelativeName(),
notificationChannel=channel,
updateMask=fields)
return self._service.Patch(req)

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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 Cloud Monitoring Metric service API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
def GetClientInstance(no_http=False):
return apis.GetClientInstance('monitoring', 'v3', no_http=no_http)
def GetMessagesModule():
return GetClientInstance().MESSAGES_MODULE
class MetricClient(object):
"""Client for the Metric service in the Cloud Monitoring API."""
def __init__(self):
self.client = GetClientInstance()
self.messages = GetMessagesModule()
def ListTimeSeriesByProject(
self,
project,
aggregation_alignment_period,
aggregation_per_series_aligner,
interval_start_time,
interval_end_time,
filter_str,
):
"""List the Metrics Scopes monitoring the specified project."""
request = self.messages.MonitoringProjectsTimeSeriesListRequest(
name=f'projects/{project}',
aggregation_alignmentPeriod=aggregation_alignment_period,
aggregation_perSeriesAligner=aggregation_per_series_aligner,
interval_startTime=interval_start_time,
interval_endTime=interval_end_time,
filter=filter_str,
view=self.messages.MonitoringProjectsTimeSeriesListRequest.ViewValueValuesEnum.FULL,
)
return self.client.projects_timeSeries.List(request)

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.
"""Utilities for Cloud Monitoring Metrics Scopes API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
def GetClientInstance(no_http=False):
return apis.GetClientInstance('monitoring', 'v1', no_http=no_http)
def GetMessagesModule(client=None):
client = client or GetClientInstance()
return client.MESSAGES_MODULE
class MetricsScopeClient(object):
"""Client for the Metrics Scope service in the Cloud Monitoring API."""
def __init__(self, client=None, messages=None):
self.client = client or GetClientInstance()
self.messages = messages or GetMessagesModule(client)
self._ms_service = self.client.locations_global_metricsScopes
self._mp_service = self.client.locations_global_metricsScopes_projects
def MetricsScopeName(self, metrics_scope_ref):
return 'locations/global/metricsScopes/' + metrics_scope_ref.Name()
def MonitoredProjectName(self, metrics_scope_ref, monitored_project_ref):
return self.MetricsScopeName(
metrics_scope_ref) + '/projects/' + monitored_project_ref.Name()
def List(self, project_ref):
"""List the Metrics Scopes monitoring the specified project."""
request = (
self.messages.
MonitoringLocationsGlobalMetricsScopesListMetricsScopesByMonitoredProjectRequest(
monitoredResourceContainer=project_ref.RelativeName()))
return self._ms_service.ListMetricsScopesByMonitoredProject(request)
def Create(self, metrics_scope_ref, monitored_project_ref):
"""Create a Monitored Project in a Monitoring Metrics Scope."""
mp = self.messages.MonitoredProject()
mp.name = self.MonitoredProjectName(metrics_scope_ref,
monitored_project_ref)
request = (
self.messages
.MonitoringLocationsGlobalMetricsScopesProjectsCreateRequest(
monitoredProject=mp,
parent=self.MetricsScopeName(metrics_scope_ref)))
return self._mp_service.Create(request)
def Delete(self, metrics_scope_ref, monitored_project_ref):
"""Delete a Monitored Project from a Monitoring Metrics Scope."""
request = (
self.messages
.MonitoringLocationsGlobalMetricsScopesProjectsDeleteRequest(
name=self.MonitoredProjectName(metrics_scope_ref,
monitored_project_ref)))
return self._mp_service.Delete(request)

View File

@@ -0,0 +1,93 @@
# -*- 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.
"""Utilities for Cloud Monitoring Policies API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
def GetClientInstance(no_http=False):
return apis.GetClientInstance('monitoring', 'v3', no_http=no_http)
def GetMessagesModule(client=None):
client = client or GetClientInstance()
return client.MESSAGES_MODULE
class AlertPolicyClient(object):
"""Client for the Alert Policy service in the Stackdriver Monitoring API."""
def __init__(self, client=None, messages=None):
self.client = client or GetClientInstance()
self.messages = messages or GetMessagesModule(client)
self._service = self.client.projects_alertPolicies
def Create(self, project_ref, policy):
"""Creates a Stackdriver alerting policy."""
req = self.messages.MonitoringProjectsAlertPoliciesCreateRequest(
name=project_ref.RelativeName(),
alertPolicy=policy)
return self._service.Create(req)
def Get(self, policy_ref):
"""Gets an Monitoring Alert Policy."""
request = self.messages.MonitoringProjectsAlertPoliciesGetRequest(
name=policy_ref.RelativeName())
return self._service.Get(request)
def List(self, project_ref, list_filter=None):
"""List Monitoring Alert Policies.
"list_filter" must be a valid filter expression or an empty value. For more
information, see
https://cloud.google.com/monitoring/api/v3/sorting-and-filtering
Args:
project_ref: resources.Resource, Resource reference to the policy to be
updated.
list_filter: str, filter to be included in the ListAlertPOliciesRequest.
Returns:
Alert policies that match the given filter. If no filter is given, fetches
all policies from the target project.
"""
request = self.messages.MonitoringProjectsAlertPoliciesListRequest(
name=project_ref.RelativeName(), filter=list_filter or ''
)
return self._service.List(request)
def Update(self, policy_ref, policy, fields=None):
"""Updates a Monitoring Alert Policy.
If fields is not specified, then the policy is replaced entirely. If
fields are specified, then only the fields are replaced.
Args:
policy_ref: resources.Resource, Resource reference to the policy to be
updated.
policy: AlertPolicy, The policy message to be sent with the request.
fields: str, Comma separated list of field masks.
Returns:
AlertPolicy, The updated AlertPolicy.
"""
request = self.messages.MonitoringProjectsAlertPoliciesPatchRequest(
name=policy_ref.RelativeName(),
alertPolicy=policy,
updateMask=fields)
return self._service.Patch(request)

View File

@@ -0,0 +1,72 @@
# -*- 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.
"""Utilities for Cloud Monitoring Snoozes API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
def GetClientInstance(no_http=False):
return apis.GetClientInstance('monitoring', 'v3', no_http=no_http)
def GetMessagesModule(client=None):
client = client or GetClientInstance()
return client.MESSAGES_MODULE
class SnoozeClient(object):
"""Client for the Snooze service in the Stackdriver Monitoring API."""
def __init__(self, client=None, messages=None):
self.client = client or GetClientInstance()
self.messages = messages or GetMessagesModule(client)
self._service = self.client.projects_snoozes
def Create(self, project_ref, snooze):
"""Creates a Stackdriver snooze."""
req = self.messages.MonitoringProjectsSnoozesCreateRequest(
parent=project_ref.RelativeName(),
snooze=snooze)
return self._service.Create(req)
def Get(self, snooze_ref):
"""Gets an Monitoring Snooze."""
request = self.messages.MonitoringProjectsSnoozesGetRequest(
name=snooze_ref.RelativeName())
return self._service.Get(request)
def Update(self, snooze_ref, snooze, fields=None):
"""Updates a Monitoring Snooze.
If fields is not specified, then the snooze is replaced entirely. If
fields are specified, then only the fields are replaced.
Args:
snooze_ref: resources.Resource, Resource reference to the snooze to be
updated.
snooze: Snooze, The snooze message to be sent with the request.
fields: str, Comma separated list of field masks.
Returns:
Snooze, The updated Snooze.
"""
request = self.messages.MonitoringProjectsSnoozesPatchRequest(
name=snooze_ref.RelativeName(),
snooze=snooze,
updateMask=fields)
return self._service.Patch(request)

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.
"""Utilities for Cloud Monitoring Uptime API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
def GetClientInstance(no_http=False):
return apis.GetClientInstance('monitoring', 'v3', no_http=no_http)
def GetMessagesModule(client=None):
client = client or GetClientInstance()
return client.MESSAGES_MODULE
class UptimeClient(object):
"""Client for the Uptime Check service in the Stackdriver Monitoring API."""
def __init__(self, client=None, messages=None):
self.client = client or GetClientInstance()
self.messages = messages or GetMessagesModule(client)
self._service = self.client.projects_uptimeCheckConfigs
def Get(self, uptime_check_ref):
"""Gets a Stackdriver uptime check."""
request = self.messages.MonitoringProjectsUptimeCheckConfigsGetRequest(
name=uptime_check_ref.RelativeName(),
)
return self._service.Get(request)
def Create(self, project_ref, uptime_check):
"""Creates a Stackdriver uptime check."""
req = self.messages.MonitoringProjectsUptimeCheckConfigsCreateRequest(
parent=project_ref.RelativeName(),
uptimeCheckConfig=uptime_check,
)
return self._service.Create(req)
def Update(self, uptime_check_ref, uptime_check, fields=None):
"""Updates a Stackdriver uptime check.
If fields is not specified, then the uptime check is replaced entirely. If
fields are specified, then only the fields are replaced.
Args:
uptime_check_ref: resources.Resource, Resource reference to the
uptime_check to be updated.
uptime_check: Uptime Check, The uptime_check message to be sent with the
request.
fields: str, Comma separated list of field masks.
Returns:
Uptime Check, The updated Uptime Check.
"""
request = self.messages.MonitoringProjectsUptimeCheckConfigsPatchRequest(
name=uptime_check_ref.RelativeName(),
uptimeCheckConfig=uptime_check,
updateMask=fields,
)
return self._service.Patch(request)

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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 the cloud monitoring API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
API_NAME = 'monitoring'
API_VERSION = 'v3'
def GetClientInstance(no_http=False):
return apis.GetClientInstance(API_NAME, API_VERSION, no_http=no_http)
def GetMessagesModule(client=None):
if client is None:
client = GetClientInstance()
return client.MESSAGES_MODULE