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,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2013 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.
"""The gcloud datastore group."""
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 Datastore(base.Group):
"""Manage your Cloud Datastore resources.
Cloud Datastore is a highly-scalable NoSQL database for your applications.
Cloud Datastore automatically handles sharding and replication, providing
you with a highly available and durable database that scales automatically
to handle your applications' load.
More information on Cloud Datastore can be found here:
https://cloud.google.com/datastore and detailed documentation can be
found here: https://cloud.google.com/datastore/docs
export -- Export data to Google Cloud Storage
import -- Import data from Google Cloud Storage
indexes -- Manage your Cloud Firestore indexes.
operations -- Manage Long Running Operations for Cloud Firestore.
"""
category = base.DATABASES_CATEGORY
def Filter(self, context, args):
# TODO(b/190530439): Determine if command group works with project number
base.RequireProjectID(args)
del context, args
base.DisableUserProjectQuota()

View File

@@ -0,0 +1,125 @@
# -*- 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.
"""The gcloud datastore export command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastore import admin_api
from googlecloudsdk.api_lib.datastore import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
class Export(base.Command):
"""Export Cloud Datastore entities to Google Cloud Storage.
Export a copy of all or a subset of entities from Google Cloud Datastore
to another storage system, such as Google Cloud Storage. Recent
updates to entities may not be reflected in the export. The export occurs in
the background and its progress can be monitored and managed via the operation
commands. The output of an export may only be used once the operation has
completed. If an export operation is cancelled before completion then it may
leave partial data behind in Google Cloud Storage.
"""
detailed_help = {
'EXAMPLES':
"""\
To export all kinds in the `exampleNs` namespace in the `exampleProject`
project to the `exampleBucket`, run:
$ {command} gs://exampleBucket --namespaces='exampleNs' --project='exampleProject'
To export the `exampleKind` and `otherKind` kinds in the `exampleNs`
namespace in the `exampleProject` project to the `exampleBucket`, run:
$ {command} gs://exampleBucket --kinds='exampleKind','otherKind' --namespaces='exampleNs' --project='exampleProject'
To export all namespaces and kinds in the currently set project to the
`exampleBucket` without waiting for the operation to complete, run:
$ {command} gs://exampleBucket --async
To export the `exampleKind` in all namespaces in the currently set
project to the `exampleBucket`, and output the result in JSON, run:
$ {command} gs://exampleBucket --kinds='exampleKind' --format=json
"""
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddEntityFilterFlags(parser)
flags.AddLabelsFlag(parser)
parser.add_argument(
'output_url_prefix',
help="""
Location for the export metadata and data files. Must be a valid
Google Cloud Storage bucket with an optional path prefix. For example:
$ {command} gs://mybucket/my/path
Will place the export in the `mybucket` bucket in objects prefixed with
`my/path`.
""")
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
project = properties.VALUES.core.project.Get(required=True)
destination = self._ParseGCSObjectPrefix(args.output_url_prefix)
response = admin_api.Export(
project,
# use join and filter to avoid trailing '/'.
'gs://{}'
.format('/'.join([part for part in destination if part is not None])),
kinds=args.kinds,
namespaces=args.namespaces,
labels=args.operation_labels)
if not args.async_:
operations.WaitForOperation(response)
return response
def _ParseGCSObjectPrefix(self, resource):
"""Parses a GCS bucket with an optional object prefix.
Args:
resource: the user input resource string.
Returns:
a tuple of strings containing the GCS bucket and GCS object. The GCS
object may be None.
"""
try:
# Try as bucket first so that a single id is interpretted as a bucket
# instead of an object with a missing bucket.
bucket_ref = resources.REGISTRY.Parse(
resource, collection='storage.buckets')
# Call Parse rather than Create to set validate to False, allowing the
# empty object.
return (bucket_ref.bucket, None)
except resources.UserError:
# Ignored, we'll try parsing again as an object.
pass
object_ref = resources.REGISTRY.Parse(
resource, collection='storage.objects')
return (object_ref.bucket, object_ref.object)

View File

@@ -0,0 +1,93 @@
# -*- 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.
"""The gcloud datastore import command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastore import admin_api
from googlecloudsdk.api_lib.datastore import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
class Import(base.Command):
"""Import Cloud Datastore entities from Google Cloud Storage.
Imports entities into Google Cloud Datastore. Existing entities with
the same key are overwritten. The import occurs in the background and its
progress can be monitored and managed via the Operation resource that is
created. If an Import operation is cancelled, it is possible that a subset of
the data has already been imported to Cloud Datastore. This data will not be
removed.
"""
detailed_help = {
'EXAMPLES':
"""\
To import all data exported to the output URL
`gs://exampleBucket/exampleExport/exampleExport.overall_export_metadata`, run:
$ {command} gs://exampleBucket/exampleExport/exampleExport.overall_export_metadata
To import all data exported to the output URL
`gs://exampleBucket/exampleExport/exampleExport.overall_export_metadata`
without waiting for the operation to complete, run:
$ {command} gs://exampleBucket/exampleExport/exampleExport.overall_export_metadata --async
To import only the `exampleKind` from the data exported to the output
URL `gs://exampleBucket/exampleExport/exampleExport.overall_export_metadata`,
run:
$ {command} gs://exampleBucket/exampleExport/exampleExport.overall_export_metadata --kinds='exampleKind'
"""
}
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags.AddEntityFilterFlags(parser)
flags.AddLabelsFlag(parser)
parser.add_argument(
'input_url',
help="""
Location of the import metadata. Must be a valid Google Cloud Storage
object. The file extension is 'overall_export_metadata'.
This location is the 'output_url' field of a previous export, and can
be found via the 'operations describe' command.
""")
base.ASYNC_FLAG.AddToParser(parser)
def Run(self, args):
project = properties.VALUES.core.project.Get(required=True)
input_url_ref = resources.REGISTRY.Parse(
args.input_url, collection='storage.objects')
response = admin_api.Import(
project,
'gs://{}/{}'.format(input_url_ref.bucket, input_url_ref.object),
kinds=args.kinds,
namespaces=args.namespaces,
labels=args.operation_labels)
if not args.async_:
operations.WaitForOperation(response)
return response

