Esempio n. 1
0
def TriggerSourceStages():
    return [
        progress_tracker.Stage('Creating Event Source...', key=SOURCE_READY),
        progress_tracker.Stage('Subscribing Service...',
                               key=_TRIGGER_SUBSCRIBED),
        progress_tracker.Stage('Linking Trigger...', key=_TRIGGER_DEPENDENCY),
    ]
Esempio n. 2
0
def _ServiceStages():
    """Return a new mapping from conditions to Stages."""
    return collections.OrderedDict([
        ('ConfigurationsReady',
         progress_tracker.Stage('Creating Revision...')),
        ('RoutesReady', progress_tracker.Stage('Routing traffic...'))
    ])
Esempio n. 3
0
def ServiceStages():
    """Return the progress tracker Stages for conditions of a Service."""
    return [
        progress_tracker.Stage('Creating Revision...',
                               key=SERVICE_CONFIGURATIONS_READY),
        progress_tracker.Stage('Routing traffic...', key=SERVICE_ROUTES_READY)
    ]
def _GetProgressTracker(patch_job_name):
  stages = [
      progress_tracker.Stage(
          'Generating instance details...', key='pre-summary'),
      progress_tracker.Stage(
          'Reporting instance details...', key='with-summary')
  ]
  return progress_tracker.StagedProgressTracker(
      message='Executing patch job [{0}]'.format(patch_job_name), stages=stages)
Esempio n. 5
0
def ServiceStages(include_iam_policy_set=False):
  """Return the progress tracker Stages for conditions of a Service."""
  stages = [
      progress_tracker.Stage(
          'Creating Revision...', key=SERVICE_CONFIGURATIONS_READY),
      _NewRoutingTrafficStage()]
  if include_iam_policy_set:
    stages.append(progress_tracker.Stage(
        'Setting IAM Policy...', key=SERVICE_IAM_POLICY_SET))
  return stages
Esempio n. 6
0
def _CreateProgressTracker(patch_job_name):
  """Creates a progress tracker to display patch status synchronously."""
  stages = [
      progress_tracker.Stage(
          'Generating instance details...', key='pre-summary'),
      progress_tracker.Stage(
          'Reporting instance details...', key='with-summary')
  ]
  return progress_tracker.StagedProgressTracker(
      message='Executing patch job [{0}]'.format(patch_job_name), stages=stages)
Esempio n. 7
0
def ApplyStages():
  """Returns the progress tracker Stages for apply command.

  Returns:
    array of progress_tracker.Stage
  """
  return [
      progress_tracker.Stage('Saving Configuration...', key=UPDATE_APPLICATION),
      progress_tracker.Stage(
          'Actuating Configuration...', key=CREATE_DEPLOYMENT),
  ]
Esempio n. 8
0
 def SetUp(self):
   self._interactive_mock = self.StartObjectPatch(console_io, 'IsInteractive')
   self._interactive_mock.return_value = True
   self.console_size_mock = self.StartObjectPatch(
       console_attr.ConsoleAttr, 'GetTermSize')
   properties.VALUES.core.interactive_ux_style.Set(
       properties.VALUES.core.InteractiveUXStyles.NORMAL.name)
   self.stages = [
       progress_tracker.Stage('Hello World...', key='a'),
       progress_tracker.Stage('A' + 'h' * 15 + '...', key='b')]
   self.keys = [s.key for s in self.stages]
Esempio n. 9
0
def JobStages(include_completion=False):
    """Returns the list of progress tracker Stages for Jobs."""
    stages = [
        progress_tracker.Stage('Provisioning resources...',
                               key=_RESOURCES_AVAILABLE)
    ]
    if include_completion:
        stages.append(progress_tracker.Stage('Starting job...', key=_STARTED))
        # Normally the last terminal condition (e.g. Ready or in this case
        # Completed) wouldn't be included as a stage since it gates the entire
        # progress tracker. But in this case we want to include it so we can show
        # updates on this stage while the job is running.
        stages.append(progress_tracker.Stage('Running job...', key=_COMPLETED))
    return stages
