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,44 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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.
"""Commands for reading and manipulating target HTTP proxies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class TargetHTTPProxies(base.Group):
"""List, create, and delete target HTTP proxies."""
TargetHTTPProxies.category = base.NETWORKING_CATEGORY
TargetHTTPProxies.detailed_help = {
'DESCRIPTION': """
List, create, and delete target HTTP proxies.
For more information about target HTTP proxies, see the
[target HTTP proxies documentation](https://cloud.google.com/load-balancing/docs/target-proxies).
See also: [Target HTTP proxies API](https://cloud.google.com/compute/docs/reference/rest/v1/targetHttpProxies)
and
[Regional target HTTP proxies API](https://cloud.google.com/compute/docs/reference/rest/v1/regionTargetHttpProxies).
""",
}

View File

@@ -0,0 +1,26 @@
# -*- 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.
"""Command group for managing Compute Engine target http proxy configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Config(base.Group):
"""Manage Compute Engine target http proxy configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Compute Engine target http proxy.
description: |
*{command}* exports the configuration for a Compute Engine target http proxy.
Target http proxy configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
target http proxies within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a target http proxy, run:
$ {command} my-target-http-proxy
To export the configuration for a target http proxy to a file, run:
$ {command} my-target-http-proxy --path=/path/to/dir/
To export the configuration for a target http proxy in Terraform
HCL format, run:
$ {command} my-target-http-proxy --resource-format=terraform
To export the configurations for all target http proxies within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Target http proxy to export the configuration for.
spec: !REF googlecloudsdk.command_lib.compute.resources:target_http_proxy

View File

@@ -0,0 +1,151 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for creating target HTTP proxies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import target_proxies_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
from googlecloudsdk.command_lib.compute.target_http_proxies import target_http_proxies_utils
from googlecloudsdk.command_lib.compute.url_maps import flags as url_map_flags
def _DetailedHelp():
return {
'brief': 'Create a target HTTP proxy.',
'DESCRIPTION': """\
*{command}* is used to create target HTTP proxies. A target
HTTP proxy is referenced by one or more forwarding rules which
specify the network traffic that the proxy is responsible for
routing. The target HTTP proxy points to a URL map that defines
the rules for routing the requests. The URL map's job is to map
URLs to backend services which handle the actual requests.
""",
'EXAMPLES': """\
If there is an already-created URL map with the name URL_MAP, create a
global target HTTP proxy pointing to this map by running:
$ {command} PROXY_NAME --url-map=URL_MAP
Create a regional target HTTP proxy by running:
$ {command} PROXY_NAME --url-map=URL_MAP --region=REGION_NAME
To create a proxy with a textual description, run:
$ {command} PROXY_NAME --url-map=URL_MAP --description="default proxy"
""",
}
def _Args(parser, traffic_director_security):
"""Add the target http proxies comamnd line flags to the parser."""
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
parser.add_argument(
'--description',
help='An optional, textual description for the target HTTP proxy.',
)
parser.display_info.AddCacheUpdater(flags.TargetHttpProxiesCompleter)
if traffic_director_security:
flags.AddProxyBind(parser, False)
target_proxies_utils.AddHttpKeepAliveTimeoutSec(parser)
def _Run(
args, holder, url_map_ref, target_http_proxy_ref, traffic_director_security
):
"""Issue a Target HTTP Proxy Insert request."""
client = holder.client
if traffic_director_security and args.proxy_bind:
target_http_proxy = client.messages.TargetHttpProxy(
description=args.description,
name=target_http_proxy_ref.Name(),
urlMap=url_map_ref.SelfLink(),
proxyBind=args.proxy_bind,
)
else:
target_http_proxy = client.messages.TargetHttpProxy(
description=args.description,
name=target_http_proxy_ref.Name(),
urlMap=url_map_ref.SelfLink(),
)
if args.IsSpecified('http_keep_alive_timeout_sec'):
target_http_proxy.httpKeepAliveTimeoutSec = args.http_keep_alive_timeout_sec
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(
target_http_proxy_ref
):
request = client.messages.ComputeRegionTargetHttpProxiesInsertRequest(
project=target_http_proxy_ref.project,
region=target_http_proxy_ref.region,
targetHttpProxy=target_http_proxy,
)
collection = client.apitools_client.regionTargetHttpProxies
else:
request = client.messages.ComputeTargetHttpProxiesInsertRequest(
project=target_http_proxy_ref.project, targetHttpProxy=target_http_proxy
)
collection = client.apitools_client.targetHttpProxies
return client.MakeRequests([(collection, 'Insert', request)])
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a target HTTP proxy."""
_traffic_director_security = False
URL_MAP_ARG = None
TARGET_HTTP_PROXY_ARG = None
detailed_help = _DetailedHelp()
@classmethod
def Args(cls, parser):
cls.TARGET_HTTP_PROXY_ARG = flags.TargetHttpProxyArgument()
cls.TARGET_HTTP_PROXY_ARG.AddArgument(parser, operation_type='create')
cls.URL_MAP_ARG = url_map_flags.UrlMapArgumentForTargetProxy()
cls.URL_MAP_ARG.AddArgument(parser)
_Args(parser, cls._traffic_director_security)
def Run(self, args):
"""Issue a Target HTTP Proxy Insert request."""
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
target_http_proxy_ref = self.TARGET_HTTP_PROXY_ARG.ResolveAsResource(
args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL
)
url_map_ref = target_http_proxies_utils.ResolveTargetHttpProxyUrlMap(
args, self.URL_MAP_ARG, target_http_proxy_ref, holder.resources
)
return _Run(
args,
holder,
url_map_ref,
target_http_proxy_ref,
self._traffic_director_security,
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(Create):
_traffic_director_security = True

View File

@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for deleting target HTTP proxies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
from googlecloudsdk.command_lib.compute.target_http_proxies import target_http_proxies_utils
def _DetailedHelp():
return {
'brief':
'Delete target HTTP proxies.',
'DESCRIPTION':
"""\
*{command}* deletes one or more target HTTP proxies.
""",
'EXAMPLES':
"""\
Delete a global target HTTP proxy by running:
$ {command} PROXY_NAME
Delete a regional target HTTP proxy by running:
$ {command} PROXY_NAME --region=REGION_NAME
""",
}
def _Run(holder, target_http_proxy_refs):
"""Issues requests necessary to delete Target HTTP Proxies."""
client = holder.client
utils.PromptForDeletion(target_http_proxy_refs)
requests = []
for target_http_proxy_ref in target_http_proxy_refs:
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(
target_http_proxy_ref):
requests.append(
(client.apitools_client.regionTargetHttpProxies, 'Delete',
client.messages.ComputeRegionTargetHttpProxiesDeleteRequest(
**target_http_proxy_ref.AsDict())))
else:
requests.append((client.apitools_client.targetHttpProxies, 'Delete',
client.messages.ComputeTargetHttpProxiesDeleteRequest(
**target_http_proxy_ref.AsDict())))
return client.MakeRequests(requests)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete target HTTP proxies."""
TARGET_HTTP_PROXY_ARG = None
detailed_help = _DetailedHelp()
@classmethod
def Args(cls, parser):
cls.TARGET_HTTP_PROXY_ARG = flags.TargetHttpProxyArgument(plural=True)
cls.TARGET_HTTP_PROXY_ARG.AddArgument(parser, operation_type='delete')
parser.display_info.AddCacheUpdater(flags.TargetHttpProxiesCompleter)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
target_http_proxy_refs = self.TARGET_HTTP_PROXY_ARG.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
return _Run(holder, target_http_proxy_refs)

View File

@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for describing target HTTP proxies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
from googlecloudsdk.command_lib.compute.target_http_proxies import target_http_proxies_utils
def _DetailedHelp():
return {
'brief':
'Display detailed information about a target HTTP proxy.',
'DESCRIPTION':
"""\
*{command}* displays all data associated with a target HTTP proxy
in a project.
""",
'EXAMPLES':
"""\
To describe a global target HTTP proxy, run:
$ {command} PROXY_NAME
To describe a regional target HTTP proxy, run:
$ {command} PROXY_NAME --region=REGION_NAME
""",
}
def _Run(holder, target_http_proxy_ref):
"""Issues requests necessary to describe Target HTTP Proxies."""
client = holder.client
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(
target_http_proxy_ref):
request = client.messages.ComputeRegionTargetHttpProxiesGetRequest(
**target_http_proxy_ref.AsDict())
collection = client.apitools_client.regionTargetHttpProxies
else:
request = client.messages.ComputeTargetHttpProxiesGetRequest(
**target_http_proxy_ref.AsDict())
collection = client.apitools_client.targetHttpProxies
return client.MakeRequests([(collection, 'Get', request)])[0]
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Display detailed information about a target HTTP proxy."""
TARGET_HTTP_PROXY_ARG = None
detailed_help = _DetailedHelp()
@classmethod
def Args(cls, parser):
cls.TARGET_HTTP_PROXY_ARG = flags.TargetHttpProxyArgument()
cls.TARGET_HTTP_PROXY_ARG.AddArgument(parser, operation_type='describe')
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
target_http_proxy_ref = self.TARGET_HTTP_PROXY_ARG.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
return _Run(holder, target_http_proxy_ref)

View File

@@ -0,0 +1,111 @@
# -*- 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.
"""Export target HTTP proxy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
from googlecloudsdk.command_lib.compute.target_http_proxies import target_http_proxies_utils
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core.util import files
def _DetailedHelp():
return {
'brief':
'Export a target HTTP proxy.',
'DESCRIPTION':
"""\
Exports a target HTTP proxy's configuration to a file.
This configuration can be imported at a later time.
""",
'EXAMPLES':
"""\
A target HTTP proxy can be exported by running:
$ {command} NAME --destination=<path-to-file>
"""
}
def _GetApiVersion(release_track):
"""Returns the API version based on the release track."""
if release_track == base.ReleaseTrack.ALPHA:
return 'alpha'
if release_track == base.ReleaseTrack.BETA:
return 'beta'
return 'v1'
def _GetSchemaPath(release_track, for_help=False):
"""Returns the resource schema path."""
return export_util.GetSchemaPath(
'compute',
_GetApiVersion(release_track),
'TargetHttpProxy',
for_help=for_help)
def _Run(args, holder, target_http_proxy_arg, release_track):
"""Issues requests necessary to export target HTTP proxies."""
client = holder.client
target_http_proxy_ref = target_http_proxy_arg.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(client))
target_http_proxy = target_http_proxies_utils.SendGetRequest(
client, target_http_proxy_ref)
if args.destination:
with files.FileWriter(args.destination) as stream:
export_util.Export(
message=target_http_proxy,
stream=stream,
schema_path=_GetSchemaPath(release_track))
else:
export_util.Export(
message=target_http_proxy,
stream=sys.stdout,
schema_path=_GetSchemaPath(release_track))
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Export(base.Command):
"""Export a target HTTP proxy."""
detailed_help = _DetailedHelp()
TARGET_HTTP_PROXY_ARG = None
@classmethod
def Args(cls, parser):
cls.TARGET_HTTP_PROXY_ARG = flags.TargetHttpProxyArgument()
cls.TARGET_HTTP_PROXY_ARG.AddArgument(parser, operation_type='export')
export_util.AddExportFlags(
parser, _GetSchemaPath(cls.ReleaseTrack(), for_help=True))
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
return _Run(args, holder, self.TARGET_HTTP_PROXY_ARG, self.ReleaseTrack())

View File

@@ -0,0 +1,207 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""Import target HTTP Proxies command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import exceptions as compute_exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import operation_utils
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
from googlecloudsdk.command_lib.compute.target_http_proxies import target_http_proxies_utils
from googlecloudsdk.command_lib.export import util as export_util
from googlecloudsdk.core import yaml_validator
from googlecloudsdk.core.console import console_io
def _DetailedHelp():
return {
'brief':
'Import a target HTTP proxy.',
'DESCRIPTION':
"""\
Imports a target HTTP proxy's configuration from a file.
""",
'EXAMPLES':
"""\
A target HTTP proxy can be imported by running:
$ {command} NAME --source=<path-to-file>
"""
}
def _GetApiVersion(release_track):
"""Returns the API version based on the release track."""
if release_track == base.ReleaseTrack.ALPHA:
return 'alpha'
elif release_track == base.ReleaseTrack.BETA:
return 'beta'
return 'v1'
def _GetSchemaPath(release_track, for_help=False):
"""Returns the resource schema path."""
return export_util.GetSchemaPath(
'compute',
_GetApiVersion(release_track),
'TargetHttpProxy',
for_help=for_help)
def _SendInsertRequest(client, resources, target_http_proxy_ref,
target_http_proxy):
"""Sends Target HTTP Proxy insert request."""
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(
target_http_proxy_ref):
service = client.apitools_client.regionTargetHttpProxies
operation = service.Insert(
client.messages.ComputeRegionTargetHttpProxiesInsertRequest(
project=target_http_proxy_ref.project,
region=target_http_proxy_ref.region,
targetHttpProxy=target_http_proxy))
else:
service = client.apitools_client.targetHttpProxies
operation = service.Insert(
client.messages.ComputeTargetHttpProxiesInsertRequest(
project=target_http_proxy_ref.project,
targetHttpProxy=target_http_proxy))
return _WaitForOperation(resources, service, operation, target_http_proxy_ref,
'Inserting TargetHttpProxy')
def _SendPatchRequest(client, resources, target_http_proxy_ref,
target_http_proxy):
"""Make target HTTP proxy patch request."""
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(
target_http_proxy_ref):
console_message = ('Target HTTP Proxy [{0}] cannot be updated'.format(
target_http_proxy_ref.Name()))
raise NotImplementedError(console_message)
service = client.apitools_client.targetHttpProxies
operation = service.Patch(
client.messages.ComputeTargetHttpProxiesPatchRequest(
project=target_http_proxy_ref.project,
targetHttpProxy=target_http_proxy_ref.Name(),
targetHttpProxyResource=target_http_proxy))
return _WaitForOperation(resources, service, operation, target_http_proxy_ref,
'Updating TargetHttpProxy')
def _WaitForOperation(resources, service, operation, target_http_proxy_ref,
message):
"""Waits for the TargetHttpProxy operation to finish."""
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(
target_http_proxy_ref):
collection = operation_utils.GetRegionalOperationsCollection()
else:
collection = operation_utils.GetGlobalOperationsCollection()
return operation_utils.WaitForOperation(resources, service, operation,
collection, target_http_proxy_ref,
message)
def _Run(args, holder, target_http_proxy_arg, release_track):
"""Issues requests necessary to import target HTTP proxies."""
client = holder.client
resources = holder.resources
target_http_proxy_ref = target_http_proxy_arg.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(client))
data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)
try:
target_http_proxy = export_util.Import(
message_type=client.messages.TargetHttpProxy,
stream=data,
schema_path=_GetSchemaPath(release_track))
except yaml_validator.ValidationError as e:
raise compute_exceptions.ValidationError(str(e))
# Get existing target HTTP proxy.
try:
target_http_proxy_old = target_http_proxies_utils.SendGetRequest(
client, target_http_proxy_ref)
except apitools_exceptions.HttpError as error:
if error.status_code != 404:
raise error
# Target HTTP proxy does not exist, create a new one.
return _SendInsertRequest(client, resources, target_http_proxy_ref,
target_http_proxy)
if target_http_proxy_old == target_http_proxy:
return
console_io.PromptContinue(
message=('Target Http Proxy [{0}] will be overwritten.').format(
target_http_proxy_ref.Name()),
cancel_on_no=True)
# Populate id and fingerprint fields. These two fields are manually
# removed from the schema files.
target_http_proxy.id = target_http_proxy_old.id
target_http_proxy.fingerprint = target_http_proxy_old.fingerprint
# Unspecified fields are assumed to be cleared.
cleared_fields = []
if target_http_proxy.description is None:
cleared_fields.append('description')
# The REST API will reject requests without the UrlMap. However, we want to
# avoid doing partial validations in the client and rely on server side
# behavior.
if target_http_proxy.urlMap is None:
cleared_fields.append('urlMap')
if release_track != base.ReleaseTrack.GA:
if target_http_proxy.proxyBind is None:
cleared_fields.append('proxyBind')
with client.apitools_client.IncludeFields(cleared_fields):
return _SendPatchRequest(client, resources, target_http_proxy_ref,
target_http_proxy)
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Import(base.UpdateCommand):
"""Import a target HTTP Proxy."""
detailed_help = _DetailedHelp()
TARGET_HTTP_PROXY_ARG = None
@classmethod
def Args(cls, parser):
cls.TARGET_HTTP_PROXY_ARG = flags.TargetHttpProxyArgument()
cls.TARGET_HTTP_PROXY_ARG.AddArgument(parser, operation_type='import')
export_util.AddImportFlags(
parser, _GetSchemaPath(cls.ReleaseTrack(), for_help=True))
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
return _Run(args, holder, self.TARGET_HTTP_PROXY_ARG, self.ReleaseTrack())

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for listing target HTTP proxies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
def _DetailedHelp():
return base_classes.GetMultiScopeListerHelp(
'target HTTP proxies',
scopes=[
base_classes.ScopeType.global_scope,
base_classes.ScopeType.regional_scope
])
def _Args(parser):
parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)
lister.AddMultiScopeListerFlags(parser, regional=True, global_=True)
parser.display_info.AddCacheUpdater(flags.TargetHttpProxiesCompleter)
def _Run(args, holder):
"""Issues requests necessary to list Target HTTP Proxies."""
client = holder.client
request_data = lister.ParseMultiScopeFlags(args, holder.resources)
list_implementation = lister.MultiScopeLister(
client,
regional_service=client.apitools_client.regionTargetHttpProxies,
global_service=client.apitools_client.targetHttpProxies,
aggregation_service=client.apitools_client.targetHttpProxies)
return lister.Invoke(request_data, list_implementation)
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA,
base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""List target HTTP proxies."""
detailed_help = _DetailedHelp()
@classmethod
def Args(cls, parser):
_Args(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
return _Run(args, holder)

View File

@@ -0,0 +1,179 @@
# -*- coding: utf-8 -*- #
# Copyright 2014 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 for updating target HTTP proxies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import target_proxies_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute import scope as compute_scope
from googlecloudsdk.command_lib.compute.target_http_proxies import flags
from googlecloudsdk.command_lib.compute.target_http_proxies import target_http_proxies_utils
from googlecloudsdk.command_lib.compute.url_maps import flags as url_map_flags
def _DetailedHelp():
return {
'brief': 'Update a target HTTP proxy.',
'DESCRIPTION': """\
*{command}* is used to change the URL map of existing target
HTTP proxies. A target HTTP proxy is referenced by one or more
forwarding rules which specify the network traffic that the proxy
is responsible for routing. The target HTTP proxy points to a URL
map that defines the rules for routing the requests. The URL map's
job is to map URLs to backend services which handle the actual
requests.
""",
'EXAMPLES': """\
If there is an already-created URL map with the name URL_MAP, update a
global target HTTP proxy pointing to this map by running:
$ {command} PROXY_NAME --url-map=URL_MAP
Update a regional target HTTP proxy by running:
$ {command} PROXY_NAME --url-map=URL_MAP --region=REGION_NAME
""",
}
def _Run(args, holder, target_http_proxy_arg, url_map_arg):
"""Issues requests necessary to update Target HTTP Proxies."""
client = holder.client
proxy_ref = target_http_proxy_arg.ResolveAsResource(
args,
holder.resources,
default_scope=compute_scope.ScopeEnum.GLOBAL,
scope_lister=compute_flags.GetDefaultScopeLister(client),
)
url_map_ref = target_http_proxies_utils.ResolveTargetHttpProxyUrlMap(
args, url_map_arg, proxy_ref, holder.resources
)
if target_http_proxies_utils.IsRegionalTargetHttpProxiesRef(proxy_ref):
invalid_arg = None
if args.IsSpecified('http_keep_alive_timeout_sec'):
invalid_arg = '--http-keep-alive-timeout-sec'
elif args.IsSpecified('clear_http_keep_alive_timeout_sec'):
invalid_arg = '--clear-http-keep-alive-timeout-sec'
if invalid_arg is not None:
raise exceptions.InvalidArgumentException(
invalid_arg,
'http keep alive timeout is not patchable for regional target HTTP'
' proxies',
)
request = client.messages.ComputeRegionTargetHttpProxiesSetUrlMapRequest(
project=proxy_ref.project,
region=proxy_ref.region,
targetHttpProxy=proxy_ref.Name(),
urlMapReference=client.messages.UrlMapReference(
urlMap=url_map_ref.SelfLink()
),
)
collection = client.apitools_client.regionTargetHttpProxies
res = client.MakeRequests([(collection, 'SetUrlMap', request)])
return res
else:
old_resource = _GetGlobalTargetHttpProxy(client, proxy_ref)
new_resource = encoding.CopyProtoMessage(old_resource)
cleared_fields = []
if args.url_map:
new_resource.urlMap = url_map_ref.SelfLink()
if args.IsSpecified('http_keep_alive_timeout_sec'):
new_resource.httpKeepAliveTimeoutSec = args.http_keep_alive_timeout_sec
elif args.IsSpecified('clear_http_keep_alive_timeout_sec'):
new_resource.httpKeepAliveTimeoutSec = None
cleared_fields.append('httpKeepAliveTimeoutSec')
if old_resource != new_resource:
return _PatchGlobalTargetHttpProxy(
client, proxy_ref, new_resource, cleared_fields
)
def _GetGlobalTargetHttpProxy(client, proxy_ref):
"""Retrieves the Global target HTTP proxy."""
requests = []
requests.append((
client.apitools_client.targetHttpProxies,
'Get',
client.messages.ComputeTargetHttpProxiesGetRequest(
project=proxy_ref.project, targetHttpProxy=proxy_ref.Name()
),
))
res = client.MakeRequests(requests)
return res[0]
def _PatchGlobalTargetHttpProxy(
client, proxy_ref, new_resource, cleared_fields
):
"""Patches the Global target HTTP proxy."""
requests = []
requests.append((
client.apitools_client.targetHttpProxies,
'Patch',
client.messages.ComputeTargetHttpProxiesPatchRequest(
project=proxy_ref.project,
targetHttpProxy=proxy_ref.Name(),
targetHttpProxyResource=new_resource,
),
))
with client.apitools_client.IncludeFields(cleared_fields):
return client.MakeRequests(requests)
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Update(base.UpdateCommand):
"""Update a target HTTP proxy."""
TARGET_HTTP_PROXY_ARG = None
URL_MAP_ARG = None
detailed_help = _DetailedHelp()
@classmethod
def Args(cls, parser):
cls.TARGET_HTTP_PROXY_ARG = flags.TargetHttpProxyArgument()
cls.TARGET_HTTP_PROXY_ARG.AddArgument(parser, operation_type='update')
cls.URL_MAP_ARG = url_map_flags.UrlMapArgumentForTargetProxy()
cls.URL_MAP_ARG.AddArgument(parser)
group = parser.add_mutually_exclusive_group()
target_proxies_utils.AddHttpKeepAliveTimeoutSec(group)
target_proxies_utils.AddClearHttpKeepAliveTimeoutSec(group)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
return _Run(
args,
holder,
self.TARGET_HTTP_PROXY_ARG,
self.URL_MAP_ARG,
)