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,25 @@
# -*- 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.
"""Package for the services/operations CLI subcommands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class VpcPeerings(base.Group):
"""VPC Peerings to various services."""

View File

@@ -0,0 +1,110 @@
# -*- 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.
"""services vpc-peerings connect command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.cloudresourcemanager import projects_api
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
OP_BASE_CMD = 'gcloud services vpc-peerings operations '
OP_WAIT_CMD = OP_BASE_CMD + 'wait {0}'
class Connect(base.SilentCommand):
"""Connect to a service via VPC peering for a project network."""
detailed_help = {
'DESCRIPTION':
"""\
This command connects a private service connection to a service via a
VPC network.
""",
'EXAMPLES':
"""\
To connect a network called `my-network` on the current project to a
service called `your-service` with IP CIDR ranges
`google-range-1,google-range-2` for the service to use, run:
$ {command} --network=my-network --service=your-service \\
--ranges=google-range-1,google-range-2
To run the same command asynchronously (non-blocking), run:
$ {command} --network=my-network --service=your-service \\
--ranges=google-range-1,google-range-2 --async
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help='The network in the current project to be peered with the service')
parser.add_argument(
'--service',
metavar='SERVICE',
default='servicenetworking.googleapis.com',
help='The service to connect to')
parser.add_argument(
'--ranges',
metavar='RANGES',
required=True,
help='The names of IP CIDR ranges for service to use.')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run 'services vpc-peerings connect'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
Nothing.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = _GetProjectNumber(project)
ranges = args.ranges.split(',')
op = peering.CreateConnection(project_number, args.service, args.network,
ranges)
if args.async_:
cmd = OP_WAIT_CMD.format(op.name)
log.status.Print('Asynchronous operation is in progress... '
'Use the following command to wait for its '
'completion:\n {0}'.format(cmd))
return
op = services_util.WaitOperation(op.name, peering.GetOperation)
services_util.PrintOperation(op)
def _GetProjectNumber(project_id):
return projects_api.Get(projects_util.ParseProject(project_id)).projectNumber

View File

@@ -0,0 +1,106 @@
# -*- 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.
"""services vpc-peerings delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.cloudresourcemanager import projects_api
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
OP_BASE_CMD = 'gcloud services vpc-peerings operations '
OP_WAIT_CMD = OP_BASE_CMD + 'wait {0}'
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.GA,
)
class Delete(base.SilentCommand):
"""Delete a private service connection to a service for a project network."""
detailed_help = {
'DESCRIPTION':
"""\
This command deletes a private service connection to a service via a
VPC network.
""",
'EXAMPLES':
"""\
To delete an existing connection for a network called `my-network` on
the current project to a service called `your-service` run:
$ {command} --network=my-network --service=your-service
To run the same command asynchronously (non-blocking), run:
$ {command} --network=my-network --service=your-service --async
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help='The network in the current project which is peered with the service'
)
parser.add_argument(
'--service',
metavar='SERVICE',
default='servicenetworking.googleapis.com',
help='The service to connect to')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run 'services vpc-peerings delete'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
Nothing.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = _GetProjectNumber(project)
op = peering.DeleteConnection(project_number, args.service, args.network)
if args.async_:
cmd = OP_WAIT_CMD.format(op.name)
log.status.Print('Asynchronous operation is in progress... '
'Use the following command to wait for its '
'completion:\n {0}'.format(cmd))
return
op = services_util.WaitOperation(op.name, peering.GetOperation)
services_util.PrintOperation(op)
def _GetProjectNumber(project_id):
return projects_api.Get(projects_util.ParseProject(project_id)).projectNumber

View File

@@ -0,0 +1,109 @@
# -*- 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.
"""services vpc-peerings disable-vpc-service-controls command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.cloudresourcemanager import projects_api
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
OP_BASE_CMD = 'gcloud services vpc-peerings operations '
OP_WAIT_CMD = OP_BASE_CMD + 'wait {0}'
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.GA,
)
class DisableVpcServiceControls(base.SilentCommand):
"""Disable VPC Service Controls for the peering connection."""
detailed_help = {
'DESCRIPTION':
"""\
This command disables VPC Service Controls for the peering connection.
The local default route (destination 0.0.0.0/0, next hop default
internet gateway) is recreated in the service producer VPC network.
After the route is recreated, the service producer VPC network cannot
import a custom default route from the peering connection to the
customer VPC network.
""",
'EXAMPLES':
"""\
To disable VPC Service Controls for a connection peering a network
called `my-network` on the current project to a service called
`your-service`, run:
$ {command} --network=my-network --service=your-service
To run the same command asynchronously (non-blocking), run:
$ {command} --network=my-network --service=your-service --async
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that can be used to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help='The network in the current project that is peered with the service.'
)
parser.add_argument(
'--service',
metavar='SERVICE',
default='servicenetworking.googleapis.com',
help='The service to enable VPC service controls for.')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run 'services vpc-peerings enable-vpc-service-controls'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = _GetProjectNumber(project)
op = peering.DisableVpcServiceControls(project_number, args.service,
args.network)
if args.async_:
cmd = OP_WAIT_CMD.format(op.name)
log.status.Print('Asynchronous operation is in progress... '
'Use the following command to wait for its '
'completion:\n {0}'.format(cmd))
return
op = services_util.WaitOperation(op.name, peering.GetOperation)
services_util.PrintOperation(op)
def _GetProjectNumber(project_id):
return projects_api.Get(projects_util.ParseProject(project_id)).projectNumber

View File

@@ -0,0 +1,131 @@
# -*- 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.
"""services vpc-peerings enable-vpc-service-controls command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.cloudresourcemanager import projects_api
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
OP_BASE_CMD = 'gcloud services vpc-peerings operations '
OP_WAIT_CMD = OP_BASE_CMD + 'wait {0}'
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.GA,
)
class EnableVpcServiceControls(base.SilentCommand):
"""Enable VPC Service Controls for the peering connection."""
detailed_help = {
'DESCRIPTION':
"""\
This command configures IPv4 routes and DNS zones applicable to a
service producer VPC network (for example, servicenetworking). The
route and DNS configuration match those recommended for using the
restricted.googleapis.com VIP:
When enabled, Google Cloud makes the following route configuration
changes in the service producer VPC network: Google Cloud removes the
IPv4 default route (destination 0.0.0.0/0, next hop default internet
gateway). Google Cloud then creates an IPv4 route for destination
199.36.153.4/30 using the default internet gateway next hop.
When enabled, Google Cloud also creates Cloud DNS managed private
zones and authorizes those zones for the service producer VPC network.
The zones include googleapis.com, pkg.dev, gcr.io, and other necessary
domains or host names for Google APIs and services that are compatible
with VPC Service Controls. Record data in the zones resolves all host
names to 199.36.153.4, 199.36.153.5, 199.36.153.6, and 199.36.153.7.
When disabled, Google Cloud makes the following route configuration
changes in the service producer VPC network: Google Cloud restores a
default route (destination 0.0.0.0/0, next hop default internet
gateway). Google Cloud also deletes the Cloud DNS managed private
zones that provided the host name overrides.
While enabled, the service producer VPC network can still import
static and dynamic routes from the peered customer network if you
enable custom route export. These custom routes can include a default
route. For this reason, this command is not to be used solely as a
means for preventing access to the internet.
""",
'EXAMPLES':
"""\
To enable VPC Service Controls for a connection peering a network
called `my-network` on the current project to a service called
`your-service`, run:
$ {command} --network=my-network --service=your-service
To run the same command asynchronously (non-blocking), run:
$ {command} --network=my-network --service=your-service --async
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that can be used to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help='The network in the current project that is peered with the service.'
)
parser.add_argument(
'--service',
metavar='SERVICE',
default='servicenetworking.googleapis.com',
help='The service to enable VPC service controls for.')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run 'services vpc-peerings enable-vpc-service-controls'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = _GetProjectNumber(project)
op = peering.EnableVpcServiceControls(project_number, args.service,
args.network)
if args.async_:
cmd = OP_WAIT_CMD.format(op.name)
log.status.Print('Asynchronous operation is in progress... '
'Use the following command to wait for its '
'completion:\n {0}'.format(cmd))
return
op = services_util.WaitOperation(op.name, peering.GetOperation)
services_util.PrintOperation(op)
def _GetProjectNumber(project_id):
return projects_api.Get(projects_util.ParseProject(project_id)).projectNumber

View File

@@ -0,0 +1,114 @@
# -*- 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.
"""services vpc-peerings get-vpc-service-controls command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import properties
@base.DefaultUniverseOnly
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class GetVpcServiceControls(base.DescribeCommand):
"""Get VPC state of Service Controls for the peering connection."""
detailed_help = {
'DESCRIPTION': """\
This command provides the state of the VPC Service Controls for a
connection. The state can be enabled or disabled.
When enabled, Google Cloud makes the following route configuration
changes in the service producer VPC network: Google Cloud removes the
IPv4 default route (destination 0.0.0.0/0, next hop default internet
gateway), Google Cloud then creates an IPv4 route for destination
199.36.153.4/30 using the default internet gateway next hop.
When enabled, Google Cloud also creates Cloud DNS managed private
zones and authorizes those zones for the service producer VPC network.
The zones include googleapis.com, gcr.io, pkg.dev,
notebooks.cloud.google.com, kernels.googleusercontent.com,
backupdr.cloud.google.com, and backupdr.googleusercontent.com
as necessary domains or host names for Google APIs and services that are
compatible with VPC Service Controls. Record data in the zones resolves
all host names to 199.36.153.4, 199.36.153.5, 199.36.153.6, and
199.36.153.7.
When disabled, Google Cloud makes the following route configuration
changes in the service producer VPC network: Google Cloud restores a
default route (destination 0.0.0.0/0, next hop default internet
gateway), Google Cloud also deletes the Cloud DNS managed private
zones that provided the host name overrides.
While enabled, the service producer VPC network can still import
static and dynamic routes from the peered customer network if you
enable custom route export. These custom routes can include a default
route. For this reason, this command is not to be used solely as a
means for preventing access to the internet.
""",
'EXAMPLES': """\
To get the status of the VPC Service Controls for a connection peering
a network called `my-network` on the current project to a service called
`your-service`, run:
$ {command} --network=my-network --service=your-service
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that can be used to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help=(
'The network in the current project that is peered with the'
' service.'
),
)
parser.add_argument(
'--service',
metavar='SERVICE',
default='servicenetworking.googleapis.com',
help='The service to get VPC service controls for.',
)
def Run(self, args):
"""Run 'services vpc-peerings get-vpc-service-controls'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The state of the Vpc Service Controls, that is enabled or disabled.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = projects_util.GetProjectNumber(project)
return peering.GetVpcServiceControls(
project_number, args.service, args.network
)

View File

@@ -0,0 +1,89 @@
# -*- 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.
"""services vpc-peerings list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import properties
_DETAILED_HELP = {
'DESCRIPTION':
"""\
This command lists connections of a network to a service via VPC peering
for a project.
""",
'EXAMPLES':
"""\
To list connections of a network called `my-network` to a service called
`your-service`, run:
$ {command} --network=my-network --service=your-service
To list connections of a network against all services, run:
$ {command} --network=my-network
""",
}
# TODO(b/125365973): add e2e test for list command.
class List(base.DescribeCommand):
"""List connections to a service via VPC peering for a project network."""
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help='The network in the current project to list connections with the service'
)
parser.add_argument(
'--service',
metavar='SERVICE',
default='',
help='The service to list connections')
def Run(self, args):
"""Run 'services vpc-peerings list'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The list of connections.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = projects_util.GetProjectNumber(project)
service = args.service if args.IsSpecified('service') else '-'
conns = peering.ListConnections(project_number, service, args.network)
return iter(conns)
List.detailed_help = _DETAILED_HELP

View File

@@ -0,0 +1,25 @@
# -*- 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.
"""Package for the services/operations CLI subcommands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Operations(base.Group):
"""Manage VPC Peering operations."""

View File

@@ -0,0 +1,66 @@
# -*- 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.
"""services operations describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
_NAME_HELP = """The name of operation to describe"""
class Describe(base.DescribeCommand):
# pylint: disable=line-too-long
"""Describes an operation resource for a given operation name.
This command will return information about an operation given the name
of that operation.
## EXAMPLES
To describe an operation resource named
`operations/abc`, run:
$ {command} --name=operations/abc
"""
# pylint: enable=line-too-long
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
parser.add_argument(
'--name', metavar='OPERATION_NAME', required=True, help=_NAME_HELP)
def Run(self, args):
"""Run 'services operations describe'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
Nothing.
"""
op = peering.GetOperation(args.name)
services_util.PrintOperation(op)

View File

@@ -0,0 +1,64 @@
# -*- 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.
"""service-management operations wait command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
_NAME_HELP = 'The name of operation to wait'
class Wait(base.Command):
"""Waits for an operation to complete for a given operation name.
This command will block until an operation has been marked as complete.
## EXAMPLES
To wait on an operation named `operations/abc`
to complete, run:
$ {command} --name=operations/abc
"""
# pylint: enable=line-too-long
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
parser.add_argument(
'--name', metavar='OPERATION_NAME', required=True, help=_NAME_HELP)
def Run(self, args):
"""Run 'services operations wait'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
Nothing.
"""
op = services_util.WaitOperation(args.name, peering.GetOperation)
services_util.PrintOperation(op)

View File

@@ -0,0 +1,113 @@
# -*- 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.
"""services vpc-peerings update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.cloudresourcemanager import projects_api
from googlecloudsdk.api_lib.services import peering
from googlecloudsdk.api_lib.services import services_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
OP_BASE_CMD = 'gcloud services vpc-peerings operations '
OP_WAIT_CMD = OP_BASE_CMD + 'wait {0}'
class Update(base.SilentCommand):
"""Update a private service connection to a service for a project network."""
detailed_help = {
'DESCRIPTION':
"""\
This command updates a private service connection to a service via a
VPC network.
""",
'EXAMPLES':
"""\
To update connection for a network called `my-network` on the current
project to a service called `your-service` with IP CIDR ranges
`google-range-1,google-range-2` for the service to use, run:
$ {command} --network=my-network --service=your-service \\
--ranges=google-range-1,google-range-2
To run the same command asynchronously (non-blocking), run:
$ {command} --network=my-network --service=your-service \\
--ranges=google-range-1,google-range-2 --async
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go on
the command line after this command. Positional arguments are allowed.
"""
parser.add_argument(
'--network',
metavar='NETWORK',
required=True,
help='The network in the current project to be peered with the service')
parser.add_argument(
'--service',
metavar='SERVICE',
default='servicenetworking.googleapis.com',
help='The service to connect to')
parser.add_argument(
'--ranges',
metavar='RANGES',
help='The names of IP CIDR ranges for service to use.')
parser.add_argument(
'--force',
action='store_true',
help='If specified, the update call will proceed even if the update '
'can be destructive.')
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
"""Run 'services vpc-peerings connect'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
"""
project = properties.VALUES.core.project.Get(required=True)
project_number = _GetProjectNumber(project)
if args.ranges:
ranges = args.ranges.split(',')
op = peering.UpdateConnection(project_number, args.service, args.network,
ranges, args.force)
if args.async_:
cmd = OP_WAIT_CMD.format(op.name)
log.status.Print('Asynchronous operation is in progress... '
'Use the following command to wait for its '
'completion:\n {0}'.format(cmd))
return
op = services_util.WaitOperation(op.name, peering.GetOperation)
services_util.PrintOperation(op)
def _GetProjectNumber(project_id):
return projects_api.Get(projects_util.ParseProject(project_id)).projectNumber