Esempio n. 10
0
def IntegrationDeleteStages():
  """Returns the progress tracker Stages for deleting an Integration.

  Returns:
    list of progress_tracker.Stage
  """
  return [
      progress_tracker.Stage('Unbinding services...', key=UPDATE_APPLICATION),
      progress_tracker.Stage('Configuring services...', key=CREATE_DEPLOYMENT),
      progress_tracker.Stage(
          'Deleting Integration resources...', key=UNDEPLOY_RESOURCE),
      progress_tracker.Stage(
          'Saving Integration configurations...', key=CLEANUP_CONFIGURATION)
  ]
Esempio n. 11
0
def ServiceStages(include_iam_policy_set=False,
                  include_route=True,
                  include_build=False):
    """Return the progress tracker Stages for conditions of a Service."""
    stages = []
    if include_build:
        stages.append(_UploadSourceStage())
        stages.append(_BuildContainerStage())
    stages.append(
        progress_tracker.Stage('Creating Revision...',
                               key=SERVICE_CONFIGURATIONS_READY))
    if include_route:
        stages.append(_NewRoutingTrafficStage())
    if include_iam_policy_set:
        stages.append(
            progress_tracker.Stage('Setting IAM Policy...',
                                   key=SERVICE_IAM_POLICY_SET))
    return stages
Esempio n. 12
0
 def _RunStagedProgressTracker(self, args):
   get_bread = progress_tracker.Stage('Getting bread...', key='bread')
   get_pb_and_j = progress_tracker.Stage('Getting peanut butter...', key='pb')
   make_sandwich = progress_tracker.Stage('Making sandwich...', key='make')
   stages = [get_bread, get_pb_and_j, make_sandwich]
   with progress_tracker.StagedProgressTracker(
       'Making sandwich...',
       stages,
       success_message='Time to eat!',
       failure_message='Time to order delivery..!',
       tracker_id='meta.make_sandwich') as tracker:
     tracker.StartStage('bread')
     time.sleep(0.5)
     tracker.UpdateStage('bread', 'Looking for bread in the pantry')
     time.sleep(0.5)
     tracker.CompleteStage('bread', 'Got some whole wheat bread!')
     tracker.StartStage('pb')
     time.sleep(1)
     tracker.CompleteStage('pb')
     tracker.StartStage('make')
     time.sleep(1)
     tracker.CompleteStage('make')
Esempio n. 13
0
def IntegrationStages(create):
  """Returns the progress tracker Stages for creating or updating an Integration.

  Args:
    create: whether it's for the create command.

  Returns:
    list of progress_tracker.Stage
  """
  return [
      _UpdateApplicationStage(create),
      progress_tracker.Stage(
          'Configuring Integration...', key=CREATE_DEPLOYMENT),
  ]
Esempio n. 14
0
def _UpdateApplicationStage(create):
  """Returns the stage for updating the Application.

  Args:
    create: whether it's for the create command.

  Returns:
    progress_tracker.Stage
  """
  if create:
    message = 'Saving Configuration for Integration...'
  else:
    message = 'Updating Configuration for Integration...'

  return progress_tracker.Stage(message, key=UPDATE_APPLICATION)
    def _WaitForLegacyNetworkMigration(self, operation_poller, operation_ref):
        progress_stages = []
        for key, label in self.MIGRATION_STAGES.items():
            progress_stages.append(progress_tracker.Stage(label, key=key))

        tracker = progress_tracker.StagedProgressTracker(
            message='Migrating Network from Legacy to Custom Mode',
            stages=progress_stages)
        first_status_message = list(self.MIGRATION_STAGES.keys())[0]
        tracker.last_status_message = first_status_message

        return waiter.WaitFor(
            poller=operation_poller,
            operation_ref=operation_ref,
            custom_tracker=tracker,
            tracker_update_func=self._LegacyNetworkMigrationTrackerUpdateFunc)
Esempio n. 16
0
def _GetStages(client, request, messages):
    """Returns None until stages have been loaded in the operation."""
    operation = _GetOperation(client, request)
    if operation.error:
        raise exceptions.StatusToFunctionsError(operation.error)

    if not operation.metadata:
        return None
    operation_metadata = _GetOperationMetadata(messages, operation)
    if not operation_metadata.stages:
        return None

    stages = []
    for stage in operation_metadata.stages:
        message = '[{}]'.format(_GetStageName(stage.name))
        stages.append(progress_tracker.Stage(message, key=str(stage.name)))
    return stages
