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,27 @@
# -*- 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.
"""Command group `gcloud container fleet rollouts`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Clusters(base.Group):
"""Create and manage rollouts."""

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.
"""Command to create a fleet rollout."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.api_lib.container.fleet import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.fleet.rollouts import flags as rollout_flags
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkehub.v1alpha import gkehub_v1alpha_messages as alpha_messages
_EXAMPLES = """
To create a rollout, run:
$ {command} ROLLOUT
"""
@base.Hidden
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
"""Create a rollout resource."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Registers flags for this command."""
flags = rollout_flags.RolloutFlags(parser)
flags.AddRolloutResourceArg()
flags.AddDisplayName()
flags.AddLabels()
flags.AddManagedRolloutConfig()
flags.AddAsync()
flags.AddRolloutTypeConfig()
flags.AddScheduledStartTime()
flags.AddExcludeMembershipNames()
flags.AddIncludeMembershipNames()
def Run(self, args: parser_extensions.Namespace) -> alpha_messages.Operation:
"""Runs the describe command."""
flag_parser = rollout_flags.RolloutFlagParser(
args, release_track=base.ReleaseTrack.ALPHA
)
req = alpha_messages.GkehubProjectsLocationsRolloutsCreateRequest(
parent=util.RolloutParentName(args),
rollout=flag_parser.Rollout(),
rolloutId=util.RolloutId(args),
)
fleet_client = client.FleetClient(release_track=self.ReleaseTrack())
operation = fleet_client.CreateRollout(req)
rollout_ref = util.RolloutRef(args)
if flag_parser.Async():
log.CreatedResource(
rollout_ref, kind='Fleet rollout', is_async=flag_parser.Async()
)
return operation
operation_client = client.OperationClient(
release_track=base.ReleaseTrack.ALPHA
)
completed_operation = operation_client.Wait(util.OperationRef(operation))
log.CreatedResource(rollout_ref, kind='Fleet rollout')
return completed_operation

View File

@@ -0,0 +1,79 @@
# -*- 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.
"""Command to delete a fleet rollout."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.api_lib.container.fleet import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.fleet.rollouts import flags as rollout_flags
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkehub.v1alpha import gkehub_v1alpha_messages as alpha_messages
_EXAMPLES = """
To delete a rollout, run:
$ {command} ROLLOUT
"""
@base.Hidden
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Delete(base.DeleteCommand):
"""Delete a rollout resource."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Registers flags for the delete command."""
flags = rollout_flags.RolloutFlags(parser)
flags.AddRolloutResourceArg()
flags.AddAsync()
def Run(self, args: parser_extensions.Namespace) -> alpha_messages.Operation:
"""Runs the delete command."""
flag_parser = rollout_flags.RolloutFlagParser(
args, release_track=base.ReleaseTrack.ALPHA
)
req = alpha_messages.GkehubProjectsLocationsRolloutsDeleteRequest()
req.name = util.RolloutName(args)
fleet_client = client.FleetClient(release_track=self.ReleaseTrack())
operation = fleet_client.DeleteRollout(req)
rollout_ref = util.RolloutRef(args)
if flag_parser.Async():
log.Print(
'Delete in progress for Fleet rollout [{}]'.format(
rollout_ref.SelfLink()
)
)
return operation
operation_client = client.OperationClient(
release_track=base.ReleaseTrack.ALPHA
)
completed_operation = operation_client.Wait(util.OperationRef(operation))
log.Print('Deleted Fleet rollout [{}].'.format(rollout_ref.SelfLink()))
return completed_operation

View File

