HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //lib/google-cloud-sdk/lib/surface/assured/workloads/create.py
# -*- 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.
"""Command to create a new Assured Workloads environment."""

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from googlecloudsdk.api_lib.assured import endpoint_util
from googlecloudsdk.api_lib.assured import message_util
from googlecloudsdk.api_lib.assured import workloads as apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.assured import flags
from googlecloudsdk.core import log
import six

_DETAILED_HELP = {
    'DESCRIPTION':
        'Create a new Assured Workloads environment',
    'EXAMPLES':
        """ \
        The following example command creates a new Assured Workloads environment with these properties:

        * belonging to an organization with ID 123
        * located in the `us-central1` region
        * display name `Test-Workload`
        * compliance regime `FEDRAMP_MODERATE` (other options include: `FEDRAMP_HIGH`, `IL4` and `CJIS`)
        * billing account `billingAccounts/456`
        * first key rotation set for 10:15am on the December 30, 2020
        * key rotation interval set for every 48 hours
        * with the label: key = 'LabelKey1', value = 'LabelValue1'
        * with the label: key = 'LabelKey2', value = 'LabelValue2'

          $ {command} --organization=123 --location=us-central1 --display-name=Test-Workload --compliance-regime=FEDRAMP_MODERATE --billing-account=billingAccounts/456 --next-rotation-time=2020-12-30T10:15:00.00Z --rotation-period=172800s --labels LabelKey1=LabelValue1,LabelKey2=LabelValue2

        """,
}


@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
  """Create a new Assured Workloads environment."""

  detailed_help = _DETAILED_HELP

  @staticmethod
  def Args(parser):
    flags.AddCreateWorkloadFlags(parser)

  def Run(self, args):
    """Run the create command."""
    with endpoint_util.AssuredWorkloadsEndpointOverridesFromRegion(
        release_track=six.text_type(self.ReleaseTrack()), region=args.location):
      parent = message_util.CreateAssuredParent(
          organization_id=args.organization, location=args.location)
      workload = message_util.CreateBetaAssuredWorkload(
          display_name=args.display_name,
          compliance_regime=args.compliance_regime,
          billing_account=args.billing_account,
          next_rotation_time=args.next_rotation_time,
          rotation_period=args.rotation_period,
          labels=args.labels)
      client = apis.WorkloadsClient(release_track=self.ReleaseTrack())
      self.created_resource = client.Create(
          external_id=args.external_identifier,
          parent=parent,
          workload=workload)
      return self.created_resource

  def Epilog(self, resources_were_displayed):
    log.CreatedResource(self.created_resource.name,
                        kind='Assured Workloads environment')