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,40 @@
# -*- 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.
"""Commands for creating and deleting resource policies."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class ResourcePolicies(base.Group):
"""Manage Compute Engine Resource Policies."""
category = base.COMPUTE_CATEGORY
ResourcePolicies.detailed_help = {
'DESCRIPTION': """
Manage Compute Engine resource policies.
For more information about resource policies, see the
[resource policies documentation](https://cloud.google.com/compute/docs/access#resource-policies).
See also: [Resource policies API](https://cloud.google.com/compute/docs/reference/rest/v1/resourcePolicies).
""",
}

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The command group for cloud resource_policies creation."""
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 Create(base.Group):
"""Create Compute Engine Resource Policies."""

View File

@@ -0,0 +1,114 @@
# -*- 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.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
DETAILED_HELP = {
'DESCRIPTION': """\
Create a Compute Engine disk consistency group resource policy.
""",
'EXAMPLES': """\
Create a disk consistency group policy:
$ {command} my-resource-policy --region=REGION
"""
}
def _CommonArgs(parser):
"""A helper function to build args based on different API version."""
CreateDiskConsistencyGroup.resource_policy_arg.AddArgument(parser)
flags.AddCommonArgs(parser)
parser.display_info.AddCacheUpdater(None)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateDiskConsistencyGroup(base.CreateCommand):
"""Create a Compute Engine Disk Consistency Group resource policy."""
@staticmethod
def Args(parser):
CreateDiskConsistencyGroup.resource_policy_arg = (
flags.MakeResourcePolicyArg())
_CommonArgs(parser)
def Run(self, args):
return self._Run(args)
def _Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = self.resource_policy_arg.ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeDiskConsistencyGroupPolicy(
policy_ref, args, messages)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
CreateDiskConsistencyGroup.detailed_help = DETAILED_HELP
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateDiskConsistencyGroupBeta(CreateDiskConsistencyGroup):
"""Create a Compute Engine Disk Consistency Group resource policy."""
@staticmethod
def Args(parser):
CreateDiskConsistencyGroup.resource_policy_arg = (
flags.MakeResourcePolicyArg())
_CommonArgs(parser)
def Run(self, args):
return self._Run(args)
CreateDiskConsistencyGroupBeta.detailed_help = DETAILED_HELP
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateDiskConsistencyGroupAlpha(CreateDiskConsistencyGroup):
"""Create a Compute Engine Disk Consistency Group resource policy."""
@staticmethod
def Args(parser):
CreateDiskConsistencyGroup.resource_policy_arg = (
flags.MakeResourcePolicyArg())
_CommonArgs(parser)
def Run(self, args):
return self._Run(args)
CreateDiskConsistencyGroupAlpha.detailed_help = DETAILED_HELP

View File

@@ -0,0 +1,100 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils as compute_api
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
def _CommonArgs(parser, api_version, track):
"""A helper function to build args based on different API version."""
messages = apis.GetMessagesModule('compute', api_version)
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddGroupPlacementArgs(parser, messages, track)
parser.display_info.AddCacheUpdater(None)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateGroupPlacement(base.CreateCommand):
"""Create a Compute Engine group placement resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, compute_api.COMPUTE_ALPHA_API_VERSION,
base.ReleaseTrack.ALPHA)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeGroupPlacementPolicy(policy_ref, args, messages,
self.ReleaseTrack())
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateGroupPlacementBeta(CreateGroupPlacement):
"""Create a Compute Engine group placement resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, compute_api.COMPUTE_BETA_API_VERSION,
base.ReleaseTrack.BETA)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateGroupPlacementGa(CreateGroupPlacement):
"""Create a Compute Engine group placement resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, compute_api.COMPUTE_GA_API_VERSION,
base.ReleaseTrack.GA)
CreateGroupPlacement.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine Group Placement Resource Policy.
""",
'EXAMPLES':
"""\
To create a Compute Engine group placement policy with two
availability domains, run:
$ {command} my-resource-policy --region=REGION --availability-domain-count=2
"""
}

View File

