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,21 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Libraries to support the builds command surface."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

View File

@@ -0,0 +1,118 @@
# -*- 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.
"""Set up flags for creating or updating a Bitbucket Server config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.command_lib.builds import flags as build_flags
def AddBitbucketServerConfigArgs(parser, update=False):
"""Set up all the argparse flags for creating or updating a Bitbucket Server config.
Args:
parser: An argparse.ArgumentParser-like object.
update: If true, use the version of the flags for updating a config.
Otherwise, use the version for creating a config.
Returns:
The parser argument with Bitbucket Server config flags added in.
"""
parser.add_argument(
'--host-uri',
required=not update,
help='The host uri of the Bitbucket Server instance.')
parser.add_argument(
'--user-name',
required=not update,
help='The Bitbucket Server user name that should be associated with this config.'
)
parser.add_argument(
'--api-key',
required=not update,
help='The Cloud Build API key that should be associated with this config.'
)
parser.add_argument(
'--admin-access-token-secret-version',
required=not update,
help='Secret Manager resource containing the admin access token. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--read-access-token-secret-version',
required=not update,
help='Secret Manager resource containing the read access token. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--webhook-secret-secret-version',
required=not update,
help='Secret Manager resource containing the webhook secret. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--ssl-ca-file',
type=arg_parsers.FileContents(),
help='Path to a local file that contains SSL certificate to use for requests to Bitbucket Server. The certificate should be in PEM format.'
)
build_flags.AddRegionFlag(parser)
if not update:
parser.add_argument(
'--name',
required=True,
help='The config name of the Bitbucket Server connection.')
network = parser.add_argument_group()
network.add_argument(
'--peered-network',
help="""\
VPC network that should be used when making calls to the Bitbucket Server instance.
If not specified, calls will be made over the public internet.
""")
network.add_argument(
'--peered-network-ip-range',
help="""\
IP range within the peered network. This is specified in CIDR notation with a slash and the subnet prefix size. Examples: `192.168.0.0/24` or '/29'.
""")
if update:
parser.add_argument(
'CONFIG',
help='The unique identifier of the Bitbucket Server Config to be updated.'
)
return parser
def AddBitbucketServerConfigCreateArgs(parser):
"""Set up all the argparse flags for creating a Bitbucket Server Config.
Args:
parser: An argparse.ArgumentParser-like object.
Returns:
The parser argument with Bitbucket Server Config flags added in.
"""
return AddBitbucketServerConfigArgs(parser, update=False)
def AddBitbucketServerConfigUpdateArgs(parser):
"""Set up all the argparse flags for updating a Bitbucket Server Config.
Args:
parser: An argparse.ArgumentParser-like object.
Returns:
The parser argument with Bitbucket Server Config flags added in.
"""
return AddBitbucketServerConfigArgs(parser, update=True)

View File

@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Support library for execution with the container builds submit command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import threading
from googlecloudsdk.core import log
from googlecloudsdk.core.util import keyboard_interrupt
import six
class MashHandler(object):
"""MashHandler only invokes its base handler once.
On the third attempt, the execution is hard-killed.
"""
def __init__(self, base_handler):
self._interrupts = 0
self._base_handler = base_handler
self._lock = threading.Lock()
def __call__(self, signal_number, stack_frame):
with self._lock:
self._interrupts += 1
# Copy the interrupts count and perform the handler outside of this
# lock context. The handler can take a long time and we want to make
# sure that future interrupts don't wait for it.
interrupts = self._interrupts
if interrupts == 1:
# Only do the base handler once.
self._base_handler(signal_number, stack_frame)
elif interrupts == 3:
# If we detect mashing, fallback to gcloud's original handler.
keyboard_interrupt.HandleInterrupt(signal_number, stack_frame)
def GetCancelBuildHandler(client, messages, build_ref):
"""Returns a handler to cancel a build.
Args:
client: base_api.BaseApiClient, An instance of the Cloud Build client.
messages: Module containing the definitions of messages for Cloud Build.
build_ref: Build reference. Expects a cloudbuild.projects.locations.builds
but also supports cloudbuild.projects.builds.
"""
def _CancelBuildHandler(unused_signal_number, unused_stack_frame):
"""Cancels the build_ref build.
Args:
unused_signal_number: The signal caught.
unused_stack_frame: The interrupt stack frame.
Raises:
InvalidUserInputError: if project ID or build ID is not specified.
"""
log.status.Print('Cancelling...')
# accepting both build_refs and legacy build_refs
project_id = None
if hasattr(build_ref, 'projectId'):
project_id = build_ref.projectId
elif hasattr(build_ref, 'projectsId'):
project_id = build_ref.projectsId
build_id = None
if hasattr(build_ref, 'id'):
build_id = build_ref.id
elif hasattr(build_ref, 'buildsId'):
build_id = build_ref.buildsId
location = None
if hasattr(build_ref, 'locationsId'):
location = build_ref.locationsId
if location is not None:
cancel_name = 'projects/{project}/locations/{location}/builds/{buildId}'
name = cancel_name.format(
project=project_id, location=location, buildId=build_id)
client.projects_locations_builds.Cancel(
messages.CancelBuildRequest(
name=name))
else:
client.projects_builds.Cancel(
messages.CloudbuildProjectsBuildsCancelRequest(
projectId=project_id, id=build_id))
log.status.Print('Cancelled [{r}].'.format(r=six.text_type(build_ref)))
return _CancelBuildHandler

View File

@@ -0,0 +1,168 @@
# -*- 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.
"""Set up flags for creating or updating a Github Enterprise config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.builds import flags as build_flags
def AddGitHubEnterpriseConfigArgs(parser, update=False):
"""Sets up all the argparse flags for creating or updating a GHE config.
Args:
parser: An argparse.ArgumentParser-like object.
update: If true, use the version of the flags for updating a config.
Otherwise, use the version for creating a config.
Returns:
The parser argument with GitHub Enterprise config flags added in.
"""
parser.add_argument(
'--host-uri',
required=not update,
help='The host uri of the GitHub Enterprise Server.')
parser.add_argument(
'--app-id',
type=int,
required=not update,
help=(
'The app id of the GitHub app that should be associated with this'
' config.'
),
)
if not update:
parser.add_argument(
'--peered-network',
help="""\
VPC network that should be used when making calls to the GitHub Enterprise Server.
If not specified, calls will be made over the public internet.
""")
if update:
parser.add_argument(
'CONFIG',
help=
'The unique identifier of the GitHub Enterprise Config to be updated.'
)
parser.add_argument(
'--webhook-key',
help="""\
The unique identifier that Cloud Build expects to be set as the value for
the query field `webhook_key` on incoming webhook requests.
If this is not set, Cloud Build will generate one on the user's behalf.
""")
gcs_or_secretmanager = parser.add_mutually_exclusive_group(
required=not update)
gcs = gcs_or_secretmanager.add_argument_group(
'Cloud Storage location of the GitHub App credentials:')
gcs.add_argument(
'--gcs-bucket',
required=True,
help='The Cloud Storage bucket containing the credential payload.')
gcs.add_argument(
'--gcs-object',
required=True,
help='The Cloud Storage object containing the credential payload.')
gcs.add_argument(
'--generation',
type=int,
help="""\
The object generation to read the credential payload from.
If this is not set, Cloud Build will read the latest version.
""")
secretmanager = gcs_or_secretmanager.add_argument_group(
'Secret Manager resources of the GitHub App credentials:')
secretmanager.add_argument(
'--private-key-name',
required=True,
help='Secret Manager resource containing the private key.')
secretmanager.add_argument(
'--webhook-secret-name',
required=True,
help='Secret Manager resource containing the webhook key.')
secretmanager.add_argument(
'--oauth-secret-name',
required=True,
help='Secret Manager resource containing the oauth secret.')
secretmanager.add_argument(
'--oauth-client-id-name',
required=True,
help='Secret Manager resource containing the oauth client id.')
secretmanager.add_argument(
'--private-key-version-name',
help='Secret Manager SecretVersion resource containing the private key.'
)
secretmanager.add_argument(
'--webhook-secret-version-name',
help='Secret Manager SecretVersion resource containing the webhook key.'
)
secretmanager.add_argument(
'--oauth-secret-version-name',
help='Secret Manager SecretVersion resource containing the oauth secret.'
)
secretmanager.add_argument(
'--oauth-client-id-version-name',
help=
'Secret Manager SecretVersion resource containing the oauth client id.',
)
return parser
def AddGitHubEnterpriseConfigCreateArgs(parser):
"""Sets up all the argparse flags for creating a GitHub Enterprise Config.
Args:
parser: An argparse.ArgumentParser-like object.
Returns:
The parser argument with GitHub Enterprise Config flags added in.
"""
# Making region and name required together as name is only needed for creating
# regional GHE configs.
region = parser.add_argument_group()
region.add_argument(
'--name',
required=True,
help='The name of the GitHub Enterprise config.',
)
region.add_argument(
'--region',
required=True,
help=("""\
The region of the Cloud Build Service to use.\nMust be set to a supported region
name (e.g. `us-central1`).\nIf unset, `builds/region`, which is the default
region to use when working with Cloud Build resources, is used. If builds/region
is unset, region is set to `global`.
"""),
)
return AddGitHubEnterpriseConfigArgs(parser, update=False)
def AddGitHubEnterpriseConfigUpdateArgs(parser):
"""Sets up all the argparse flags for updating a GitHub Enterprise Config.
Args:
parser: An argparse.ArgumentParser-like object.
Returns:
The parser argument with GitHub Enterprise Config flags added in.
"""
build_flags.AddRegionFlag(parser)
return AddGitHubEnterpriseConfigArgs(parser, update=True)

