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,32 @@
# -*- 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 calling the Networkservices API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
API_VERSION_FOR_TRACK = {
base.ReleaseTrack.ALPHA: 'v1alpha1',
}
_API_NAME = 'networkservices'
def GetClientInstance(release_track=base.ReleaseTrack.ALPHA):
api_version = API_VERSION_FOR_TRACK.get(release_track)
return apis.GetClientInstance(_API_NAME, api_version)

View File

@@ -0,0 +1,110 @@
# -*- 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.
"""API wrapper for `gcloud network-actions wasm-plugin` commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.network_actions import util
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.core import resources
class Client:
"""API client for WasmPlugin commands.
Attributes:
messages: API messages class, The Networkservices API messages.
"""
def __init__(self, release_track):
self._client = util.GetClientInstance(release_track)
self._wasm_plugin_client = self._client.projects_locations_wasmPlugins
self._operations_client = self._client.projects_locations_operations
self.messages = self._client.MESSAGES_MODULE
self._resource_parser = resources.Registry()
self._resource_parser.RegisterApiByName(
'networkservices', util.API_VERSION_FOR_TRACK.get(release_track)
)
def CreateWasmPlugin(
self, name, parent, description=None, labels=None, log_config=None
):
"""Calls the CreateWasmPlugin API."""
request = (
self.messages.NetworkservicesProjectsLocationsWasmPluginsCreateRequest(
parent=parent,
wasmPluginId=name,
wasmPlugin=self.messages.WasmPlugin(
description=description,
labels=labels,
logConfig=log_config,
),
)
)
return self._wasm_plugin_client.Create(request)
def UpdateWasmPlugin(
self,
name,
main_version,
update_mask=None,
description=None,
labels=None,
log_config=None,
):
"""Calls the UpdateWasmPlugin API."""
request = (
self.messages.NetworkservicesProjectsLocationsWasmPluginsPatchRequest(
name=name,
updateMask=update_mask,
wasmPlugin=self.messages.WasmPlugin(
mainVersionId=main_version,
description=description,
labels=labels,
logConfig=log_config,
),
)
)
return self._wasm_plugin_client.Patch(request)
def WaitForOperation(
self,
operation_ref,
message,
):
"""Waits for the opration to complete and returns the result of the operation.
Args:
operation_ref: A Resource describing the Operation.
message: The message to display to the user while they wait.
Returns:
result of result_service.Get request for the provided operation.
"""
op_resource = resources.REGISTRY.ParseRelativeName(
operation_ref.name,
collection='networkservices.projects.locations.operations',
)
poller = waiter.CloudOperationPoller(
self._wasm_plugin_client, self._operations_client
)
return waiter.WaitFor(
poller,
op_resource,
message,
)

View File

@@ -0,0 +1,120 @@
# -*- 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.
"""API wrapper for `gcloud network-actions wasm-plugin-versions` commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.network_actions import util
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.core import resources
import six
class Client:
"""API client for WasmPluginVersion commands.
Attributes:
messages: API messages class, The Networkservices API messages.
"""
def __init__(self, release_track):
self._client = util.GetClientInstance(release_track)
self._wasm_plugin_version_client = (
self._client.projects_locations_wasmPlugins_versions
)
self._operations_client = self._client.projects_locations_operations
self.messages = self._client.MESSAGES_MODULE
self._resource_parser = resources.Registry()
self._resource_parser.RegisterApiByName(
'networkservices', util.API_VERSION_FOR_TRACK.get(release_track)
)
def CreateWasmPluginVersion(
self,
name,
parent,
image,
plugin_config_data=None,
plugin_config_uri=None,
description=None,
labels=None,
):
"""Calls the CreateWasmPluginVersion API.
Args:
name: string, wasmPluginVersion's name.
parent: string, wasmPluginVersion's parent relative name.
image: string, URI of the container image containing the Wasm module,
stored in the Artifact Registry.
plugin_config_data: string or bytes, WasmPlugin configuration in the
textual or binary format.
plugin_config_uri: string, URI of the container image containing the
plugin configuration, stored in the Artifact Registry.
description: string, human-readable description of the service.
labels: set of label tags.
Returns:
(Operation) The response message.
"""
plugin_config_data_binary = None
if plugin_config_data:
# Converts string --plugin-config flag into bytes for the string-type
# argument and returns the unchanged argument value for bytes-type
# --plugin-config-file flag.
plugin_config_data_binary = six.ensure_binary(plugin_config_data)
request = (
self.messages.NetworkservicesProjectsLocationsWasmPluginsVersionsCreateRequest(
parent=parent,
wasmPluginVersionId=name,
wasmPluginVersion=self.messages.WasmPluginVersion(
imageUri=image,
description=description,
labels=labels,
pluginConfigData=plugin_config_data_binary,
pluginConfigUri=plugin_config_uri,
),
)
)
return self._wasm_plugin_version_client.Create(request)
def WaitForOperation(
self,
operation_ref,
message,
):
"""Waits for the opration to complete and returns the result of the operation.
Args:
operation_ref: A Resource describing the Operation.
message: The message to display to the user while they wait.
Returns:
result of result_service.Get request for the provided operation.
"""
op_resource = resources.REGISTRY.ParseRelativeName(
operation_ref.name,
collection='networkservices.projects.locations.operations',
)
poller = waiter.CloudOperationPoller(
self._wasm_plugin_version_client, self._operations_client
)
return waiter.WaitFor(
poller,
op_resource,
message,
)