Пример #1
0
    def Run(self, args):
        datafusion = df.Datafusion()
        instance_ref = args.CONCEPTS.instance.Parse()

        request = datafusion.messages.DatafusionProjectsLocationsInstancesRestartRequest(
            name=instance_ref.RelativeName())

        operation = datafusion.client.projects_locations_instances.Restart(
            request)

        if args. async:
            log.CreatedResource(instance_ref.RelativeName(),
                                kind='instance',
                                is_async=True)
            return operation
        else:
            waiter.WaitFor(
                operation_poller.OperationPoller(),
                operation.name,
                'Waiting for [{}] to complete. This may take several minutes.'.
                format(operation.name),
                wait_ceiling_ms=df.OPERATION_TIMEOUT)
            log.CreatedResource(instance_ref.RelativeName(),
                                kind='instance',
                                is_async=False)
Пример #2
0
    def Run(self, args):
        datafusion = df.Datafusion()
        instance_ref = args.CONCEPTS.instance.Parse()

        # Prompt for zone if it is not specified
        version = args.version
        if not version:
            version = ''
        zone = args.zone
        if not zone:
            zone = ''
        options = args.options
        if not options:
            options = {}
        labels = args.labels
        if not labels:
            labels = {}
        enable_stackdriver_logging = args.enable_stackdriver_logging
        if not enable_stackdriver_logging:
            enable_stackdriver_logging = False
        enable_stackdriver_monitoring = args.enable_stackdriver_monitoring
        if not enable_stackdriver_monitoring:
            enable_stackdriver_monitoring = False
        edition_mapper = arg_utils.ChoiceEnumMapper(
            'edition_enum',
            df.Datafusion().messages.Instance.TypeValueValuesEnum)
        edition = edition_mapper.GetEnumForChoice(args.edition)
        instance = datafusion.messages.Instance(
            zone=zone,
            type=edition,
            version=version,
            enableStackdriverLogging=enable_stackdriver_logging,
            enableStackdriverMonitoring=enable_stackdriver_monitoring,
            options=encoding.DictToAdditionalPropertyMessage(
                options, datafusion.messages.Instance.OptionsValue, True),
            labels=encoding.DictToAdditionalPropertyMessage(
                labels, datafusion.messages.Instance.LabelsValue, True))

        req = datafusion.messages.DatafusionProjectsLocationsInstancesCreateRequest(
            instance=instance,
            instanceId=instance_ref.Name(),
            parent=instance_ref.Parent().RelativeName())

        operation = datafusion.client.projects_locations_instances.Create(req)

        if args.async_:
            log.CreatedResource(instance_ref.RelativeName(),
                                kind='instance',
                                is_async=True)
            return operation
        else:
            waiter.WaitFor(
                operation_poller.OperationPoller(),
                operation.name,
                'Waiting for [{}] to complete. This may take several minutes.'.
                format(operation.name),
                wait_ceiling_ms=df.OPERATION_TIMEOUT)
            log.CreatedResource(instance_ref.RelativeName(),
                                kind='instance',
                                is_async=False)
Пример #3
0
    def Run(self, args):
        datafusion = df.Datafusion()
        instance_ref = args.CONCEPTS.instance.Parse()

        name = instance_ref.RelativeName()
        req = datafusion.messages.DatafusionProjectsLocationsInstancesDeleteRequest(
            name=instance_ref.RelativeName())

        console_io.PromptContinue(message="'{0}' will be deleted".format(name),
                                  cancel_on_no=True,
                                  cancel_string='Deletion aborted by user.',
                                  throw_if_unattended=True)

        operation = datafusion.client.projects_locations_instances.Delete(req)

        log.status.write('Deleting [{0}] with operation [{1}].'.format(
            instance_ref.RelativeName(), operation.name))

        if args.async_:
            return operation
        else:
            waiter.WaitFor(
                operation_poller.OperationPoller(), operation.name,
                'Waiting for [{}] to complete. This may take several minutes'.
                format(operation.name))