View File

@@ -0,0 +1,107 @@
# -*- 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.
"""Set up flags for creating or updating a GitLab config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
def AddGitLabConfigArgs(parser, update=False):
"""Set up all the argparse flags for creating or updating a GitLab config.
Args:
parser: An argparse.ArgumentParser-like object.
update: If true, use the version of the flags for updating a config.
Otherwise, use the version for creating a config.
Returns:
The parser argument with GitLab config flags added in.
"""
parser.add_argument(
'--host-uri',
required=not update,
help='The host uri of the GitLab Enterprise instance.')
parser.add_argument(
'--user-name',
required=not update,
help='The GitLab user name that should be associated with this config.')
parser.add_argument(
'--api-key-secret-version',
required=not update,
help='Secret Manager resource containing the Cloud Build API key that should be associated with this config. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--api-access-token-secret-version',
required=not update,
help='Secret Manager resource containing the API access token. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--read-access-token-secret-version',
required=not update,
help='Secret Manager resource containing the read access token. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--webhook-secret-secret-version',
required=not update,
help='Secret Manager resource containing the webhook secret. The secret is specified in resource URL format projects/{secret_project}/secrets/{secret_name}/versions/{secret_version}.'
)
parser.add_argument(
'--ssl-ca-file',
type=arg_parsers.FileContents(),
help='Path to a local file that contains SSL certificate to use for requests to GitLab Enterprise. The certificate should be in PEM format.'
)
parser.add_argument(
'--service-directory-service',
help="""\
Service Directory service that should be used when making calls to the GitLab Enterprise instance.
If not specified, calls will be made over the public internet.
""")
if not update:
parser.add_argument(
'--name', required=True, help='The name of the GitLab config.')
parser.add_argument(
'--region',
required=True,
help='The Cloud location of the GitLab config.')
return parser
def AddGitLabConfigCreateArgs(parser):
"""Set up all the argparse flags for creating a GitLab config.
Args:
parser: An argparse.ArgumentParser-like object.
Returns:
The parser argument with GitLab config flags added in.
"""
return AddGitLabConfigArgs(parser, update=False)
def AddGitLabConfigUpdateArgs(parser):
"""Set up all the argparse flags for updating a GitLab config.
Args:
parser: An argparse.ArgumentParser-like object.
Returns:
The parser argument with GitLab config flags added in.
"""
return AddGitLabConfigArgs(parser, update=True)

View File

@@ -0,0 +1,32 @@
project:
name: project
collection: cloudbuild.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Cloud Project ID
disable_auto_completers: false
location:
name: location
collection: cloudbuild.projects.locations
attributes:
- *project
- &location
parameter_name: locationsId
attribute_name: location
help: Cloud Region
disable_auto_completers: false
build:
name: build
collection: cloudbuild.projects.locations.builds
attributes:
- *project
- *location
- &build
parameter_name: buildsId
attribute_name: build
help: Build ID
disable_auto_completers: false

View File

@@ -0,0 +1,79 @@
# -*- 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.
"""Shared resource flags for Cloud Build commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.calliope.concepts import deps
from googlecloudsdk.core import properties
def RegionAttributeConfig():
fallthroughs = [
deps.PropertyFallthrough(properties.VALUES.builds.region)
]
return concepts.ResourceParameterAttributeConfig(
name='region',
fallthroughs=fallthroughs,
help_text='The Cloud location for the {resource}.')
def GetTriggerResourceSpec():
return concepts.ResourceSpec(
'cloudbuild.projects.locations.triggers',
api_version='v1',
resource_name='trigger',
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
locationsId=RegionAttributeConfig(),
triggersId=TriggerAttributeConfig())
def TriggerAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='trigger',
help_text='Build Trigger ID')
def GetWorkflowResourceSpec():
return concepts.ResourceSpec(
'cloudbuild.projects.locations.workflows',
api_version='v2',
resource_name='workflow',
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
locationsId=RegionAttributeConfig(),
workflowsId=WorkflowAttributeConfig())
def WorkflowAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='workflow', help_text='Workflow ID')
def GetGitLabConfigResourceSpec():
return concepts.ResourceSpec(
'cloudbuild.projects.locations.gitLabConfigs',
api_version='v1',
resource_name='gitLabConfig',
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
locationsId=RegionAttributeConfig(),
gitLabConfigsId=GitLabConfigAttributeConfig())
def GitLabConfigAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='config', help_text='Config Name')

