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,22 @@
# -*- 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.
"""Cloud Storage buckets anywhere-caches commands."""
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
class AnywhereCaches(base.Group):
"""Manage Cloud Storage Anywhere Caches."""

View File

@@ -0,0 +1,118 @@
# -*- 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.
"""Implementation of create command for creating Anywhere Cache Instances."""
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import errors_util
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.command_lib.storage import plurality_checkable_iterator
from googlecloudsdk.command_lib.storage import progress_callbacks
from googlecloudsdk.command_lib.storage import storage_url
from googlecloudsdk.command_lib.storage.tasks import task_executor
from googlecloudsdk.command_lib.storage.tasks import task_graph_executor
from googlecloudsdk.command_lib.storage.tasks import task_status
from googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_caches import create_anywhere_cache_task
@base.DefaultUniverseOnly
class Create(base.CreateCommand):
"""Create Anywhere Cache instances for a bucket."""
detailed_help = {
'DESCRIPTION': """
Create Anywhere Cache instances.
Only one cache instance per zone can be created for each bucket.
""",
'EXAMPLES': """
The following command creates an anywhere cache instance for bucket
in ``asia-south2-b'' zone:
$ {command} gs://my-bucket asia-south2-b
The following command creates anywhere cache instances for bucket
in ``asia-south2-b'', and ``asia-east1-a'' zone:
$ {command} gs://my-bucket asia-south2-b asia-east1-a
The following command creates an anywhere cache instance for bucket
in ``asia-south2-b'' zone, with ttl for cache entry as 6 hours, and
admission policy as ``ADMIT_ON_SECOND_MISS'':
$ {command} gs://my-bucket asia-south2-b --ttl=6h --admission-policy='ADMIT_ON_SECOND_MISS'
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'url',
type=str,
help=(
'Specifies the URL of the bucket where the Anywhere Cache should be'
' created.'
),
)
parser.add_argument(
'zone',
type=str,
nargs='+',
help=(
'Specifies the name of the zonal locations where the Anywhere Cache'
' should be created.'
),
)
parser.add_argument(
'--ttl',
type=arg_parsers.Duration(),
help='Cache entry time-to-live. Default to 24h if not provided.',
)
flags.add_admission_policy_flag(parser)
def get_task_iterator(self, args, task_status_queue):
url = storage_url.storage_url_from_string(args.url)
errors_util.raise_error_if_not_gcs_bucket(args.command_path, url)
progress_callbacks.workload_estimator_callback(
task_status_queue, len(args.zone)
)
if args.ttl is not None:
args.ttl = str(args.ttl)+'s'
for zone in args.zone:
yield create_anywhere_cache_task.CreateAnywhereCacheTask(
url, zone, admission_policy=args.admission_policy, ttl=args.ttl
)
def Run(self, args):
task_status_queue = task_graph_executor.multiprocessing_context.Queue()
task_iterator = self.get_task_iterator(args, task_status_queue)
plurality_checkable_task_iterator = (
plurality_checkable_iterator.PluralityCheckableIterator(task_iterator)
)
self.exit_code = task_executor.execute_tasks(
plurality_checkable_task_iterator,
parallelizable=True,
task_status_queue=task_status_queue,
progress_manager_args=task_status.ProgressManagerArgs(
increment_type=task_status.IncrementType.INTEGER, manifest_path=None
),
)

View File

@@ -0,0 +1,88 @@
# -*- 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.
"""Implementation of describe command to get the Anywhere Cache Instance."""
import collections
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.command_lib.storage import storage_url
from googlecloudsdk.command_lib.storage.resources import resource_util
# Determines the order in which the fields should be displayed for
# an AnywhereCacheResource.
AnywhereCacheDisplayTitlesAndDefaults = collections.namedtuple(
'AnywhereCacheDisplayTitlesAndDefaults',
(
'admission_policy',
'anywhere_cache_id',
'bucket',
'create_time',
'id',
'kind',
'pending_update',
'state',
'ttl',
'update_time',
'zone',
),
)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Returns details of Anywhere Cache instance of a bucket."""
detailed_help = {
'DESCRIPTION': """
Desribes a single Anywhere Cache instance if it exists.
""",
'EXAMPLES': """
The following command describes the anywhere cache instance of bucket
``my-bucket'' having anywhere_cache_id ``my-cache-id'':
$ {command} my-bucket/my-cache-id
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'id',
type=str,
help=(
'Identifier for a Anywhere Cache instance. It is a combination of'
' bucket_name/anywhere_cache_id, For example :'
' test-bucket/my-cache-id.'
),
)
flags.add_raw_display_flag(parser)
def Run(self, args):
bucket_name, _, anywhere_cache_id = args.id.rpartition('/')
result = api_factory.get_api(
storage_url.ProviderPrefix.GCS
).get_anywhere_cache(bucket_name, anywhere_cache_id)
return resource_util.get_display_dict_for_resource(
result,
AnywhereCacheDisplayTitlesAndDefaults,
args.raw,
)

View File

@@ -0,0 +1,90 @@
# -*- 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.
"""Implementation of disable command for disabling Anywhere Cache Instances."""
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import progress_callbacks
from googlecloudsdk.command_lib.storage import storage_url
from googlecloudsdk.command_lib.storage.tasks import task_executor
from googlecloudsdk.command_lib.storage.tasks import task_graph_executor
from googlecloudsdk.command_lib.storage.tasks import task_status
from googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_caches import disable_anywhere_cache_task
@base.DefaultUniverseOnly
class Disable(base.Command):
"""Disable Anywhere Cache instances."""
detailed_help = {
'DESCRIPTION': """
Disables one or more Anywhere Cache instances.
The cache instance will be set to DISABLED state. The existing entries
can be read from the cache but new entries will not be written to the
cache. The L4 SSD cache would not be deleted by the cache manager until
the min TTL (1h) has been reached (cache instance is kept for at least
1h). Google Cloud Storage defines the min TTL which is applied to all
cache instances. Cach disablement could be canceled by using
anywhere-caches resume command before the instance is deleted.
""",
'EXAMPLES': """
The following command disables the anywhere cache instance of bucket
``my-bucket'' having anywhere_cache_id ``my-cache-id'':
$ {command} my-bucket/my-cache-id
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'id',
type=str,
nargs='+',
help=(
'Identifiers for a Anywhere Cache instance. They are combination of'
' bucket_name/anywhere_cache_id. For example :'
' test-bucket/my-cache-id.'
),
)
def _get_task_iterator(self, args, task_status_queue):
progress_callbacks.workload_estimator_callback(
task_status_queue, len(args.id)
)
for id_str in args.id:
bucket_name, _, anywhere_cache_id = id_str.rpartition(
storage_url.CLOUD_URL_DELIMITER
)
yield disable_anywhere_cache_task.DisableAnywhereCacheTask(
bucket_name, anywhere_cache_id
)
def Run(self, args):
task_status_queue = task_graph_executor.multiprocessing_context.Queue()
task_iterator = self._get_task_iterator(args, task_status_queue)
self.exit_code = task_executor.execute_tasks(
task_iterator,
parallelizable=True,
task_status_queue=task_status_queue,
progress_manager_args=task_status.ProgressManagerArgs(
increment_type=task_status.IncrementType.INTEGER, manifest_path=None
),
)

View File

@@ -0,0 +1,69 @@
# -*- 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.
"""Implementation of list command to list Anywhere Cache instances of bucket."""
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import errors_util
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.command_lib.storage import storage_url
from googlecloudsdk.command_lib.storage.resources import resource_util
from surface.storage.buckets.anywhere_caches import describe
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List all Anywhere Cache instances of a bucket."""
detailed_help = {
'DESCRIPTION': """
List all cache instances of this bucket.
""",
'EXAMPLES': """
The following command lists all anywhere cache instances of bucket
``gs://my-bucket'':
$ {command} gs://my-bucket
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'url',
type=str,
help=(
'Specifies the URL of the bucket for which anywhere cache instances'
' should be listed.'
),
)
flags.add_raw_display_flag(parser)
def Run(self, args):
url = storage_url.storage_url_from_string(args.url)
errors_util.raise_error_if_not_gcs_bucket(args.command_path, url)
cache_resources = api_factory.get_api(url.scheme).list_anywhere_caches(
url.bucket_name
)
for cache_resource in cache_resources:
yield resource_util.get_display_dict_for_resource(
cache_resource,
describe.AnywhereCacheDisplayTitlesAndDefaults,
args.raw,
)

