feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*- #
# Copyright 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.
"""Provide commands for managing AlloyDB instances."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Clusters(base.Group):
"""Provide commands for managing AlloyDB instances.
Provide commands for managing AlloyDB clusters including creating,
configuring, restarting, and deleting instances.
"""

View File

@@ -0,0 +1,194 @@
# -*- 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.
"""Creates a new AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.command_lib.alloydb import instance_helper
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
# TODO(b/312466999): Change @base.DefaultUniverseOnly to
# @base.UniverseCompatible once b/312466999 is fixed.
# See go/gcloud-cli-running-tpc-tests.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Creates a new AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To create a new primary instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1 --instance-type=PRIMARY --cpu-count=4
To create a new read pool instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1 --instance-type=READ_POOL --read-pool-node-count=1 --cpu-count=4
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser: Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
flags.AddAvailabilityType(parser)
flags.AddCluster(parser, False)
flags.AddDatabaseFlags(parser)
flags.AddInstance(parser)
flags.AddInstanceType(parser)
flags.AddCPUCount(parser, required=False)
flags.AddMachineType(parser)
flags.AddReadPoolNodeCount(parser)
flags.AddRegion(parser)
flags.AddInsightsConfigQueryStringLength(parser)
flags.AddInsightsConfigQueryPlansPerMinute(parser)
flags.AddInsightsConfigRecordApplicationTags(
parser, show_negated_in_help=True
)
flags.AddInsightsConfigRecordClientAddress(
parser, show_negated_in_help=True
)
flags.AddSSLMode(parser)
flags.AddRequireConnectors(parser)
flags.AddAssignInboundPublicIp(parser)
flags.AddAuthorizedExternalNetworks(parser)
flags.AddOutboundPublicIp(parser, show_negated_in_help=True)
flags.AddAllowedPSCProjects(parser)
flags.AddPSCNetworkAttachmentUri(parser)
flags.AddPSCAutoConnections(parser)
flags.AddAllocatedIPRangeOverride(parser)
# Connection pooling flags.
flags.AddEnableConnectionPooling(parser)
flags.AddConnectionPoolingPoolMode(parser)
flags.AddConnectionPoolingMinPoolSize(parser)
flags.AddConnectionPoolingMaxPoolSize(parser)
flags.AddConnectionPoolingMaxClientConnections(parser)
flags.AddConnectionPoolingServerIdleTimeout(parser)
flags.AddConnectionPoolingQueryWaitTimeout(parser)
flags.AddConnectionPoolingStatsUsers(parser)
flags.AddConnectionPoolingIgnoreStartupParameters(parser)
flags.AddConnectionPoolingServerLifetime(parser)
flags.AddConnectionPoolingClientConnectionIdleTimeout(parser)
flags.AddConnectionPoolingMaxPreparedStatements(parser)
# TODO(b/185795425): Add --ssl-required and --labels later once we
# understand the use cases
def ConstructCreateRequestFromArgs(
self, client, alloydb_messages, cluster_ref, args
):
return instance_helper.ConstructCreateRequestFromArgsGA(
client, alloydb_messages, cluster_ref, args
)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
cluster_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster)
req = self.ConstructCreateRequestFromArgs(
client, alloydb_messages, cluster_ref, args
)
op = alloydb_client.projects_locations_clusters_instances.Create(req)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations')
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(op_ref, 'Creating instance',
self.ReleaseTrack())
return op
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateBeta(Create):
"""Creates a new AlloyDB instance within a given cluster."""
@classmethod
def Args(cls, parser):
super(CreateBeta, CreateBeta).Args(parser)
flags.AddObservabilityConfigEnabled(
parser, show_negated_in_help=True
)
flags.AddObservabilityConfigPreserveComments(
parser, show_negated_in_help=True
)
flags.AddObservabilityConfigTrackWaitEvents(
parser, show_negated_in_help=False
)
flags.AddObservabilityConfigMaxQueryStringLength(parser)
flags.AddObservabilityConfigRecordApplicationTags(
parser, show_negated_in_help=True
)
flags.AddObservabilityConfigQueryPlansPerMinute(parser)
flags.AddObservabilityConfigTrackActiveQueries(
parser, show_negated_in_help=True
)
flags.AddAutoscalerCreateFlags(parser)
def ConstructCreateRequestFromArgs(
self, client, alloydb_messages, cluster_ref, args
):
return instance_helper.ConstructCreateRequestFromArgsBeta(
client, alloydb_messages, cluster_ref, args
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateAlpha(CreateBeta):
"""Creates a new AlloyDB instance within a given cluster."""
@classmethod
def Args(cls, parser):
super(CreateAlpha, CreateAlpha).Args(parser)
def ConstructCreateRequestFromArgs(
self, client, alloydb_messages, cluster_ref, args
):
return instance_helper.ConstructCreateRequestFromArgsAlpha(
client, alloydb_messages, cluster_ref, args
)

View File

@@ -0,0 +1,158 @@
# -*- 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.
"""Creates a new AlloyDB secondary instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.command_lib.alloydb import instance_helper
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
# TODO(b/312466999): Change @base.DefaultUniverseOnly to
# @base.UniverseCompatible once b/312466999 is fixed.
# See go/gcloud-cli-running-tpc-tests.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateSecondary(base.CreateCommand):
"""Creates a new AlloyDB SECONDARY instance within a given cluster."""
detailed_help = {
'DESCRIPTION': '{description}',
'EXAMPLES': """\
To create a new secondary instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser: Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
flags.AddCluster(parser, False)
flags.AddAvailabilityType(parser)
flags.AddInstance(parser)
flags.AddRegion(parser)
flags.AddDatabaseFlags(parser)
flags.AddSSLMode(parser, default_from_primary=True)
flags.AddRequireConnectors(parser)
flags.AddAssignInboundPublicIp(parser)
flags.AddAuthorizedExternalNetworks(parser)
flags.AddOutboundPublicIp(parser, show_negated_in_help=True)
flags.AddAllowedPSCProjects(parser)
flags.AddPSCNetworkAttachmentUri(parser)
flags.AddPSCAutoConnections(parser)
flags.AddAllocatedIPRangeOverride(parser)
# Connection pooling flags.
flags.AddEnableConnectionPooling(parser)
flags.AddConnectionPoolingPoolMode(parser)
flags.AddConnectionPoolingMinPoolSize(parser)
flags.AddConnectionPoolingMaxPoolSize(parser)
flags.AddConnectionPoolingMaxClientConnections(parser)
flags.AddConnectionPoolingServerIdleTimeout(parser)
flags.AddConnectionPoolingQueryWaitTimeout(parser)
flags.AddConnectionPoolingStatsUsers(parser)
flags.AddConnectionPoolingIgnoreStartupParameters(parser)
flags.AddConnectionPoolingServerLifetime(parser)
flags.AddConnectionPoolingClientConnectionIdleTimeout(parser)
flags.AddConnectionPoolingMaxPreparedStatements(parser)
def ConstructSecondaryCreateRequestFromArgs(
self, client, alloydb_messages, cluster_ref, args
):
return instance_helper.ConstructSecondaryCreateRequestFromArgsGA(
client, alloydb_messages, cluster_ref, args
)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
cluster_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
)
req = self.ConstructSecondaryCreateRequestFromArgs(
client, alloydb_messages, cluster_ref, args
)
op = alloydb_client.projects_locations_clusters_instances.Createsecondary(
req
)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations'
)
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(
op_ref, 'Creating secondary instance', self.ReleaseTrack()
)
return op
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateSecondaryBeta(CreateSecondary):
"""Creates a new AlloyDB SECONDARY instance within a given cluster."""
@classmethod
def Args(cls, parser):
super(CreateSecondaryBeta, CreateSecondaryBeta).Args(parser)
def ConstructSecondaryCreateRequestFromArgs(
self, client, alloydb_messages, cluster_ref, args
):
return instance_helper.ConstructSecondaryCreateRequestFromArgsBeta(
client, alloydb_messages, cluster_ref, args
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateSecondaryAlpha(CreateSecondaryBeta):
"""Creates a new AlloyDB SECONDARY instance within a given cluster."""
@classmethod
def Args(cls, parser):
super(CreateSecondaryAlpha, CreateSecondaryAlpha).Args(parser)
def ConstructSecondaryCreateRequestFromArgs(
self, client, alloydb_messages, cluster_ref, args
):
return instance_helper.ConstructSecondaryCreateRequestFromArgsAlpha(
client, alloydb_messages, cluster_ref, args
)

View File

@@ -0,0 +1,94 @@
# -*- 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.
"""Deletes an AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Deletes an AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To delete an instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser, Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
flags.AddCluster(parser, False)
flags.AddInstance(parser)
flags.AddRegion(parser)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
instance_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters.instances',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
instancesId=args.instance)
prompt_message = (
'Instance settings and IPs will be deleted on upon deletion.')
if not console_io.PromptContinue(message=prompt_message):
return None
req = alloydb_messages.AlloydbProjectsLocationsClustersInstancesDeleteRequest(
name=instance_ref.RelativeName())
op = alloydb_client.projects_locations_clusters_instances.Delete(req)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations')
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(op_ref, 'Deleting instance', self.ReleaseTrack(), False)
return op

View File

@@ -0,0 +1,88 @@
# -*- 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.
"""Describes an AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.core import properties
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describes an AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To describe an instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1
--view=BASIC/FULL
""",
}
@classmethod
def Args(cls, parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser: Parser object for command line inputs
"""
alloydb_messages = api_util.GetMessagesModule(cls.ReleaseTrack())
flags.AddCluster(parser, False)
flags.AddInstance(parser)
flags.AddRegion(parser)
flags.AddView(parser, alloydb_messages)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
instance_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters.instances',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
instancesId=args.instance)
if args.view:
req = alloydb_messages.AlloydbProjectsLocationsClustersInstancesGetRequest(
name=instance_ref.RelativeName(),
view=flags.GetInstanceViewFlagMapper(
alloydb_messages).GetEnumForChoice(args.view))
else:
req = alloydb_messages.AlloydbProjectsLocationsClustersInstancesGetRequest(
name=instance_ref.RelativeName())
op = alloydb_client.projects_locations_clusters_instances.Get(req)
return op