View File

@@ -0,0 +1,31 @@
project:
name: project
collection: cloudbuild.projects
attributes:
- &project
parameter_name: projectId
attribute_name: project
help: Cloud Project ID
disable_auto_completers: false
trigger:
name: trigger
collection: cloudbuild.projects.triggers
attributes:
- *project
- &trigger
parameter_name: triggerId
attribute_name: trigger
help: Build Trigger ID
disable_auto_completers: false
build:
name: build
collection: cloudbuild.projects.builds
attributes:
- *project
- &build
parameter_name: id
attribute_name: build
help: Build ID
disable_auto_completers: false

View File

@@ -0,0 +1,51 @@
project:
name: project
collection: cloudbuild.projects
attributes:
- &project
# For correct collection and parameter_names see
# $ blaze run //cloud/sdk/gcloud:gcloud -- meta apis collections list --api=cloudbuild --api-version=v2
parameter_name: projectsId
attribute_name: project
help: Cloud Project ID.
property: core/project
disable_auto_completers: false
# Naming this as region instead of location to keep consistency with worker-pools, workflows, etc.
region:
name: region
collection: cloudbuild.projects.locations
attributes:
- &region
parameter_name: locationsId
attribute_name: region
help: The Google Cloud region.
property: builds/region
disable_auto_completers: false
connection:
name: connection
collection: cloudbuild.projects.locations.connections
request_id_field: connectionId
attributes:
- *project
- *region
- &connection
parameter_name: connectionsId
attribute_name: connection
help: Connection ID.
disable_auto_completers: false
repository:
name: repository
collection: cloudbuild.projects.locations.connections.repositories
request_id_field: repositoryId
attributes:
- *project
- *region
- *connection
- &repository
parameter_name: repositoriesId
attribute_name: repository
help: Repository ID.
disable_auto_completers: false