View File

@@ -0,0 +1,29 @@
# -*- 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.
"""The command group for Cloud Datastore indexes."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Indexes(base.Group):
"""Manage your Cloud Datastore indexes.
The gcloud datastore command group lets you create and delete Google Cloud
Datastore indexes.
"""

View File

@@ -0,0 +1,127 @@
# -*- 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.
"""The gcloud datastore indexes cleanup command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app import yaml_parsing
from googlecloudsdk.api_lib.datastore import constants
from googlecloudsdk.api_lib.datastore import index_api
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.app import output_helpers
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core.console import console_io
@base.DefaultUniverseOnly
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Cleanup(base.Command):
"""Cleanup Cloud Datastore indexes."""
detailed_help = {
'brief': (
'Remove unused datastore indexes based on your local index '
'configuration.'
),
'DESCRIPTION': """
This command removes unused datastore indexes based on your local index
configuration. Any indexes that exist that are not in the index file will be
removed.
""",
'EXAMPLES': """\
To remove unused indexes based on your local configuration, run:
$ {command} ~/myapp/index.yaml
""",
}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Get arguments for this command.
Args:
parser: argparse.ArgumentParser, the parser for this command.
"""
flags.AddIndexFileFlag(parser)
flags.AddDatabaseIdFlag(parser)
def Run(self, args) -> None:
"""Deletes indexes that have been removed from the index.yaml file."""
# Default to '(default)' if unset.
database_id = (
args.database if args.database else constants.DEFAULT_NAMESPACE
)
self.Cleanup(index_file=args.index_file, database=database_id)
def Cleanup(self, index_file: str, database: str) -> None:
"""Delete indexes that have been removed from the index.yaml file."""
project = properties.VALUES.core.project.Get(required=True)
info = yaml_parsing.ConfigYamlInfo.FromFile(index_file)
if not info or info.name != yaml_parsing.ConfigYamlInfo.INDEX:
raise exceptions.InvalidArgumentException(
'index_file', 'You must provide the path to a valid index.yaml file.'
)
output_helpers.DisplayProposedConfigDeployments(
project=project, configs=[info]
)
console_io.PromptContinue(
default=True, throw_if_unattended=False, cancel_on_no=True
)
self.PerformApiCleanupViaFirestoreAdmin(info, project, database)
def PerformApiCleanupViaFirestoreAdmin(
self, info: yaml_parsing.ConfigYamlInfo, project: str, database: str
) -> None:
"""Cleans up removed indexes via the Firestore Admin API.
Lists the database's existing indexes, and then compares them against the
indexes that are defined in the given index.yaml file. Any discrepancies
against the index.yaml file are deleted.
Args:
info: The parsed index.yaml information.
project: The project we are operating on.
database: The database within the project we are operating on.
"""
received_indexes = (
index_api.NormalizeIndexesForFirestoreApi(info.parsed.indexes or [])
)
indexes_to_delete_ids = set()
current_indexes = index_api.ListDatastoreIndexesViaFirestoreApi(
project, database
)
for index_id, index in current_indexes:
# Firestore API returns index with '__name__' field path. Normalizing the
# index is required.
normalized_index = index_api.NormalizeIndexForFirestoreApi(index)
if normalized_index in received_indexes:
continue
msg = (
'This index is no longer defined in your index.yaml file.\n{0}'
.format(index.ToYAML())
)
prompt = 'Do you want to delete this index'
if console_io.PromptContinue(msg, prompt, default=True):
indexes_to_delete_ids.add(index_id)
index_api.DeleteIndexesViaFirestoreApi(
project, database, indexes_to_delete_ids
)

View File

@@ -0,0 +1,120 @@
# -*- 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.
"""The gcloud datastore indexes create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.app import yaml_parsing
from googlecloudsdk.api_lib.datastore import constants
from googlecloudsdk.api_lib.datastore import index_api
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.app import output_helpers
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core.console import console_io
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class Create(base.Command):
"""Create Cloud Datastore indexes."""
detailed_help = {
'brief': (
'Create new datastore indexes based on your local index '
'configuration.'
),
'DESCRIPTION': """
Create new datastore indexes based on your local index configuration.
Any indexes in your index file that do not exist will be created.
""",
'EXAMPLES': """\
To create new indexes based on your local configuration, run:
$ {command} ~/myapp/index.yaml
Detailed information about index configuration can be found at the
[index.yaml reference](https://cloud.google.com/datastore/docs/tools/indexconfig).
""",
}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Get arguments for this command."""
flags.AddIndexFileFlag(parser)
flags.AddDatabaseIdFlag(parser)
def Run(self, args) -> None:
"""Create missing indexes as defined in the index.yaml file."""
# Default to '(default)' if unset.
database_id = (
args.database if args.database else constants.DEFAULT_NAMESPACE
)
self.CreateIndexes(
index_file=args.index_file, database=database_id, enable_vector=False
)
def CreateIndexes(
self, index_file: str, database: str, enable_vector: bool
) -> None:
"""Cleates missing indexes via the Firestore Admin API.
Lists the database's existing indexes, and then compares them against the
indexes that are defined in the given index.yaml file. Any discrepancies
against the index.yaml file are created.
Args:
index_file: The users definition of their desired indexes.
database: The database within the project we are operating on.
enable_vector: Whether or not vector indexes are supported.
"""
project = properties.VALUES.core.project.Get(required=True)
info = yaml_parsing.ConfigYamlInfo.FromFile(index_file)
if not info or info.name != yaml_parsing.ConfigYamlInfo.INDEX:
raise exceptions.InvalidArgumentException(
'index_file', 'You must provide the path to a valid index.yaml file.'
)
output_helpers.DisplayProposedConfigDeployments(
project=project, configs=[info]
)
console_io.PromptContinue(
default=True, throw_if_unattended=False, cancel_on_no=True
)
index_api.CreateMissingIndexesViaFirestoreApi(
project_id=project,
database_id=database,
index_definitions=info.parsed,
enable_vector=enable_vector,
)
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateFirestoreAPI(Create):
"""Create Cloud Datastore indexes with Firestore API."""
def Run(self, args) -> None:
# Default to '(default)' if unset.
database_id = (
constants.DEFAULT_NAMESPACE if not args.database else args.database
)
return self.CreateIndexes(
index_file=args.index_file, database=database_id, enable_vector=True
)

View File

@@ -0,0 +1,18 @@
- release_tracks: []
help_text:
brief: Show details about an Cloud Datastore index.
description: Show details about an Cloud Datastore index.
examples: |
To describe the index with id `exampleIndexId`, run:
$ {command} exampleIndexId
request:
collection: datastore.projects.indexes
api_version: v1
arguments:
resource:
help_text: The index you want to get the details of.
spec: !REF googlecloudsdk.command_lib.datastore.resources:index

View File

@@ -0,0 +1,21 @@
- release_tracks: []
help_text:
brief: List Cloud Datastore indexes.
description: List Cloud Datastore indexes.
examples: |
To list all composite indexes in the database, run:
$ {command}
request:
collection: datastore.projects.indexes
api_version: v1
arguments:
resource:
help_text: The project name where to list the indexes.
spec: !REF googlecloudsdk.command_lib.datastore.resources:project
response:
id_field: indexId

View File

@@ -0,0 +1,28 @@
# -*- 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.
"""The command group for Cloud Datastore operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Operations(base.Group):
"""Manage Long Running Operations for Cloud Datastore."""
pass

