Example #1
0
def HandleLRO(operation,
              args,
              environment_service,
              release_track,
              is_delete=False):
  """Handles Long Running Operations for both cases of async."""
  logging_method = log.DeletedResource if is_delete else log.CreatedResource
  if args.async_:
    logging_method(
        util.GetOperationResource(operation.name, release_track),
        kind='notebooks environment {0}'.format(args.environment),
        is_async=True)
    return operation
  else:
    response = util.WaitForOperation(
        operation,
        'Waiting for Environment [{}] to be {} with [{}]'.format(
            args.environment, 'deleted' if is_delete else 'created',
            operation.name),
        service=environment_service,
        release_track=release_track,
        is_delete=is_delete)
    logging_method(
        util.GetOperationResource(operation.name, release_track),
        kind='notebooks environment {0}'.format(args.environment),
        is_async=False)
    return response
def HandleLRO(operation,
              args,
              instance_service,
              release_track,
              operation_type=OperationType.UPDATE):
    """Handles Long Running Operations for both cases of async.

  Args:
    operation: The operation to poll.
    args: ArgParse instance containing user entered arguments.
    instance_service: The service to get the resource after the long running
      operation completes.
    release_track: base.ReleaseTrack object.
    operation_type: Enum value of type OperationType indicating the kind of
      operation to wait for.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error

  Returns:
    The Instance resource if synchronous, else the Operation Resource.
  """
    logging_method = operation_type.value[0]
    if args.async_:
        logging_method(util.GetOperationResource(operation.name,
                                                 release_track),
                       kind='notebooks instance {0}'.format(args.instance),
                       is_async=True)
        return operation
    else:
        response = util.WaitForOperation(
            operation,
            'Waiting for operation on Instance [{}] to be {} with [{}]'.format(
                args.instance, operation_type.value[1], operation.name),
            service=instance_service,
            release_track=release_track,
            is_delete=(operation_type.value[1] == 'deleted'))
        logging_method(util.GetOperationResource(operation.name,
                                                 release_track),
                       kind='notebooks instance {0}'.format(args.instance),
                       is_async=False)
        return response