@@ -0,0 +1,128 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
def _CommonArgs(parser):
"""A helper function."""
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
parser.add_argument(
'--timezone',
help="""
Timezone used in interpreting schedule. The value of this field must be
a time zone name from the tz database
http://en.wikipedia.org/wiki/Tz_database
""")
parser.add_argument(
'--vm-start-schedule',
help="""
Schedule for starting the instance, specified using standard CRON format.
""")
parser.add_argument(
'--vm-stop-schedule',
help="""
Schedule for stopping the instance, specified using standard CRON format.
""")
parser.add_argument(
'--initiation-date',
type=arg_parsers.Datetime.Parse,
help="""
The start time of the schedule policy. The timestamp must be
an RFC3339 valid string.""")
parser.add_argument(
'--end-date',
type=arg_parsers.Datetime.Parse,
help="""The expiration time of the schedule policy. The timestamp must be
an RFC3339 valid string.""")
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateInstanceSchedulePolicy(base.CreateCommand):
"""Create a Compute Engine instance schedule resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeInstanceSchedulePolicy(policy_ref, args,
messages)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateInstanceSchedulePolicyBeta(CreateInstanceSchedulePolicy):
"""Create a Compute Engine instance schedule resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateInstanceSchedulePolicyAlpha(CreateInstanceSchedulePolicyBeta):
"""Create a Compute Engine instance schedule resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
CreateInstanceSchedulePolicy.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine instance schedule resource policy.
""",
'EXAMPLES':
"""\
To create an instance schedule resource policy that has a daily start operation at 8 AM and a daily stop operation at 5 PM for the UTC timezone, run:
$ {command} my-resource-policy --description="daily policy" --vm-start-schedule="0 8 * * *" --vm-stop-schedule="0 17 * * *" --timezone="UTC" --region=REGION
Use the initiation date and end date to limit when the policy is active. To create an instance schedule resource policy with initiation and end dates, run:
$ {command} my-resource-policy --description="limited daily policy" --vm-start-schedule="0 8 * * *" --vm-stop-schedule="0 17 * * *" --timezone="UTC" --region=REGION --initiation-date="2021-01-01T00:00:00.000Z" --end-date="2021-02-01T00:00:00.000Z"
"""
}

View File

@@ -0,0 +1,123 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils as compute_api
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
def _CommonArgs(parser, api_version, support_snapshot_region=False):
"""A helper function to build args based on different API version."""
messages = apis.GetMessagesModule('compute', api_version)
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddCycleFrequencyArgs(
parser,
flag_suffix='schedule',
start_time_help="""\
Start time for the disk snapshot schedule in UTC. For example, `--start-time="15:00"`.
""",
cadence_help='Snapshot schedule',
supports_weekly=True,
supports_hourly=True)
flags.AddSnapshotScheduleArgs(parser, messages, support_snapshot_region)
parser.display_info.AddCacheUpdater(None)
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.UniverseCompatible
class CreateSnapshotSchedule(base.CreateCommand):
"""Create a Compute Engine Snapshot Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, api_version=compute_api.COMPUTE_BETA_API_VERSION)
def Run(self, args):
return self._Run(args)
def _Run(self, args, support_snapshot_region=False):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeDiskSnapshotSchedulePolicy(
policy_ref, args, messages, support_snapshot_region)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateSnapshotScheduleBeta(CreateSnapshotSchedule):
"""Create a Compute Engine Snapshot Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(
parser,
api_version=compute_api.COMPUTE_BETA_API_VERSION,
support_snapshot_region=True,
)
def Run(self, args):
return self._Run(
args,
support_snapshot_region=True,
)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateSnapshotScheduleAlpha(CreateSnapshotScheduleBeta):
"""Create a Compute Engine Snapshot Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(
parser,
api_version=compute_api.COMPUTE_ALPHA_API_VERSION,
support_snapshot_region=True)
CreateSnapshotSchedule.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine Snapshot Schedule Resource Policy.
""",
'EXAMPLES':
"""\
The following command creates a Compute Engine Snapshot Schedule Resource Policy with a daily snapshot taken at 13:00Z and a one day snapshot retention policy.
$ {command} my-resource-policy --region=REGION --start-time=13:00 --daily-schedule --max-retention-days=1
"""
}

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The command group for cloud resource_policies creation."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.Group):
"""Create Compute Engine VM Maintenance Resource Policies."""