View File

@@ -0,0 +1,65 @@
# -*- 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.
"""The gcloud datastore operations cancel command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastore import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
from googlecloudsdk.core.console import console_io
class Cancel(base.Command):
"""Cancel a currently-running Cloud Datastore admin operation."""
detailed_help = {
'EXAMPLES':
"""\
To cancel the currently-running operation with id `exampleId`, run:
$ {command} exampleId
or
$ {command} projects/your-project-id/operations/exampleId
"""
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: argparse.ArgumentParser, the parser for this command.
"""
flags.AddOperationNameFlag(parser, 'cancel')
def Run(self, args):
name = resources.REGISTRY.Parse(
args.name,
params={
'projectsId': properties.VALUES.core.project.GetOrFail,
},
collection='datastore.projects.operations').RelativeName()
console_io.PromptContinue(
message='The operation [{}] will be cancelled.'.format(name),
cancel_on_no=True)
return operations.CancelOperation(name)

View File

@@ -0,0 +1,65 @@
# -*- 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.
"""The gcloud datastore operations delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastore import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete a completed Cloud Datastore admin operation."""
detailed_help = {
'EXAMPLES':
"""\
To delete the completed operation with id `exampleId`, run:
$ {command} exampleId
or
$ {command} projects/your-project-id/operations/exampleId
"""
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: argparse.ArgumentParser, the parser for this command.
"""
flags.AddOperationNameFlag(parser, 'delete')
def Run(self, args):
name = resources.REGISTRY.Parse(
args.name,
params={
'projectsId': properties.VALUES.core.project.GetOrFail,
},
collection='datastore.projects.operations').RelativeName()
console_io.PromptContinue(
message='The operation [{}] will be deleted.'.format(name),
cancel_on_no=True)
return operations.DeleteOperation(name)

View File

@@ -0,0 +1,60 @@
# -*- 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.
"""The gcloud datastore operations describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastore import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.datastore import flags
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
class Describe(base.DescribeCommand):
"""Retrieves information about a Cloud Datastore admin operation."""
detailed_help = {
'EXAMPLES':
"""\
To see information on the operation with id `exampleId`, run:
$ {command} exampleId
or
$ {command} projects/your-project-id/operations/exampleId
"""
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: argparse.ArgumentParser, the parser for this command.
"""
flags.AddOperationNameFlag(parser, 'retrieve')
def Run(self, args):
name = resources.REGISTRY.Parse(
args.name,
params={
'projectsId': properties.VALUES.core.project.GetOrFail,
},
collection='datastore.projects.operations').RelativeName()
return operations.GetOperation(name)

View File

@@ -0,0 +1,92 @@
# -*- 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.
"""The gcloud datastore operations list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.datastore import operations
from googlecloudsdk.api_lib.datastore import rewrite_backend
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
from googlecloudsdk.core.resource import resource_projection_spec
class List(base.ListCommand):
"""List pending Cloud Datastore admin operations and their status.
Filters are case-sensitive and have the following syntax:
field = value [AND [field = value]] ...
where `field` is one of `kind`, `namespace`, `type`, or `labels.[KEY]`, and
`[KEY]` is a label key. `kind` and `namespace` may be `*` to query for
operations on all kinds and/or all namespaces. `type` may be one of
`export_entities` or `import_entities`.
Only the logical `AND` operator is
supported; space-separated items are treated as having an implicit `AND`
operator.
## EXAMPLES
To see the list of all operations, run:
$ {command}
To see the list of all export operations, run:
$ {command} --filter='type:export_entities'
To see the list of all export operations for kind 'MyKind', run:
$ {command} --filter='type:export_entities AND kind:MyKind'
To see the list of all operations with particular labels, run:
$ {command} --filter='labels.run = daily'
"""
@staticmethod
def Args(parser):
"""Register flags for this command."""
base.PAGE_SIZE_FLAG.SetDefault(parser, operations.DEFAULT_PAGE_SIZE)
base.LIMIT_FLAG.SetDefault(parser, operations.DEFAULT_PAGE_SIZE)
def Run(self, args):
frontend_filter, backend_filter = self._ConvertFilter(args.filter, args)
# Override existing filter with frontend filter.
args.filter = frontend_filter
return operations.ListOperations(
project=properties.VALUES.core.project.Get(required=True),
limit=args.limit,
operation_filter=backend_filter)
def _ConvertFilter(self, expression, args):
"""Translates user-provided filter spec into one our backend understands.
Args:
expression: a filter spec to translate
args: the args namespace object
Returns:
A tuple of string filter specs. The first is the frontend spec for post
filtering, the second is a spec that the Datastore Admin API understands.
"""
operation_rewrite_backend = rewrite_backend.OperationsRewriteBackend()
display_info = args.GetDisplayInfo()
defaults = resource_projection_spec.ProjectionSpec(
symbols=display_info.transforms, aliases=display_info.aliases)
return operation_rewrite_backend.Rewrite(expression, defaults=defaults)