Beispiel #1
0
  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
        )
    )
  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
    def Run(self, args):
        """Run 'runtime-configs variables list'.

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

    Yields:
      The list of variables.

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

        config_resource = util.ParseConfigName(util.ConfigName(args))

        request = messages.RuntimeconfigProjectsConfigsVariablesListRequest(
            parent=config_resource.RelativeName(), )

        page_size = args.page_size or self.DEFAULT_PAGE_SIZE

        results = list_pager.YieldFromList(variable_client,
                                           request,
                                           field='variables',
                                           batch_size_attribute='pageSize',
                                           limit=args.limit,
                                           batch_size=page_size)

        for result in results:
            yield util.FormatVariable(result)
  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
Beispiel #5
0
    def _Update(self, args, var_resource, value):
        variable_client = util.VariableClient()
        messages = util.Messages()

        result = variable_client.Update(
            messages.Variable(
                name=var_resource.RelativeName(),
                value=value if not args.is_text else None,
                text=value if args.is_text else None,
            ))

        log.UpdatedResource(var_resource)
        return util.FormatVariable(result)
Beispiel #6
0
    def _Create(self, args, var_resource, value):
        variable_client = util.VariableClient()
        messages = util.Messages()

        project = var_resource.projectsId
        config = var_resource.configsId
        name = var_resource.Name()

        result = variable_client.Create(
            messages.RuntimeconfigProjectsConfigsVariablesCreateRequest(
                projectsId=project,
                configsId=config,
                variable=messages.Variable(name=util.VariablePath(
                    project, config, name),
                                           value=value)))

        log.CreatedResource(var_resource)
        return util.FormatVariable(result)
Beispiel #7
0
    def _Create(self, args, var_resource, value):
        variable_client = util.VariableClient()
        messages = util.Messages()

        project = var_resource.projectsId
        config = var_resource.configsId

        result = variable_client.Create(
            messages.RuntimeconfigProjectsConfigsVariablesCreateRequest(
                parent=util.ConfigPath(project, config),
                variable=messages.Variable(
                    name=var_resource.RelativeName(),
                    value=value if not args.is_text else None,
                    text=value if args.is_text else None,
                )))

        log.CreatedResource(var_resource)
        return util.FormatVariable(result)
Beispiel #8
0
    def _Update(self, args, var_resource, value):
        variable_client = util.VariableClient()
        messages = util.Messages()

        project = var_resource.projectsId
        config = var_resource.configsId
        name = var_resource.Name()

        result = variable_client.Update(
            messages.RuntimeconfigProjectsConfigsVariablesUpdateRequest(
                projectsId=project,
                configsId=config,
                variablesId=name,
                variable=messages.Variable(
                    name=util.VariablePath(project, config, name),
                    value=value if not args.is_text else None,
                    text=value if args.is_text else None,
                )))

        log.UpdatedResource(var_resource)
        return util.FormatVariable(result)