Esempio n. 17
0
    def Run(self, args):
        """Executes when the user runs the create command."""
        conn_context = connection_context.EventsConnectionContext(args)

        namespace_ref = args.CONCEPTS.namespace.Parse()

        with eventflow_operations.Connect(conn_context) as client:
            client.CreateBroker(namespace_ref.Name(), args.BROKER)

            broker_full_name = 'namespaces/{}/brokers/{}'.format(
                namespace_ref.Name(), args.BROKER)

            with progress_tracker.StagedProgressTracker(
                    'Creating Broker...',
                [progress_tracker.Stage('Creating Broker...')]) as tracker:
                client.PollBroker(broker_full_name, tracker)

        log.status.Print('Created broker [{}] in namespace [{}].'.format(
            args.BROKER, namespace_ref.Name()))
Esempio n. 18
0
    def Run(self, args):
        """Executes when the user runs the create command."""
        if platforms.GetPlatform() == platforms.PLATFORM_MANAGED:
            raise exceptions.UnsupportedArgumentError(
                'This command is only available with Cloud Run for Anthos.')

        conn_context = connection_context.GetConnectionContext(
            args, serverless_flags.Product.EVENTS, self.ReleaseTrack())

        namespace_ref = args.CONCEPTS.namespace.Parse()

        with eventflow_operations.Connect(conn_context) as client:
            client.CreateBroker(namespace_ref.Name(), args.BROKER)

            broker_full_name = 'namespaces/{}/brokers/{}'.format(
                namespace_ref.Name(), args.BROKER)

            with progress_tracker.StagedProgressTracker(
                    'Creating Broker...',
                [progress_tracker.Stage('Creating Broker...')]) as tracker:
                client.PollBroker(broker_full_name, tracker)

        log.status.Print('Created broker [{}] in namespace [{}].'.format(
            args.BROKER, namespace_ref.Name()))
Esempio n. 19
0
    def Run(self, args):
        """Runs local extraction then calls ODS with the results.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      AnalyzePackages operation.
    """
        # Create the command wrapper immediately so we can fail fast if necessary.
        cmd = Command()

        # TODO(b/173619679): Validate RESOURCE_URI argument.

        # Dynamically construct the stages based on the --async flag; when
        # --async=true, we do not need a separate poll stage.
        stages = [
            progress_tracker.Stage(
                EXTRACT_MESSAGE.format('remote' if args.remote else 'local'),
                key='extract'),
            progress_tracker.Stage(RPC_MESSAGE, key='rpc')
        ]
        if not args.async_:
            stages += [progress_tracker.Stage(POLL_MESSAGE, key='poll')]

        messages = api_util.GetMessages()
        with progress_tracker.StagedProgressTracker(SCAN_MESSAGE,
                                                    stages=stages) as tracker:
            # Stage 1) Extract.
            tracker.StartStage('extract')
            operation_result = cmd(
                resource_uri=args.RESOURCE_URI,
                remote=args.remote,
                fake_extraction=args.fake_extraction,
            )
            if operation_result.exit_code:
                tracker.FailStage(
                    'extract', ExtractionFailedError(operation_result.stderr))
                return

            # Parse stdout for the JSON-ified PackageData protos.
            pkgs = []
            for pkg in json.loads(operation_result.stdout):
                pkgs += [
                    messages.PackageData(
                        package=pkg['package'],
                        version=pkg['version'],
                        cpeUri=pkg['cpe_uri'],
                    )
                ]
            tracker.CompleteStage('extract')

            # Stage 2) Make the RPC to the On-Demand Scanning API.
            tracker.StartStage('rpc')
            op = api_util.AnalyzePackages(
                properties.VALUES.core.project.Get(required=True),
                args.location, args.RESOURCE_URI, pkgs)
            tracker.CompleteStage('rpc')

            # Stage 3) Poll the operation if requested.
            response = None
            if not args.async_:
                tracker.StartStage('poll')
                tracker.UpdateStage('poll', '[{}]'.format(op.name))
                response = ods_util.WaitForOperation(op)
                tracker.CompleteStage('poll')

        if args.async_:
            log.status.Print('Check operation [{}] for status.'.format(
                op.name))
            return op
        return response