View File

@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Create VM maintenance resource policy concurrency-limit command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateVmMaintenanceConcurrentSet(base.CreateCommand):
"""Create a Compute Engine VM Maintenance Resource Policy.
*{command} creates a Resource Policy which can be attached to instances and
specifies amount of instances in the group that can go to maintenance.
"""
@staticmethod
def Args(parser):
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddMaxPercentArg(parser)
parser.display_info.AddCacheUpdater(None)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeVmMaintenanceConcurrentPolicy(policy_ref, args,
messages)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
CreateVmMaintenanceConcurrentSet.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine VM Maintenance Resource Policy that,
when attached to an instance, recognizes that instance as a part of a group of
instances where only up the configured amount of instances in that group can
undergo simultaneous maintenance.
""",
'EXAMPLES':
"""\
The following command creates a VM maintenance resource policy with a concurrency maintenance limit set to 1%.
$ {command} my-resource-policy --region=REGION
"""
}

View File

@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Create VM maintenance resource policy maintenance-window command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateVmMaintenanceMaintenanceWindow(base.CreateCommand):
"""Create a Compute Engine VM Maintenance Resource Policy.
*{command} creates a Compute Engine VM Maintenance Resource Policy
that, contains a window in which maintenance should start.
"""
@staticmethod
def Args(parser):
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddCycleFrequencyArgs(
parser,
flag_suffix='window',
start_time_help=('Start time of a four-hour window in which '
'maintenance should start in daily cadence.'),
cadence_help='Maintenance activity window',
has_restricted_start_times=True)
parser.display_info.AddCacheUpdater(None)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeVmMaintenanceMaintenanceWindow(policy_ref,
args, messages)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
CreateVmMaintenanceMaintenanceWindow.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine VM Maintenance Resource Policy that
contains time window in which maintenance should start.
""",
'EXAMPLES':
"""\
The following command creates a Compute Engine VM Maintenance Resource
Policy with a daily maintenance activity window that starts at 04:00Z.
$ {command} my-resource-policy --region=REGION --start-time=04:00 --daily-window
"""
}

View File

