コード例 #1
0
ファイル: base_commands.py プロジェクト: AlexisMarie8330/Doll
  def Run(self, args):
    """Run a command that retrieves a variable.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The requested variable.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    variable_client = util.VariableClient()
    messages = util.Messages()

    var_resource = util.ParseVariableName(args.name, args)
    project = var_resource.projectsId
    config = var_resource.configsId
    name = var_resource.Name()

    return variable_client.Get(
        messages.RuntimeconfigProjectsConfigsVariablesGetRequest(
            projectsId=project,
            configsId=config,
            variablesId=name
        )
    )
コード例 #2
0
  def Run(self, args):
    """Run 'runtime-configs variables set'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The new variable.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    variable_client = util.VariableClient()
    messages = util.Messages()

    var_resource = util.ParseVariableName(args.name, args)

    try:
      variable_client.Delete(
          messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest(
              name=var_resource.RelativeName(),
              recursive=args.recursive,
          )
      )

      log.DeletedResource(var_resource)

    except apitools_exceptions.HttpError as error:
      # Raise this failure if the user requested it, or if the
      # error is not a 404.
      if not util.IsNotFoundError(error) or args.fail_if_absent:
        raise
コード例 #3
0
  def Run(self, args):
    """Run a command that watches a variable.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The WatchVariable response.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    # Disable retries and configure the timeout.
    variable_client = util.VariableClient(num_retries=0, timeout=args.max_wait)
    messages = util.Messages()

    var_resource = util.ParseVariableName(args.name, args)
    project = var_resource.projectsId
    config = var_resource.configsId
    name = var_resource.Name()

    if args.newer_than:
      # TODO(user): better way to handle UTC suffix?
      newer_than = args.newer_than.isoformat() + 'Z'
    else:
      newer_than = None

    with progress_tracker.ProgressTracker(
        'Waiting for variable [{0}] to change'.format(name)):
      try:
        return util.FormatVariable(
            variable_client.Watch(
                messages.RuntimeconfigProjectsConfigsVariablesWatchRequest(
                    projectsId=project,
                    configsId=config,
                    variablesId=name,
                    watchVariableRequest=messages.WatchVariableRequest(
                        newerThan=newer_than,
                    )
                )
            )
        )

      except apitools_exceptions.HttpError as error:
        # For deadline exceeded or bad gateway errors,
        # we return a status code of 2.
        # In some cases, the GFE will timeout before the backend
        # responds with a 504 Gateway Timeout (DEADLINE_EXCEEDED).
        # In that scenario, GFE responds first with a 502 BAD GATEWAY error.
        if util.IsDeadlineExceededError(error) or util.IsBadGatewayError(error):
          _RaiseTimeout()
        raise

      except socket.error as error:
        if util.IsSocketTimeout(error):
          _RaiseTimeout()
        raise
コード例 #4
0
ファイル: set.py プロジェクト: TobiahRex/Wingman
    def Run(self, args):
        """Run 'runtime-configs variables set'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The new variable.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        var_resource = util.ParseVariableName(args.name, args)
        if args.value is None:
            log.status.Print(
                'No value argument specified; reading value from stdin.')
            value = sys.stdin.read()
        else:
            value = args.value

        if args.fail_if_absent:
            # Update case
            return self._Update(args, var_resource, value)
        else:
            # Either create or create-or-update
            try:
                return self._Create(args, var_resource, value)
            except apitools_exceptions.HttpError as error:
                # If --fail-if-present was not specified, and we got an
                # Already Exists error, try updating instead.
                if not args.fail_if_present and util.IsAlreadyExistsError(
                        error):
                    return self._Update(args, var_resource, value)

                # If --fail-if-present was specified, or some other error
                # occurred, re-raise the error.
                raise