Example #1
0
    def Run(self, args):
        flags.ValidateDiskSize('--disk-size', args.disk_size)
        env_ref = args.CONCEPTS.environment.Parse()
        env_name = env_ref.Name()
        if not command_util.IsValidEnvironmentName(env_name):
            raise command_util.InvalidUserInputError(
                'Invalid environment name: [{}]. Must match pattern: {}'.
                format(env_name,
                       command_util.ENVIRONMENT_NAME_PATTERN.pattern))

        zone_ref = parsers.ParseZone(args.zone) if args.zone else None
        zone = zone_ref.RelativeName() if zone_ref else None
        machine_type = None
        network = None
        subnetwork = None
        if args.machine_type:
            machine_type = parsers.ParseMachineType(
                args.machine_type,
                fallback_zone=zone_ref.Name()
                if zone_ref else None).RelativeName()
        if args.network:
            network = parsers.ParseNetwork(args.network).RelativeName()
        if args.subnetwork:
            subnetwork = parsers.ParseSubnetwork(
                args.subnetwork,
                fallback_region=env_ref.Parent().Name()).RelativeName()
        operation = environments_api_util.Create(
            env_ref,
            args.node_count,
            labels=args.labels,
            location=zone,
            machine_type=machine_type,
            network=network,
            subnetwork=subnetwork,
            env_variables=args.env_variables,
            airflow_config_overrides=args.airflow_configs,
            service_account=args.service_account,
            oauth_scopes=args.oauth_scopes,
            tags=args.tags,
            disk_size_gb=args.disk_size >> 30,
            release_track=self.ReleaseTrack())
        details = 'with operation [{0}]'.format(operation.name)
        if args. async:
            log.CreatedResource(env_ref.RelativeName(),
                                kind='environment',
                                is_async=True,
                                details=details)
            return operation
        else:
            try:
                operations_api_util.WaitForOperation(
                    operation,
                    'Waiting for [{}] to be created with [{}]'.format(
                        env_ref.RelativeName(), operation.name),
                    release_track=self.ReleaseTrack())
            except command_util.OperationError as e:
                raise command_util.EnvironmentCreateError(
                    'Error creating [{}]: {}'.format(env_ref.RelativeName(),
                                                     str(e)))
Example #2
0
    def Run(self, args):
        self.ParseIpAliasConfigOptions(args)
        self.ParsePrivateEnvironmentConfigOptions(args)
        if self._support_web_server_cloud_sql_private_ip_ranges:
            self.ParsePrivateEnvironmentWebServerCloudSqlRanges(args)

        flags.ValidateDiskSize('--disk-size', args.disk_size)
        self.env_ref = args.CONCEPTS.environment.Parse()
        env_name = self.env_ref.Name()
        if not command_util.IsValidEnvironmentName(env_name):
            raise command_util.InvalidUserInputError(
                'Invalid environment name: [{}]. Must match pattern: {}'.
                format(env_name,
                       command_util.ENVIRONMENT_NAME_PATTERN.pattern))

        self.zone_ref = parsers.ParseZone(args.zone) if args.zone else None
        self.zone = self.zone_ref.RelativeName() if self.zone_ref else None
        self.machine_type = None
        self.network = None
        self.subnetwork = None
        if args.machine_type:
            self.machine_type = parsers.ParseMachineType(
                args.machine_type,
                fallback_zone=self.zone_ref.Name()
                if self.zone_ref else None).RelativeName()
        if args.network:
            self.network = parsers.ParseNetwork(args.network).RelativeName()
        if args.subnetwork:
            self.subnetwork = parsers.ParseSubnetwork(
                args.subnetwork,
                fallback_region=self.env_ref.Parent().Name()).RelativeName()

        self.image_version = None
        if args.airflow_version:
            self.image_version = image_versions_util.ImageVersionFromAirflowVersion(
                args.airflow_version)
        elif args.image_version:
            self.image_version = args.image_version

        operation = self.GetOperationMessage(args)

        details = 'with operation [{0}]'.format(operation.name)
        if args.async_:
            log.CreatedResource(self.env_ref.RelativeName(),
                                kind='environment',
                                is_async=True,
                                details=details)
            return operation
        else:
            try:
                operations_api_util.WaitForOperation(
                    operation,
                    'Waiting for [{}] to be created with [{}]'.format(
                        self.env_ref.RelativeName(), operation.name),
                    release_track=self.ReleaseTrack())
            except command_util.OperationError as e:
                raise command_util.EnvironmentCreateError(
                    'Error creating [{}]: {}'.format(
                        self.env_ref.RelativeName(), six.text_type(e)))