Esempio n. 20
0
def DomainMappingStages():
    return [progress_tracker.Stage('Creating Domain Mapping...', key=READY)]
    def Run(self, args):
        """Runs local extraction then calls ODS with the results.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      AnalyzePackages operation.

    Raises:
      UnsupportedOS: when the command is run on a Windows machine.
    """
        if platforms.OperatingSystem.IsWindows():
            raise ods_util.UnsupportedOS(
                'On-Demand Scanning is not supported on Windows')

        # Verify that the local-extract component is installed, and prompt the user
        # to install it if it's not.
        try:
            # If the user has access to the gcloud components manager, this will
            # prompt the user to install it. If they do not have access, it will
            # instead print the command to install it using a package manager.
            update_manager.UpdateManager.EnsureInstalledAndRestart(
                ['local-extract'])
        except update_manager.MissingRequiredComponentsError:
            # Two possibilities with this error:
            #   1. The user has access to the gcloud components manager but decided
            #      against intalling it.
            #   2. The user does not have access to the gcloud components manager. A
            #      message was printed to the user with the command to install the
            #      component using their package manager (e.g. apt-get).
            raise
        except local_state.InvalidSDKRootError:
            # This happens when gcloud is run locally, but not when distributed.
            pass

        # Construct the object which invokes the `local-extract` component. This
        # might still fail if the binary is run locally.
        cmd = Command()

        # TODO(b/173619679): Validate RESOURCE_URI argument.

        # Dynamically construct the stages based on the --async flag; when
        # --async=true, we do not need a separate poll stage.
        stages = [
            progress_tracker.Stage(
                EXTRACT_MESSAGE.format('remote' if args.remote else 'local'),
                key='extract'),
            progress_tracker.Stage(RPC_MESSAGE, key='rpc')
        ]
        if not args.async_:
            stages += [progress_tracker.Stage(POLL_MESSAGE, key='poll')]

        messages = self.GetMessages()
        with progress_tracker.StagedProgressTracker(SCAN_MESSAGE,
                                                    stages=stages) as tracker:
            # Stage 1) Extract.
            tracker.StartStage('extract')
            operation_result = cmd(
                resource_uri=args.RESOURCE_URI,
                remote=args.remote,
                fake_extraction=args.fake_extraction,
                additional_package_types=args.additional_package_types,
                experimental_package_types=args.experimental_package_types,
                verbose_errors=args.verbose_errors,
            )
            if operation_result.exit_code:
                # Filter out any log messages on std err and only include any actual
                # extraction errors.
                extraction_error = None
                if operation_result.stderr:
                    extraction_error = '\n'.join([
                        line for line in operation_result.stderr.splitlines()
                        if line.startswith('Extraction failed')
                    ])
                if not extraction_error:
                    if operation_result.exit_code < 0:
                        extraction_error = EXTRACTION_KILLED_ERROR_TEMPLATE.format(
                            exit_code=operation_result.exit_code, )
                    else:
                        extraction_error = UNKNOWN_EXTRACTION_ERROR_TEMPLATE.format(
                            exit_code=operation_result.exit_code, )
                tracker.FailStage(
                    'extract',
                    ods_util.ExtractionFailedError(extraction_error))
                return

            # Parse stdout for the JSON-ified PackageData protos.
            pkgs = []
            for pkg in json.loads(operation_result.stdout):
                pkg_data = messages.PackageData(
                    package=pkg['package'],
                    version=pkg['version'],
                    cpeUri=pkg['cpe_uri'],
                )
                if 'package_type' in pkg:
                    pkg_data.packageType = arg_utils.ChoiceToEnum(
                        pkg['package_type'],
                        messages.PackageData.PackageTypeValueValuesEnum)
                pkgs += [pkg_data]
            tracker.CompleteStage('extract')

            # Stage 2) Make the RPC to the On-Demand Scanning API.
            tracker.StartStage('rpc')
            op = self.AnalyzePackages(args, pkgs)
            tracker.CompleteStage('rpc')

            # Stage 3) Poll the operation if requested.
            response = None
            if not args.async_:
                tracker.StartStage('poll')
                tracker.UpdateStage('poll', '[{}]'.format(op.name))
                response = self.WaitForOperation(op)
                tracker.CompleteStage('poll')

        if args.async_:
            log.status.Print('Check operation [{}] for status.'.format(
                op.name))
            return op
        return response