@@ -0,0 +1,68 @@
# -*- 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.
"""Command to show fleet rollout information."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.api_lib.container.fleet import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.command_lib.container.fleet.rollouts import flags as rollout_flags
from googlecloudsdk.command_lib.container.fleet.rollouts import rollout_printer
from googlecloudsdk.core.resource import resource_printer
_EXAMPLES = """
To describe a rollout named `my-rollout`,
run:
$ {command} my-rollout
"""
@base.ReleaseTracks(base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describe a fleet rollout."""
_release_track = base.ReleaseTrack.BETA
detailed_help = {'EXAMPLES': _EXAMPLES}
@classmethod
def Args(cls, parser: parser_arguments.ArgumentInterceptor) -> None:
flags = rollout_flags.RolloutFlags(parser, cls._release_track)
flags.AddRolloutResourceArg()
resource_printer.RegisterFormatter(
rollout_printer.ROLLOUT_PRINTER_FORMAT,
rollout_printer.RolloutPrinter,
)
parser.display_info.AddFormat(rollout_printer.ROLLOUT_PRINTER_FORMAT)
def Run(self, args):
fleet_client = client.FleetClient(release_track=self.ReleaseTrack())
req = fleet_client.messages.GkehubProjectsLocationsRolloutsGetRequest(
name=util.RolloutName(args)
)
return fleet_client.DescribeRollout(req)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class DescribeAlpha(Describe):
"""Describe a fleet rollout."""
_release_track = base.ReleaseTrack.ALPHA

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.
"""Command to list fleet rollouts."""
from __future__ import absolute_import
from __future__ import annotations
from __future__ import division
from __future__ import unicode_literals
from typing import Generator
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.api_lib.container.fleet import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.fleet import flags as fleet_flags
from googlecloudsdk.command_lib.container.fleet import util as fleet_util
from googlecloudsdk.generated_clients.apis.gkehub.v1alpha import gkehub_v1alpha_messages as alpha_messages
from googlecloudsdk.generated_clients.apis.gkehub.v1beta import gkehub_v1beta_messages as beta_messages
_EXAMPLES = """
To list all rollouts, run:
$ {command}
"""
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class List(base.ListCommand):
"""List all fleet rollouts."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Registers flags for this command.
Args:
parser: Top level argument group to add new arguments.
"""
def Run(
self, args: parser_extensions.Namespace
) -> Generator[
alpha_messages.Operation | beta_messages.Operation, None, None
]:
"""Runs the rollout list command.
Args:
Args:
args: Flag arguments received from command line.
Returns:
A list of rollouts under the fleet project.
"""
if '--format' not in args.GetSpecifiedArgNames():
args.format = fleet_util.ROLLOUT_LIST_FORMAT
flag_parser = fleet_flags.FleetFlagParser(
args, release_track=self.ReleaseTrack()
)
fleet_client = client.FleetClient(self.ReleaseTrack())
req = fleet_client.messages.GkehubProjectsLocationsRolloutsListRequest(
parent=util.LocationResourceName(flag_parser.Project())
)
return fleet_client.ListRollouts(
req, page_size=flag_parser.PageSize(), limit=flag_parser.Limit()
)

View File

@@ -0,0 +1,80 @@
# -*- 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.
"""Command to pause a fleet rollout."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.api_lib.container.fleet import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.fleet.rollouts import flags as rollout_flags
from googlecloudsdk.core import log
from googlecloudsdk.generated_clients.apis.gkehub.v1alpha import gkehub_v1alpha_messages as alpha_messages
_EXAMPLES = """
To pause a rollout, run:
$ {command} ROLLOUT
"""
@base.Hidden
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Pause(base.UpdateCommand):
"""Pause a rollout resource."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Registers flags for the pause command."""
flags = rollout_flags.RolloutFlags(parser)
flags.AddRolloutResourceArg()
flags.AddAsync()
def Run(self, args: parser_extensions.Namespace) -> alpha_messages.Operation:
"""Runs the pause command."""
flag_parser = rollout_flags.RolloutFlagParser(
args, release_track=base.ReleaseTrack.ALPHA
)
req = alpha_messages.GkehubProjectsLocationsRolloutsPauseRequest()
req.name = util.RolloutName(args)
req.pauseRolloutRequest = alpha_messages.PauseRolloutRequest()
fleet_client = client.FleetClient(release_track=self.ReleaseTrack())
operation = fleet_client.PauseRollout(req)
rollout_ref = util.RolloutRef(args)
if flag_parser.Async():
log.Print(
'Pause in progress for Fleet rollout [{}]'.format(
rollout_ref.SelfLink()
)
)
return operation
operation_client = client.OperationClient(
release_track=base.ReleaseTrack.ALPHA
)
completed_operation = operation_client.Wait(util.OperationRef(operation))
log.Print('Paused Fleet rollout [{}].'.format(rollout_ref.SelfLink()))
return completed_operation

View File