View File

@@ -0,0 +1,62 @@
# -*- 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.
"""Set up flags for creating a PipelineRun/TaskRun."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.command_lib.cloudbuild import resource_args
from googlecloudsdk.command_lib.util.concepts import concept_parsers
def AddsCreateFlags(parser):
parser.add_argument(
'--file',
required=True,
help='The YAML file to use as the PipelineRun/TaskRun configuration file.'
)
AddsRegionResourceArg(parser)
def AddsRegionResourceArg(parser, is_required=True):
"""Add region resource argument to parser."""
region_resource_spec = concepts.ResourceSpec(
'cloudbuild.projects.locations',
resource_name='region',
locationsId=resource_args.RegionAttributeConfig(),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
concept_parsers.ConceptParser.ForResource(
'--region',
region_resource_spec,
'Region for Cloud Build.',
required=is_required).AddToParser(parser)
def AddsRunFlags(parser):
"""Add flags related to a run to parser."""
parser.add_argument('RUN_ID', help='The ID of the PipelineRun/TaskRun.')
parser.add_argument(
'--type',
choices=[
'pipelinerun',
'taskrun',
],
default='pipelinerun',
help='Type of Run.',
)
AddsRegionResourceArg(parser)

View File

@@ -0,0 +1,265 @@
# -*- 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.
"""Set up flags for creating or updating a workerpool."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import actions
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
_PWP_CONFIG_LINK = 'https://cloud.google.com/build/docs/private-pools/worker-pool-config-file-schema'
_CREATE_FILE_DESC = (
'File that contains the configuration for the'
' worker pool to be created. See %s for options.' % _PWP_CONFIG_LINK
)
_UPDATE_FILE_DESC = (
'File that contains updates to the configuration for'
' the worker pool. See %s for options.' % _PWP_CONFIG_LINK
)
_CREATE_FILE_DESC_ALPHA_BETA = (
'File that contains the configuration for the worker pool to be '
'created.\n\nPrivate pool options:\n\n %s\n\n' % (_PWP_CONFIG_LINK)
)
_UPDATE_FILE_DESC_ALPHA_BETA = (
'File that contains updates to the configuration for worker pool to be '
'created.\n\n'
'Private pool options:\n\n %s\n\n' % (_PWP_CONFIG_LINK)
)
DEFAULT_FLAG_VALUES = {
'BUILDER_IMAGE_CACHING': 'CACHING_DISABLED',
'DISK_SIZE': '60GB',
'MEMORY': '4.0GB',
'VCPU_COUNT': 1.0,
}
def AddWorkerpoolArgs(parser, release_track, update=False):
"""Set up all the argparse flags for creating or updating a workerpool.
Args:
parser: An argparse.ArgumentParser-like object.
release_track: A base.ReleaseTrack-like object.
update: If true, use the version of the flags for updating a workerpool.
Otherwise, use the version for creating a workerpool.
Returns:
The parser argument with workerpool flags added in.
"""
verb = 'update' if update else 'create'
parser.add_argument(
'WORKER_POOL',
help=(
'Unique identifier for the worker pool to %s. This value should be'
' 1-63 characters, and valid characters are [a-z][0-9]-'
)
% verb,
)
parser.add_argument(
'--region',
help=(
'Cloud region where the worker pool is %sd. See'
' https://cloud.google.com/build/docs/locations for available'
' locations.'
)
% verb,
)
file_or_flags = parser.add_mutually_exclusive_group(required=update)
if (
release_track != base.ReleaseTrack.ALPHA
and release_track != base.ReleaseTrack.BETA
):
file_or_flags.add_argument(
'--config-from-file',
help=(_UPDATE_FILE_DESC if update else _CREATE_FILE_DESC),
)
else:
file_or_flags.add_argument(
'--config-from-file',
help=(
_UPDATE_FILE_DESC_ALPHA_BETA
if update
else _CREATE_FILE_DESC_ALPHA_BETA
),
)
flags = file_or_flags.add_argument_group(
'Command-line flags to configure the private pool:'
)
network_flags = flags.add_mutually_exclusive_group()
service_network_flags = network_flags.add_argument_group(
'Network configuration for Service Networking:'
)
if not update:
service_network_flags.add_argument(
'--peered-network',
help="""\
Existing network to which workers are peered. The network is specified in
resource URL format
projects/{network_project}/global/networks/{network_name}.
If not specified, the workers are not peered to any network.
""",
)
service_network_flags.add_argument(
'--peered-network-ip-range',
help="""\
An IP range for your peered network. Specify the IP range using Classless
Inter-Domain Routing (CIDR) notation with a slash and the subnet prefix size,
such as `/29`.
Your subnet prefix size must be between 1 and 29. Optional: you can specify an
IP address before the subnet prefix value - for example `192.168.0.0/24`.
If no IP address is specified, your VPC automatically determines the starting
IP for the range. If no IP range is specified, Cloud Build uses `/24` as the
default network IP range.
""",
)
if (
release_track == base.ReleaseTrack.ALPHA
or release_track == base.ReleaseTrack.BETA
):
private_service_connect_flags = network_flags.add_argument_group(
'Network configuration for Private Service Connect interface:'
)
private_service_connect_flags.add_argument(
'--network-attachment',
help="""\
The network attachment that the worker network interface is peered to. The
network attachment is specified in resource URL format
projects/{project}/regions/{region}/networkAttachments/{name}.
The region of network attachment must be the same as the worker pool.
See https://cloud.google.com/vpc/docs/about-network-attachments for details.
""",
)
private_service_connect_flags.add_argument(
'--route-all-traffic',
action='store_true',
help="""\
Route all traffic through PSC interface. Enable this if you want full control
of traffic in the private pool. Configure Cloud NAT for the subnet of network
attachment if you need to access public Internet.
If unset, Only route private IPs, e.g. 10.0.0.0/8, 172.16.0.0/12,
and 192.168.0.0/16 through PSC interface.
""",
)
private_service_connect_flags.add_argument(
'--disable-public-ip-address',
action='store_true',
help="""\
If set, workers in the worker pool are created without an external IP address.
If the worker pool is within a VPC Service Control perimeter, use this flag.
""",
)
worker_flags = flags.add_argument_group(
'Configuration to be used for creating workers in the worker pool:'
)
worker_flags.add_argument(
'--worker-machine-type',
help="""\
Compute Engine machine type for a worker pool.
If unspecified, Cloud Build uses a standard machine type.
""",
)
worker_flags.add_argument(
'--worker-disk-size',
type=arg_parsers.BinarySize(lower_bound='100GB'),
help="""\
Size of the disk attached to the worker.
If unspecified, Cloud Build uses a standard disk size.
""",
)
if release_track == base.ReleaseTrack.GA:
worker_flags.add_argument(
'--no-external-ip',
hidden=release_track == base.ReleaseTrack.GA,
action=actions.DeprecationAction(
'--no-external-ip',
warn=(
'The `--no-external-ip` option is deprecated; use'
' `--no-public-egress` and/or `--public-egress instead`.'
),
removed=False,
action='store_true',
),
help="""\
If set, workers in the worker pool are created without an external IP address.
If the worker pool is within a VPC Service Control perimeter, use this flag.
""",
)
if update:
service_network_flags.add_argument(
'--public-egress',
action=arg_parsers.StoreTrueFalseAction,
help="""\
If set to true, workers in the worker pool are created with an external
IP address.
If set to false, workers in the worker pool are created without an
external IP address. If the worker pool is within a VPC Service Control
perimeter, use this flag.
""",
)
else:
service_network_flags.add_argument(
'--no-public-egress',
action='store_true',
help="""\
If set, workers in the worker pool are created without an external IP address.
If the worker pool is within a VPC Service Control perimeter, use this flag.
""",
)
return parser
def AddWorkerpoolCreateArgs(parser, release_track):
"""Set up all the argparse flags for creating a workerpool.
Args:
parser: An argparse.ArgumentParser-like object.
release_track: A base.ReleaseTrack-like object.
Returns:
The parser argument with workerpool flags added in.
"""
return AddWorkerpoolArgs(parser, release_track, update=False)
def AddWorkerpoolUpdateArgs(parser, release_track):
"""Set up all the argparse flags for updating a workerpool.
Args:
parser: An argparse.ArgumentParser-like object.
release_track: A base.ReleaseTrack-like object.
Returns:
The parser argument with workerpool flags added in.
"""
return AddWorkerpoolArgs(parser, release_track, update=True)