Пример #4
0
    def Run(self, args):
        datafusion = df.Datafusion()
        operation_ref = args.CONCEPTS.operation.Parse()

        req = datafusion.messages.DatafusionProjectsLocationsOperationsGetRequest(
            name=operation_ref.RelativeName())

        operation = datafusion.client.projects_locations_operations.Get(req)

        waiter.WaitFor(operation_poller.OperationPoller(),
                       operation.name,
                       'Waiting for [{}] to complete.'.format(operation.name),
                       wait_ceiling_ms=self.WAIT_CEILING_MS)
Пример #5
0
    def Run(self, args):
        datafusion = df.Datafusion()
        instance_ref = args.CONCEPTS.instance.Parse()

        labels = args.labels or {}
        enable_stackdriver_logging = args.enable_stackdriver_logging or False
        enable_stackdriver_monitoring = args.enable_stackdriver_monitoring or False
        version = args.version
        instance = datafusion.messages.Instance(
            name=instance_ref.RelativeName(),
            version=version,
            enableStackdriverLogging=enable_stackdriver_logging,
            enableStackdriverMonitoring=enable_stackdriver_monitoring,
            labels=encoding.DictToAdditionalPropertyMessage(
                labels, datafusion.messages.Instance.LabelsValue, True))
        request = datafusion.messages.DatafusionProjectsLocationsInstancesPatchRequest(
            instance=instance, name=instance_ref.RelativeName())

        operation = datafusion.client.projects_locations_instances.Patch(
            request)

        if args.async_:
            log.CreatedResource(instance_ref.RelativeName(),
                                kind='instance',
                                is_async=True)
            return operation
        else:
            waiter.WaitFor(
                operation_poller.OperationPoller(),
                operation.name,
                'Waiting for [{}] to complete. This may take several minutes.'.
                format(operation.name),
                wait_ceiling_ms=df.OPERATION_TIMEOUT)
            log.UpdatedResource(instance_ref.RelativeName(),
                                kind='instance',
                                is_async=False)
Пример #6
0
  def Run(self, args):
    datafusion = df.Datafusion()
    instance_ref = args.CONCEPTS.instance.Parse()

    # Prompt for zone if it is not specified
    zone = args.zone
    if not zone:
      holder = compute_base.ComputeApiHolder(self.ReleaseTrack())
      _, zone = scope_prompter.PromptForScope(
          resource_name='instance',
          underspecified_names=[instance_ref.Name()],
          scopes=[compute_scope.ScopeEnum.ZONE],
          default_scope=None,
          scope_lister=flags.GetDefaultScopeLister(holder.client))

    options = args.options
    if not options:
      options = {}
    labels = args.labels
    if not labels:
      labels = {}
    enable_stackdriver_logging = args.enable_stackdriver_logging
    if not enable_stackdriver_logging:
      enable_stackdriver_logging = False
    enable_stackdriver_monitoring = args.enable_stackdriver_monitoring
    if not enable_stackdriver_monitoring:
      enable_stackdriver_monitoring = False
    edition = args.edition.upper()
    if edition == 'ENTERPRISE':
      edition = datafusion.messages.Instance.TypeValueValuesEnum.ENTERPRISE
    else:
      edition = datafusion.messages.Instance.TypeValueValuesEnum.BASIC
    instance = datafusion.messages.Instance(
        zone=zone,
        type=edition,
        enableStackdriverLogging=enable_stackdriver_logging,
        enableStackdriverMonitoring=enable_stackdriver_monitoring,
        options=encoding.DictToAdditionalPropertyMessage(
            options, datafusion.messages.Instance.OptionsValue, True),
        labels=encoding.DictToAdditionalPropertyMessage(
            labels, datafusion.messages.Instance.LabelsValue, True))

    req = datafusion.messages.DatafusionProjectsLocationsInstancesCreateRequest(
        instance=instance,
        instanceId=instance_ref.Name(),
        parent=instance_ref.Parent().RelativeName())

    operation = datafusion.client.projects_locations_instances.Create(req)

    if args.async:
      log.CreatedResource(
          instance_ref.RelativeName(), kind='instance', is_async=True)
      return operation
    else:
      waiter.WaitFor(
          operation_poller.OperationPoller(),
          operation.name,
          'Waiting for [{}] to complete. This may take several minutes.'.format(
              operation.name),
          wait_ceiling_ms=df.OPERATION_TIMEOUT)
      log.CreatedResource(
          instance_ref.RelativeName(), kind='instance', is_async=False)