View File

@@ -0,0 +1,86 @@
# -*- 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.
"""Failover an AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Failover(base.SilentCommand):
"""Failover an AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To failover an instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser, Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
flags.AddCluster(parser, False)
flags.AddInstance(parser)
flags.AddRegion(parser)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
project_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters.instances',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
instancesId=args.instance)
req = alloydb_messages.AlloydbProjectsLocationsClustersInstancesFailoverRequest(
name=project_ref.RelativeName())
op = alloydb_client.projects_locations_clusters_instances.Failover(req)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations')
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(op_ref, 'Failing over instance',
self.ReleaseTrack(), False)
return op

View File

@@ -0,0 +1,96 @@
# -*- 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.
"""Inject fault on an AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class InjectFault(base.SilentCommand):
"""Inject fault on an AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION': '{description}',
'EXAMPLES': """\
To Inject fault on an instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1 --fault-type=stop-vm
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser, Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
flags.AddCluster(parser, False)
flags.AddInstance(parser)
flags.AddRegion(parser)
flags.AddFaultType(parser, True)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
fault_type = flags.GetInjectFaultTypeFlagMapper(
alloydb_messages
).GetEnumForChoice(args.fault_type)
project_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters.instances',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
instancesId=args.instance,
)
req = alloydb_messages.AlloydbProjectsLocationsClustersInstancesInjectFaultRequest(
name=project_ref.RelativeName(),
injectFaultRequest=alloydb_messages.InjectFaultRequest(
faultType=fault_type
),
)
op = alloydb_client.projects_locations_clusters_instances.InjectFault(req)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations'
)
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(
op_ref, 'Injecting fault over instance', self.ReleaseTrack(), False
)
return op

View File

@@ -0,0 +1,103 @@
# -*- 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.
"""Lists AlloyDB instances in a given cluster."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
_INSTANCE_FORMAT = """
table(
name,
instanceType:label="INSTANCE_TYPE",
state:label=STATUS
)
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class List(base.ListCommand):
"""Lists AlloyDB instances in a given cluster."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list instances, run:
$ {command} --cluster=my-cluster --region=us-central1
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser: Parser object for command line inputs
"""
cluster_args = parser.add_argument_group(help='Cluster')
cluster_args.add_argument(
'--region',
required=True,
default='-',
help=('Regional location (e.g. asia-east1, us-east1) of CLUSTER. '
'See the full list of regions at '
'https://cloud.google.com/sql/docs/instance-locations. '
'Default: list clusters in all regions.'))
cluster_args.add_argument(
'--cluster',
required=True,
default='-',
help=('AlloyDB cluster ID'))
parser.display_info.AddFormat(_INSTANCE_FORMAT)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
cluster_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster)
result = api_util.YieldFromListHandlingUnreachable(
alloydb_client.projects_locations_clusters_instances,
alloydb_messages
.AlloydbProjectsLocationsClustersInstancesListRequest(
parent=cluster_ref.RelativeName()),
field='instances',
limit=args.limit,
batch_size=args.page_size,
batch_size_attribute='pageSize')
return result

View File

@@ -0,0 +1,105 @@
# -*- 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.
"""Restarts an AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.command_lib.alloydb import instance_helper
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
# TODO(b/312466999): Change @base.DefaultUniverseOnly to
# @base.UniverseCompatible once b/312466999 is fixed.
# See go/gcloud-cli-running-tpc-tests
@base.DefaultUniverseOnly
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
class Restart(base.SilentCommand):
"""Restarts an AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION': '{description}',
'EXAMPLES': """\
To restart an instance, run:
$ {command} my-instance --cluster=my-cluster --region=us-central1
""",
}
@staticmethod
def Args(parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser, Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
flags.AddCluster(parser, False)
flags.AddInstance(parser)
flags.AddRegion(parser)
flags.AddNodeIds(parser)
def ConstructRestartRequest(self, **kwargs):
return instance_helper.ConstructRestartRequestFromArgs(
kwargs.get('alloydb_messages'),
kwargs.get('project_ref'),
kwargs.get('args'),
)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
project_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters.instances',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
instancesId=args.instance,
)
req = self.ConstructRestartRequest(
alloydb_messages=alloydb_messages,
project_ref=project_ref,
args=args
)
op = alloydb_client.projects_locations_clusters_instances.Restart(req)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations'
)
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(
op_ref, 'Restarting instance', self.ReleaseTrack(), False
)
return op

View File

@@ -0,0 +1,192 @@
# -*- 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.
"""Updates an AlloyDB instance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.alloydb import api_util
from googlecloudsdk.api_lib.alloydb import instance_operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.alloydb import flags
from googlecloudsdk.command_lib.alloydb import instance_helper
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
# TODO(b/312466999): Change @base.DefaultUniverseOnly to
# @base.UniverseCompatible once b/312466999 is fixed.
# See go/gcloud-cli-running-tpc-tests.
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Updates an AlloyDB instance within a given cluster."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To update the number of nodes in the read pool, run:
$ {command} my-read-instance --cluster=my-cluster --region=us-central1 --read-pool-node-count=3
""",
}
@classmethod
def Args(cls, parser):
"""Specifies additional command flags.
Args:
parser: argparse.Parser, Parser object for command line inputs
"""
base.ASYNC_FLAG.AddToParser(parser)
alloydb_messages = api_util.GetMessagesModule(cls.ReleaseTrack())
# Update runs for a long time, it is better to default to async mode so that
# users can query the operation status and find the status.
base.ASYNC_FLAG.SetDefault(parser, True)
flags.AddAvailabilityType(parser)
flags.AddCluster(parser, False)
flags.AddDatabaseFlags(parser)
flags.AddInstance(parser)
flags.AddCPUCount(parser, required=False)
flags.AddMachineType(parser, required=False)
flags.AddReadPoolNodeCount(parser)
flags.AddRegion(parser)
flags.AddInsightsConfigQueryStringLength(parser)
flags.AddInsightsConfigQueryPlansPerMinute(parser)
flags.AddInsightsConfigRecordApplicationTags(
parser, show_negated_in_help=True
)
flags.AddInsightsConfigRecordClientAddress(
parser, show_negated_in_help=True
)
flags.AddSSLMode(parser, update=True)
flags.AddRequireConnectors(parser)
flags.AddAssignInboundPublicIp(parser)
flags.AddAuthorizedExternalNetworks(parser)
flags.AddOutboundPublicIp(parser, show_negated_in_help=True)
flags.AddAllowedPSCProjects(parser)
flags.AddPSCNetworkAttachmentUri(parser)
flags.ClearPSCNetworkAttachmentUri(parser)
flags.AddPSCAutoConnectionGroup(parser)
flags.AddActivationPolicy(parser, alloydb_messages)
# Connection pooling flags.
flags.AddEnableConnectionPooling(parser)
flags.AddConnectionPoolingPoolMode(parser)
flags.AddConnectionPoolingMinPoolSize(parser)
flags.AddConnectionPoolingMaxPoolSize(parser)
flags.AddConnectionPoolingMaxClientConnections(parser)
flags.AddConnectionPoolingServerIdleTimeout(parser)
flags.AddConnectionPoolingQueryWaitTimeout(parser)
flags.AddConnectionPoolingStatsUsers(parser)
flags.AddConnectionPoolingIgnoreStartupParameters(parser)
flags.AddConnectionPoolingServerLifetime(parser)
flags.AddConnectionPoolingClientConnectionIdleTimeout(parser)
flags.AddConnectionPoolingMaxPreparedStatements(parser)
# TODO(b/185795425): Add --ssl-required and --labels later once we
# understand the use cases
def ConstructPatchRequestFromArgs(self, alloydb_messages, instance_ref, args):
return instance_helper.ConstructPatchRequestFromArgs(
alloydb_messages, instance_ref, args)
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
Returns:
ProcessHttpResponse of the request made.
"""
client = api_util.AlloyDBClient(self.ReleaseTrack())
alloydb_client = client.alloydb_client
alloydb_messages = client.alloydb_messages
instance_ref = client.resource_parser.Create(
'alloydb.projects.locations.clusters.instances',
projectsId=properties.VALUES.core.project.GetOrFail,
locationsId=args.region,
clustersId=args.cluster,
instancesId=args.instance,
)
req = self.ConstructPatchRequestFromArgs(
alloydb_messages, instance_ref, args
)
op = alloydb_client.projects_locations_clusters_instances.Patch(req)
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='alloydb.projects.locations.operations'
)
log.status.Print('Operation ID: {}'.format(op_ref.Name()))
if not args.async_:
instance_operations.Await(
op_ref, 'Updating instance', self.ReleaseTrack(), False
)
return op
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateBeta(Update):
"""Updates an AlloyDB instance within a given cluster."""
@classmethod
def Args(cls, parser):
super(UpdateBeta, cls).Args(parser)
flags.AddUpdateMode(parser)
flags.AddObservabilityConfigEnabled(
parser, show_negated_in_help=True
)
flags.AddObservabilityConfigPreserveComments(
parser, show_negated_in_help=True
)
flags.AddObservabilityConfigTrackWaitEvents(
parser, show_negated_in_help=False
)
flags.AddObservabilityConfigMaxQueryStringLength(parser)
flags.AddObservabilityConfigRecordApplicationTags(
parser, show_negated_in_help=True
)
flags.AddObservabilityConfigQueryPlansPerMinute(parser)
flags.AddObservabilityConfigTrackActiveQueries(
parser, show_negated_in_help=True
)
flags.AddAutoscalerUpdateFlags(parser)
def ConstructPatchRequestFromArgs(self, alloydb_messages, instance_ref, args):
return instance_helper.ConstructPatchRequestFromArgsBeta(
alloydb_messages, instance_ref, args
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateAlpha(UpdateBeta):
"""Updates an AlloyDB instance within a given cluster."""
@classmethod
def Args(cls, parser):
super(UpdateAlpha, cls).Args(parser)
def ConstructPatchRequestFromArgs(self, alloydb_messages, instance_ref, args):
return instance_helper.ConstructPatchRequestFromArgsAlpha(
alloydb_messages, instance_ref, args
)