@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
def _CommonArgs(parser):
"""A helper function."""
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddTypeArgsForWorkloadPolicy(parser)
flags.AddMaxTopologyDistanceAndAcceleratorTopologyArgsForWorkloadPolicy(
parser
)
def ValidateWorkloadPolicy(resource_policy, messages, args):
"""Validates the workload policy."""
if args.accelerator_topology is not None and (
resource_policy.workloadPolicy.type
!= messages.ResourcePolicyWorkloadPolicy.TypeValueValuesEnum.HIGH_THROUGHPUT
):
raise exceptions.InvalidArgumentException(
'--accelerator-topology',
'Accelerator topology is only supported for high throughput workload'
' policies.',
)
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.GA)
class CreateWorkloadPolicyGa(base.CreateCommand):
"""Create a Compute Engine workload resource policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client),
)
messages = holder.client.messages
resource_policy = util.MakeWorkloadPolicy(policy_ref, args, messages)
ValidateWorkloadPolicy(resource_policy, messages, args)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region,
)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateWorkloadPolicyBeta(CreateWorkloadPolicyGa):
"""Create a Compute Engine workload resource policy."""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateWorkloadPolicyAlpha(CreateWorkloadPolicyGa):
"""Create a Compute Engine workload resource policy."""
CreateWorkloadPolicyGa.detailed_help = {
'DESCRIPTION': """Create a Compute Engine workload resource policy.""",
'EXAMPLES': """\
To create a workload policy:
$ {command} NAME --type=TYPE
"""
}

View File

@@ -0,0 +1,125 @@
# -*- 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.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils as compute_api
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
_DEPRECATION_WARNING = """
`create-snapshot-schedule` is deprecated.
Use `compute resource-policies create snapshot-schedule` instead.
"""
def _CommonArgs(parser, api_version, support_snapshot_region=False):
"""A helper function to build args based on different API version."""
messages = apis.GetMessagesModule('compute', api_version)
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddCycleFrequencyArgs(
parser,
flag_suffix='schedule',
start_time_help="""\
Start time for the disk snapshot schedule. See $ gcloud topic datetimes for information on time formats.
""",
cadence_help='Snapshot schedule',
supports_weekly=True,
supports_hourly=True)
flags.AddSnapshotScheduleArgs(parser, messages, support_snapshot_region)
parser.display_info.AddCacheUpdater(None)
@base.Deprecate(is_removed=False, warning=_DEPRECATION_WARNING)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
@base.UniverseCompatible
class CreateSnapshotScheduleBeta(base.CreateCommand):
"""Create a Compute Engine Snapshot Schedule Resource Policy.
*{command} creates a Resource Policy which can be attached to disks and
specifies a schedule for taking disk snapshots and how long these snapshots
should be retained.
"""
@staticmethod
def Args(parser):
_CommonArgs(
parser,
api_version=compute_api.COMPUTE_BETA_API_VERSION,
support_snapshot_region=True,
)
def Run(self, args):
return self._Run(args, support_snapshot_region=True)
def _Run(self, args, support_snapshot_region=False):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeDiskSnapshotSchedulePolicy(
policy_ref, args, messages, support_snapshot_region)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
@base.Deprecate(is_removed=False, warning=_DEPRECATION_WARNING)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateSnapshotScheduleAlpha(CreateSnapshotScheduleBeta):
"""Create a Compute Engine Snapshot Schedule Resource Policy.
*{command} creates a Resource Policy which can be attached to disks and
specifies a schedule for taking disk snapshots and how long these snapshots
should be retained.
"""
@staticmethod
def Args(parser):
_CommonArgs(
parser,
api_version=compute_api.COMPUTE_ALPHA_API_VERSION,
support_snapshot_region=True)
CreateSnapshotScheduleBeta.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine Snapshot Schedule Resource Policy.
""",
'EXAMPLES':
"""\
The following command creates a Compute Engine Snapshot Schedule Resource Policy with a daily snapshot and a one day snapshot retention policy.
$ {command} my-resource-policy --region=REGION --start-time=04:00Z --daily-schedule --max-retention-days=1
"""
}

View File

