예제 #1
0
    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
예제 #3
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)
예제 #4
0
파일: set.py 프로젝트: TobiahRex/Wingman
    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)
예제 #5
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)
예제 #6
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)
예제 #7
0
 def Run(self, args):
     result = super(Describe, self).Run(args)
     return util.FormatVariable(result)