View File

@@ -0,0 +1,84 @@
# -*- 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.
"""Implementation of pause command to pause Anywhere Cache instances."""
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import plurality_checkable_iterator
from googlecloudsdk.command_lib.storage import progress_callbacks
from googlecloudsdk.command_lib.storage.tasks import task_executor
from googlecloudsdk.command_lib.storage.tasks import task_graph_executor
from googlecloudsdk.command_lib.storage.tasks import task_status
from googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_caches import pause_anywhere_cache_task
@base.DefaultUniverseOnly
class Pause(base.Command):
"""Pause Anywhere Cache instances."""
detailed_help = {
'DESCRIPTION': """
The pause operation can be used to stop the data ingestion of a cache
instance in RUNNING state (read-only cache) until the Resume is invoked.
""",
'EXAMPLES': """
The following command pause the anywhere cache instance of bucket
``my-bucket'' having anywhere_cache_id ``my-cache-id'':
$ {command} my-bucket/my-cache-id
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'id',
type=str,
nargs='+',
help=(
'Identifiers for a Anywhere Cache instance. They are combination of'
' bucket_name/anywhere_cache_id. For example :'
' test-bucket/my-cache-id.'
),
)
def get_task_iterator(self, args, task_status_queue):
progress_callbacks.workload_estimator_callback(
task_status_queue, len(args.id)
)
for id_str in args.id:
bucket_name, _, anywhere_cache_id = id_str.rpartition('/')
yield pause_anywhere_cache_task.PauseAnywhereCacheTask(
bucket_name, anywhere_cache_id
)
def Run(self, args):
task_status_queue = task_graph_executor.multiprocessing_context.Queue()
task_iterator = self.get_task_iterator(args, task_status_queue)
plurality_checkable_task_iterator = (
plurality_checkable_iterator.PluralityCheckableIterator(task_iterator)
)
self.exit_code = task_executor.execute_tasks(
plurality_checkable_task_iterator,
parallelizable=True,
task_status_queue=task_status_queue,
progress_manager_args=task_status.ProgressManagerArgs(
increment_type=task_status.IncrementType.INTEGER, manifest_path=None
),
continue_on_error=getattr(args, 'continue_on_error', False),
)

View File

@@ -0,0 +1,85 @@
# -*- 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.
"""Implementation of resume command for resuming Anywhere Cache instances."""
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import progress_callbacks
from googlecloudsdk.command_lib.storage import storage_url
from googlecloudsdk.command_lib.storage.tasks import task_executor
from googlecloudsdk.command_lib.storage.tasks import task_graph_executor
from googlecloudsdk.command_lib.storage.tasks import task_status
from googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_caches import resume_anywhere_cache_task
@base.DefaultUniverseOnly
class Resume(base.Command):
"""Resume Anywhere Cache instances."""
detailed_help = {
'DESCRIPTION': """
Resume operation could be used to revert the Paused and Disabled state.
Once a paused/disabled cache is resumed, the cache will be set to
RUNNING/CREATING state:
1. RUNNING if the cache is active.
2. CREATING if the cache is pending creation.
""",
'EXAMPLES': """
The following command resume the anywhere cache instance of bucket
``my-bucket'' having anywhere_cache_id ``my-cache-id'':
$ {command} my-bucket/my-cache-id
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'id',
type=str,
nargs='+',
help=(
'Identifiers for a Anywhere Cache instance. They are combination of'
' bucket_name/anywhere_cache_id. For example :'
' test-bucket/my-cache-id.'
),
)
def _get_task_iterator(self, args, task_status_queue):
progress_callbacks.workload_estimator_callback(
task_status_queue, len(args.id)
)
for id_str in args.id:
bucket_name, _, anywhere_cache_id = id_str.rpartition(
storage_url.CLOUD_URL_DELIMITER
)
yield resume_anywhere_cache_task.ResumeAnywhereCacheTask(
bucket_name, anywhere_cache_id
)
def Run(self, args):
task_status_queue = task_graph_executor.multiprocessing_context.Queue()
task_iterator = self._get_task_iterator(args, task_status_queue)
self.exit_code = task_executor.execute_tasks(
task_iterator,
parallelizable=True,
task_status_queue=task_status_queue,
progress_manager_args=task_status.ProgressManagerArgs(
increment_type=task_status.IncrementType.INTEGER, manifest_path=None
),
)