@@ -0,0 +1,88 @@
# -*- 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.
"""Create resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
_DEPRECATION_WARNING = """
`create-vm-maintenance` is deprecated.
Use `compute resource-policies create vm-maintenance` instead.
"""
@base.Deprecate(is_removed=False, warning=_DEPRECATION_WARNING)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateVmMaintenance(base.CreateCommand):
"""Create a Compute Engine VM Maintenance Resource Policy.
*{command} creates a Resource Policy which can be attached to instances and
specifies what kind of maintenance operations may be performed and when
they can be performed.
"""
@staticmethod
def Args(parser):
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddCycleFrequencyArgs(
parser,
flag_suffix='window',
start_time_help=('Start time of a four-hour window in which '
'maintenance should start in daily cadence.'),
cadence_help='Maintenance activity window',
has_restricted_start_times=True)
parser.display_info.AddCacheUpdater(None)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
resource_policy = util.MakeVmMaintenancePolicy(
policy_ref, args, messages)
create_request = messages.ComputeResourcePoliciesInsertRequest(
resourcePolicy=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Insert', create_request)])[0]
CreateVmMaintenance.detailed_help = {
'DESCRIPTION':
"""\
Create a Compute Engine VM Maintenance Resource Policy.
""",
'EXAMPLES':
"""\
The following command creates a Compute Engine VM Maintenance Resource Policy with a daily maintenance activity window that starts at 04:00Z.
$ {command} my-resource-policy --region=REGION --start-time=04:00Z --daily-window
"""
}

View File

@@ -0,0 +1,65 @@
# -*- 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.
"""Delete resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
class Delete(base.DeleteCommand):
"""Delete a Compute Engine resource policy."""
@staticmethod
def Args(parser):
flags.MakeResourcePolicyArg().AddArgument(parser)
parser.display_info.AddCacheUpdater(None)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
request = messages.ComputeResourcePoliciesDeleteRequest(
resourcePolicy=policy_ref.Name(),
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Delete', request)])
Delete.detailed_help = {
'DESCRIPTION':
"""\
Delete a Compute Engine resource policy.
""",
'EXAMPLES':
"""\
The following command deletes a Compute Engine resource policy.
$ {command} my-resource-policy --region=REGION
"""
}

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Describe resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
class Describe(base.DescribeCommand):
"""Describe a Compute Engine resource policy."""
@staticmethod
def Args(parser):
flags.MakeResourcePolicyArg().AddArgument(parser)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
messages = holder.client.messages
request = messages.ComputeResourcePoliciesGetRequest(
resourcePolicy=policy_ref.Name(),
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Get', request)])[0]
Describe.detailed_help = {
'DESCRIPTION':
"""\
Describe a Compute Engine resource policy.
""",
'EXAMPLES':
"""\
The following command shows the details of a Compute Engine resource policy.
$ {command} my-resource-policy --region=REGION
"""
}

View File

@@ -0,0 +1,33 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM policy for a Compute Engine resource policy.
description: |
*{command}* displays the IAM policy associated with a
Compute Engine resource policy in a project. If formatted as JSON,
the output can be edited and used as a policy file for
set-iam-policy. The output includes an "etag" field
identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given resource policy, run:
$ {command} my-policy --region=REGION
request:
collection: compute.resourcePolicies
use_relative_name: false
api_version: v1
BETA:
api_version: beta
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=optionsRequestedPolicyVersion
ALPHA:
api_version: alpha
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=optionsRequestedPolicyVersion
arguments:
resource:
help_text: The resource policy to display the IAM policy for.
spec: !REF googlecloudsdk.command_lib.compute.resources:resource_policy

View File

@@ -0,0 +1,54 @@
# -*- 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.
"""List resource policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import lister
from googlecloudsdk.calliope import base
class List(base.ListCommand):
"""List Compute Engine resource policies."""
@staticmethod
def Args(parser):
parser.display_info.AddFormat("""\
table(
name,
description,
region,
creationTimestamp
)""")
# TODO(b/69426858): Remove these deprecated flags.
lister.AddRegionsArg(parser, hidden=True)
parser.display_info.AddCacheUpdater(None)
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
request_data = lister.ParseRegionalFlags(args, holder.resources)
list_implementation = lister.RegionalLister(
client, client.apitools_client.resourcePolicies)
return lister.Invoke(request_data, list_implementation)
List.detailed_help = base_classes.GetRegionalListerHelp('resource policies')

View File

@@ -0,0 +1,36 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Set the IAM policy for a Compute Engine resource policy.
description: |
Set the IAM policy for the given resource policy as defined in a JSON or YAML file.
examples: |
The following command will read am IAM policy defined in a JSON file
'policy.json' and set it for the resource policy `my-policy`:
$ {command} my-policy --region=REGION policy.json
See https://cloud.google.com/iam/docs/managing-policies for details of the
policy file format and contents.
request:
collection: compute.resourcePolicies
use_relative_name: false
modify_request_hooks:
- googlecloudsdk.command_lib.iam.hooks:UseMaxRequestedPolicyVersion:api_field=regionSetPolicyRequest.policy.version
api_version: v1
BETA:
api_version: beta
ALPHA:
api_version: alpha
arguments:
resource:
help_text: The resource policy to set the IAM policy for.
spec: !REF googlecloudsdk.command_lib.compute.resources:resource_policy
iam:
set_iam_policy_request_path: regionSetPolicyRequest
message_type_overrides:
policy: Policy
set_iam_policy_request: ComputeResourcePoliciesSetIamPolicyRequest

View File

@@ -0,0 +1,27 @@
# -*- 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.
"""The command group for cloud resource_policies update."""
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 Update(base.Group):
"""Update Compute Engine Resource Policies."""

View File

@@ -0,0 +1,110 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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.
"""Update Instance schedule policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
def _CommonArgs(parser):
"""A helper function to build args."""
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddInstanceScheduleArgs(parser)
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class UpdateInstanceSchedule(base.UpdateCommand):
"""Update a Compute Engine Instance Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
def Run(self, args):
return self._Run(args)
def _Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
messages = holder.client.messages
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client),
)
resource_policy = util.MakeInstanceSchedulePolicyForUpdate(
policy_ref, args, messages
)
patch_request = messages.ComputeResourcePoliciesPatchRequest(
resourcePolicy=policy_ref.Name(),
resourcePolicyResource=resource_policy,
project=policy_ref.project,
region=policy_ref.region,
)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Patch', patch_request)])
@base.ReleaseTracks(base.ReleaseTrack.BETA)
@base.DefaultUniverseOnly
class UpdateInstanceScheduleBeta(UpdateInstanceSchedule):
"""Update a Compute Engine Instance Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
def Run(self, args):
return self._Run(args)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class UpdateInstanceScheduleAlpha(UpdateInstanceSchedule):
"""Update a Compute Engine Instance Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser)
def Run(self, args):
return self._Run(args)
UpdateInstanceSchedule.detailed_help = {
'DESCRIPTION': """\
Update a Compute Engine Instance Schedule Resource Policy.
""",
'EXAMPLES': """\
To update an instance schedule resource policy with specified parameters:
$ {command} NAME \
--region=REGION
--timezone=UTC \
--vm-start-schedule="0 7 * * *" \
--vm-stop-schedule="0 17 * * *"
""",
}

View File

@@ -0,0 +1,117 @@
# -*- 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.
"""Update snapshot schedule policy command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import utils as compute_api
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.compute import flags as compute_flags
from googlecloudsdk.command_lib.compute.resource_policies import flags
from googlecloudsdk.command_lib.compute.resource_policies import util
def _CommonArgs(parser, api_version):
"""A helper function to build args."""
flags.MakeResourcePolicyArg().AddArgument(parser)
flags.AddCommonArgs(parser)
flags.AddCycleFrequencyArgs(
parser,
flag_suffix='schedule',
start_time_help="""\
Start time for the disk snapshot schedule in UTC. For example, `--start-time="15:00"`.
""",
cadence_help='Snapshot schedule',
supports_weekly=True,
supports_hourly=True,
required=False)
flags.AddSnapshotLabelArgs(parser)
flags.AddSnapshotMaxRetentionDaysArgs(parser, required=False)
messages = apis.GetMessagesModule('compute', api_version)
flags.AddOnSourceDiskDeleteArgs(parser, messages)
@base.ReleaseTracks(base.ReleaseTrack.GA)
class UpdateSnapshotSchedule(base.UpdateCommand):
"""Update a Compute Engine Snapshot Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, compute_api.COMPUTE_GA_API_VERSION)
def Run(self, args):
return self._Run(args)
def _Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
messages = holder.client.messages
policy_ref = flags.MakeResourcePolicyArg().ResolveAsResource(
args,
holder.resources,
scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
resource_policy = util.MakeDiskSnapshotSchedulePolicyForUpdate(
policy_ref, args, messages)
patch_request = messages.ComputeResourcePoliciesPatchRequest(
resourcePolicy=policy_ref.Name(),
resourcePolicyResource=resource_policy,
project=policy_ref.project,
region=policy_ref.region)
service = holder.client.apitools_client.resourcePolicies
return client.MakeRequests([(service, 'Patch', patch_request)])
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateSnapshotScheduleBeta(UpdateSnapshotSchedule):
"""Update a Compute Engine Snapshot Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, compute_api.COMPUTE_BETA_API_VERSION)
def Run(self, args):
return self._Run(args)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdateSnapshotScheduleAlpha(UpdateSnapshotSchedule):
"""Update a Compute Engine Snapshot Schedule Resource Policy."""
@staticmethod
def Args(parser):
_CommonArgs(parser, compute_api.COMPUTE_ALPHA_API_VERSION)
def Run(self, args):
return self._Run(args)
UpdateSnapshotSchedule.detailed_help = {
'DESCRIPTION':
"""\
Update a Compute Engine Snapshot Schedule Resource Policy.
""",
'EXAMPLES':
"""\
The following command updates a Compute Engine Snapshot Schedule Resource Policy to take a daily snapshot at 13:00 UTC
$ {command} my-resource-policy --region=REGION --start-time=13:00 --daily-schedule
"""
}