Esempio n. 22
0
def _NewRoutingTrafficStage():
    return progress_tracker.Stage('Routing traffic...',
                                  key=SERVICE_ROUTES_READY)
Esempio n. 23
0
    ('clear_secrets', '--clear-secrets'),
]
_UNSUPPORTED_V2_FLAG_ERROR = '`%s` is not yet supported in Cloud Functions V2.'

_CLOUD_RUN_SERVICE_COLLECTION_K8S = 'run.namespaces.services'
_CLOUD_RUN_SERVICE_COLLECTION_ONE_PLATFORM = 'run.projects.locations.services'

_DEFAULT_IGNORE_FILE = gcloudignore.DEFAULT_IGNORE_FILE + '\nnode_modules\n'

_ZIP_MIME_TYPE = 'application/zip'

_DEPLOYMENT_TOOL_LABEL = 'deployment-tool'
_DEPLOYMENT_TOOL_VALUE = 'cli-gcloud'

# cs/symbol:google.cloud.functions.v2main.Stage.Name.SERVICE_ROLLBACK
_SERVICE_ROLLBACK_STAGE = progress_tracker.Stage('[Healthcheck]',
                                                 key='SERVICE_ROLLBACK')
_TRIGGER_ROLLBACK_STAGE = progress_tracker.Stage('[Triggercheck]',
                                                 key='TRIGGER_ROLLBACK')

_EXTRA_STAGES = [_SERVICE_ROLLBACK_STAGE, _TRIGGER_ROLLBACK_STAGE]

# GCF 2nd generation control plane valid memory units
_GCF_GEN2_UNITS = [
    'k',
    'Ki',
    'M',
    'Mi',
    'G',
    'Gi',
    'T',
    'Ti',
Esempio n. 24
0
from googlecloudsdk.core.console import progress_tracker
from googlecloudsdk.core.util import retry

DEFAULT_ENDPOINT_VERSION = 'v1'
_SERVERLESS_API_NAME = 'serverless'
_SERVERLESS_API_VERSION = 'v1alpha1'

# Wait 11 mins for each deployment. This is longer than the server timeout,
# making it more likely to get a useful error message from the server.
MAX_WAIT_MS = 660000

# Because gcloud cannot update multiple lines of output simultaneously, the
# order of conditions in this dictionary should match the order in which we
# expect Serverless resources to complete deployment.
_CONDITION_TO_STAGE = OrderedDict([
    ('ConfigurationsReady', progress_tracker.Stage(
        'Creating Revision...')),
    ('RoutesReady', progress_tracker.Stage('Routing traffic...')),
    ('Ready', progress_tracker.Stage('Readying...'))])


class UnknownAPIError(exceptions.Error):
  pass


@contextlib.contextmanager
def Connect(cluster_ref):
  """Provide a ServerlessOperations instance to use.

  Arguments:
    cluster_ref: Resource, the gke cluster to connect to if present. Otherwise,
      connect to Hosted Serverless.
Esempio n. 25
0
def _BuildFromSourceStage():
  return progress_tracker.Stage(
      'Building Container...', key=BUILD_READY)
Esempio n. 26
0
def TriggerStages():
  return [
      progress_tracker.Stage('Subscribing Service...', key=_TRIGGER_SUBSCRIBED),
      progress_tracker.Stage('Linking Trigger...', key=_TRIGGER_DEPENDENCY),
  ]
Esempio n. 27
0
def TriggerAndSourceStages():
  return [
      progress_tracker.Stage('Creating Event Source...', key=SOURCE_READY)
  ] + TriggerStages()
Esempio n. 28
0
def _UploadSourceStage():
    return progress_tracker.Stage('Uploading sources...', key=UPLOAD_SOURCE)
Esempio n. 29
0
def EventingStages():
  return [
      progress_tracker.Stage('Enabling Eventing...'),
  ]
def _CreateRepoStage():
    return progress_tracker.Stage('Creating Container Repository...',
                                  key=CREATE_REPO)