Example #3
0
 def Run(self, args):
     operation_ref = args.CONCEPTS.operation.Parse()
     operation = operations_api_util.Get(operation_ref,
                                         release_track=self.ReleaseTrack())
     operations_api_util.WaitForOperation(
         operation,
         'Waiting for [{}] to complete.'.format(operation.name),
         release_track=self.ReleaseTrack())
 def _SynchronousExecution(self, env_resource, operation):
     try:
         operations_api_util.WaitForOperation(
             operation,
             'Waiting for [{}] to be updated with [{}]'.format(
                 env_resource.RelativeName(), operation.name),
             release_track=self.ReleaseTrack())
     except command_util.Error as e:
         raise command_util.Error(
             'Error restarting web server [{}]: {}'.format(
                 env_resource.RelativeName(), six.text_type(e)))
 def _SynchronousExecution(self, env_resource, operation):
     try:
         operations_api_util.WaitForOperation(
             operation,
             'Waiting for [{}] to be updated with [{}]'.format(
                 env_resource.RelativeName(), operation.name),
             release_track=self.ReleaseTrack())
     except command_util.Error as e:
         raise command_util.Error(
             'Failed to load the snapshot of the environment [{}]: {}'.
             format(env_resource.RelativeName(), six.text_type(e)))
def Patch(env_resource,
          field_mask,
          patch,
          is_async,
          release_track=base.ReleaseTrack.GA):
    """Patches an Environment, optionally waiting for the operation to complete.

  This function is intended to perform the common work of an Environment
  patching command's Run method. That is, calling the patch API method and
  waiting for the result or immediately returning the Operation.

  Args:
    env_resource: googlecloudsdk.core.resources.Resource, Resource representing
        the Environment to be patched
    field_mask: str, a field mask string containing comma-separated paths to be
        patched
    patch: Environment, a patch Environment containing updated values to apply
    is_async: bool, whether or not to perform the patch asynchronously
    release_track: base.ReleaseTrack, the release track of command. Will dictate
        which Composer client library will be used.

  Returns:
    an Operation corresponding to the Patch call if `is_async` is True;
    otherwise None is returned after the operation is complete

  Raises:
    command_util.Error: if `is_async` is False and the operation encounters
    an error
  """
    operation = environments_api_util.Patch(env_resource,
                                            patch,
                                            field_mask,
                                            release_track=release_track)
    details = 'with operation [{0}]'.format(operation.name)
    if is_async:
        log.UpdatedResource(env_resource.RelativeName(),
                            kind='environment',
                            is_async=True,
                            details=details)
        return operation

    try:
        operations_api_util.WaitForOperation(
            operation,
            'Waiting for [{}] to be updated with [{}]'.format(
                env_resource.RelativeName(), operation.name),
            release_track=release_track)
    except command_util.Error as e:
        raise command_util.Error('Error updating [{}]: {}'.format(
            env_resource.RelativeName(), six.text_type(e)))
 def Wait(self):
   """Polls pending deletions and returns when they are complete."""
   encountered_errors = False
   for pending_delete in self.pending_deletes:
     try:
       operations_api_util.WaitForOperation(
           pending_delete.operation, 'Waiting for [{}] to be deleted'.format(
               pending_delete.environment_name))
     except command_util.OperationError as e:
       encountered_errors = True
       log.DeletedResource(
           pending_delete.environment_name,
           kind='environment',
           is_async=False,
           failed=six.text_type(e))
   return encountered_errors
    def Run(self, args):
        flags.ValidateDiskSize('--disk-size', args.disk_size)
        self.env_ref = args.CONCEPTS.environment.Parse()
        env_name = self.env_ref.Name()
        if not command_util.IsValidEnvironmentName(env_name):
            raise command_util.InvalidUserInputError(
                'Invalid environment name: [{}]. Must match pattern: {}'.
                format(env_name,
                       command_util.ENVIRONMENT_NAME_PATTERN.pattern))

        self.zone_ref = parsers.ParseZone(args.zone) if args.zone else None
        self.zone = self.zone_ref.RelativeName() if self.zone_ref else None
        self.machine_type = None
        self.network = None
        self.subnetwork = None
        if args.machine_type:
            self.machine_type = parsers.ParseMachineType(
                args.machine_type,
                fallback_zone=self.zone_ref.Name()
                if self.zone_ref else None).RelativeName()
        if args.network:
            self.network = parsers.ParseNetwork(args.network).RelativeName()
        if args.subnetwork:
            self.subnetwork = parsers.ParseSubnetwork(
                args.subnetwork,
                fallback_region=self.env_ref.Parent().Name()).RelativeName()

        operation = self.GetOperationMessage(args)

        details = 'with operation [{0}]'.format(operation.name)
        if args. async:
            log.CreatedResource(self.env_ref.RelativeName(),
                                kind='environment',
                                is_async=True,
                                details=details)
            return operation
        else:
            try:
                operations_api_util.WaitForOperation(
                    operation,
                    'Waiting for [{}] to be created with [{}]'.format(
                        self.env_ref.RelativeName(), operation.name),
                    release_track=self.ReleaseTrack())
            except command_util.OperationError as e:
                raise command_util.EnvironmentCreateError(
                    'Error creating [{}]: {}'.format(
                        self.env_ref.RelativeName(), str(e)))
Example #9
0
 def Run(self, args):
     operation_ref = args.CONCEPTS.operation.Parse()
     operation = operations_api_util.Get(operation_ref)
     operations_api_util.WaitForOperation(
         operation, 'Waiting for [{}] to complete.'.format(operation.name))