@@ -0,0 +1,165 @@
# -*- 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.
"""Command to resume a fleet rollout."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from typing import Any
from apitools.base.py import encoding
from googlecloudsdk import core
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.api_lib.container.fleet import util
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import parser_arguments
from googlecloudsdk.calliope import parser_extensions
from googlecloudsdk.command_lib.container.fleet.rollouts import flags as rollout_flags
from googlecloudsdk.generated_clients.apis.gkehub.v1alpha import gkehub_v1alpha_messages as alpha_messages
_EXAMPLES = """
To resume a rollout, run:
$ {command} ROLLOUT
"""
@base.Hidden
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Resume(base.UpdateCommand):
"""Resume a rollout resource."""
detailed_help = {'EXAMPLES': _EXAMPLES}
@staticmethod
def Args(parser: parser_arguments.ArgumentInterceptor) -> None:
"""Registers flags for the resume command."""
flags = rollout_flags.RolloutFlags(parser)
flags.AddRolloutResourceArg()
flags.AddScheduleOffset()
flags.AddValidateOnly()
flags.AddAsync()
def Run(self, args: parser_extensions.Namespace) -> alpha_messages.Operation:
"""Runs the resume command."""
flag_parser = rollout_flags.RolloutFlagParser(
args, release_track=base.ReleaseTrack.ALPHA
)
fleet_client = client.FleetClient(release_track=self.ReleaseTrack())
operation_client = client.OperationClient(
release_track=base.ReleaseTrack.ALPHA
)
rollout_ref = util.RolloutRef(args)
utils = _Utils(args, operation_client, fleet_client)
if flag_parser.Async():
# This effectively skips the confirmation prompt when resuming with an
# offset.
operation = utils.resume_rollout_async(
flag_parser.ScheduleOffset(),
flag_parser.ValidateOnly()
)
core.log.Print(
'Resume in progress for Fleet rollout [{}]'.format(
rollout_ref.SelfLink()
)
)
return operation
if flag_parser.ValidateOnly():
completed_operation = utils.resume_rollout_sync(
flag_parser.ScheduleOffset(), True)
utils.log_schedule(completed_operation, rollout_ref)
elif flag_parser.ScheduleOffset():
# This is not a transaction - the rollout could theoretically be resumed
# with a different schedule than that displayed to the user, if a
# concurrent resume is invoked before the user confirms.
completed_operation = utils.resume_rollout_sync(
flag_parser.ScheduleOffset(), True
)
utils.log_schedule(completed_operation, rollout_ref)
core.console.console_io.PromptContinue(
message=(
'Do you want to resume the rollout with the displayed schedule?'
),
throw_if_unattended=True,
cancel_on_no=True,
)
completed_operation = utils.resume_rollout_sync(
flag_parser.ScheduleOffset(), False
)
core.log.Print(
'Resumed Fleet rollout [{}].'.format(rollout_ref.SelfLink())
)
else:
completed_operation = utils.resume_rollout_sync(
flag_parser.ScheduleOffset(), flag_parser.ValidateOnly()
)
core.log.Print(
'Resumed Fleet rollout [{}].'.format(rollout_ref.SelfLink())
)
return completed_operation
class _Utils:
"""Utility functions for the resume command."""
def __init__(
self,
args,
operation_client: client.OperationClient,
fleet_client: client.FleetClient
):
self.rollout_name = util.RolloutName(args)
self.operation_client = operation_client
self.fleet_client = fleet_client
def resume_rollout_async(self, offset: str, validate_only: bool) -> Any:
req = alpha_messages.GkehubProjectsLocationsRolloutsResumeRequest()
req.name = self.rollout_name
req.resumeRolloutRequest = alpha_messages.ResumeRolloutRequest(
scheduleOffset=offset,
validateOnly=validate_only,
)
return self.fleet_client.ResumeRollout(req)
def resume_rollout_sync(self, offset: str, validate_only: bool) -> Any:
operation = self.resume_rollout_async(offset, validate_only)
return self.operation_client.Wait(util.OperationRef(operation))
@staticmethod
def log_schedule(
completed_operation: Any, rollout_ref: core.resources.Resource
) -> None:
"""Pretty prints the returned rollout schedule."""
resp = encoding.MessageToDict(completed_operation)
core.log.Print(
'Schedule after resume for fleet rollout [{}]:'.format(
rollout_ref.SelfLink()
)
)
waves = {
wave['waveNumber']: (wave['waveStartTime'], wave['waveEndTime'])
for wave in resp['schedule']['waves']
}
for n in range(1, len(waves) + 1):
core.log.Print('Wave {}: [{}, {}]'.format(n, waves[n][0], waves[n][1]))