View File

@@ -0,0 +1,101 @@
# -*- 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.
"""Implementation of update command for updating Anywhere Cache instances."""
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import flags
from googlecloudsdk.command_lib.storage import progress_callbacks
from googlecloudsdk.command_lib.storage.tasks import task_executor
from googlecloudsdk.command_lib.storage.tasks import task_graph_executor
from googlecloudsdk.command_lib.storage.tasks import task_status
from googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_caches import patch_anywhere_cache_task
@base.DefaultUniverseOnly
class Update(base.UpdateCommand):
"""Update Anywhere Cache instances."""
detailed_help = {
'DESCRIPTION': """
Update one or more Anywhere Cache instances. A cache instance can be
updated if its state is created or pending creation.
""",
'EXAMPLES': """
The following command updates cache entry's ttl, and admisson policy of
anywhere cache instance in bucket ``my-bucket'' having anywhere_cache_id
``my-cache-id'':
$ {command} my-bucket/my-cache-id --ttl=6h --admission-policy='ADMIT_ON_SECOND_MISS'
The following command updates cache entry's ttl of anywhere cache
instances in bucket ``bucket-1'' and ``bucket-2'' having anywhere_cache_id
``my-cache-id-1'', and ``my-cache-id-2'' respectively:
$ {command} bucket-1/my-cache-id-1 bucket-2/my-cache-id-2 --ttl=6h
""",
}
@classmethod
def Args(cls, parser):
parser.add_argument(
'id',
type=str,
nargs='+',
help=(
'Identifiers for a Anywhere Cache Instance.They are combination of'
' bucket_name/anywhere_cache_id. For example :'
' test-bucket/my-cache-id.'
),
)
parser.add_argument(
'--ttl',
type=arg_parsers.Duration(),
help='Cache entry time-to-live. Default to 24h if not provided.',
)
flags.add_admission_policy_flag(parser)
def get_task_iterator(self, args, task_status_queue):
progress_callbacks.workload_estimator_callback(
task_status_queue, len(args.id)
)
ttl = str(args.ttl) + 's' if args.ttl else None
for id_str in args.id:
bucket_name, _, anywhere_cache_id = id_str.rpartition('/')
yield patch_anywhere_cache_task.PatchAnywhereCacheTask(
bucket_name,
anywhere_cache_id,
admission_policy=args.admission_policy,
ttl=ttl,
)
def Run(self, args):
task_status_queue = task_graph_executor.multiprocessing_context.Queue()
task_iterator = self.get_task_iterator(args, task_status_queue)
self.exit_code = task_executor.execute_tasks(
task_iterator,
parallelizable=True,
task_status_queue=task_status_queue,
progress_manager_args=task_status.ProgressManagerArgs(
increment_type=task_status.IncrementType.INTEGER, manifest_path=None
),
)