Ejemplo n.º 1
0
    def Run(self, args):
        """Run 'runtime-configs list'.

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

    Yields:
      The list of runtime-config resources.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
        config_client = util.ConfigClient()
        messages = util.Messages()
        project = util.Project()

        request = messages.RuntimeconfigProjectsConfigsListRequest(
            projectsId=project, )

        page_size = args.page_size or self.DEFAULT_PAGE_SIZE

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

        for result in results:
            yield util.FormatConfig(result)
Ejemplo n.º 2
0
    def Run(self, args):
        """Run 'runtime-configs update'.

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

    Returns:
      The updated runtime-config resource.

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

        config_resource = util.ParseConfigName(args.name)
        project = config_resource.projectsId
        name = config_resource.Name()

        result = config_client.Update(
            messages.RuntimeconfigProjectsConfigsUpdateRequest(
                projectsId=project,
                configsId=name,
                runtimeConfig=messages.RuntimeConfig(
                    name=util.ConfigPath(project, name),
                    description=args.description,
                )))

        log.UpdatedResource(config_resource)
        return util.FormatConfig(result)
Ejemplo n.º 3
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
        )
    )
Ejemplo n.º 4
0
    def Run(self, args):
        """Run 'runtime-configs delete'.

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

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

        config_resource = util.ParseConfigName(args.name)
        project = config_resource.projectsId
        name = config_resource.Name()

        config_client.Delete(
            messages.RuntimeconfigProjectsConfigsDeleteRequest(
                projectsId=project,
                configsId=name,
            ))

        log.DeletedResource(config_resource)
Ejemplo n.º 5
0
    def Run(self, args):
        """Run 'runtime-configs waiters describe'.

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

    Returns:
      The requested waiter.

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

        waiter_resource = util.ParseWaiterName(args.name, args)
        project = waiter_resource.projectsId
        config = waiter_resource.configsId
        name = waiter_resource.Name()

        result = waiter_client.Get(
            messages.RuntimeconfigProjectsConfigsWaitersGetRequest(
                projectsId=project,
                configsId=config,
                waitersId=name,
            ))

        return util.FormatWaiter(result)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
  def Run(self, args):
    """Run 'runtime-configs waiters list'.

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

    Yields:
      The list of waiters.

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

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

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

    page_size = args.page_size or self.DEFAULT_PAGE_SIZE

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

    for result in results:
      yield util.FormatWaiter(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
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    def Run(self, args):
        """Run 'runtime-configs waiters delete'.

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

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

        waiter_resource = util.ParseWaiterName(args.name, args)

        waiter_client.Delete(
            messages.RuntimeconfigProjectsConfigsWaitersDeleteRequest(
                name=waiter_resource.RelativeName(), ))

        log.DeletedResource(waiter_resource)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
    def Run(self, args):
        """Run 'runtime-configs describe'.

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

    Returns:
      The requested runtime-config resource.

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

        config_resource = util.ParseConfigName(args.name)

        result = config_client.Get(
            messages.RuntimeconfigProjectsConfigsGetRequest(
                name=config_resource.RelativeName(), ))
        return util.FormatConfig(result)
Ejemplo n.º 15
0
    def Run(self, args):
        """Run 'runtime-configs waiters create'.

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

    Returns:
      The associated waiter operation.

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

        waiter_resource = util.ParseWaiterName(args.name, args)
        project = waiter_resource.projectsId
        config = waiter_resource.configsId
        name = waiter_resource.Name()

        success = messages.EndCondition(cardinality=messages.Cardinality(
            path=args.success_cardinality_path,
            number=args.success_cardinality_number,
        ))

        if args.failure_cardinality_path:
            failure = messages.EndCondition(cardinality=messages.Cardinality(
                path=args.failure_cardinality_path,
                number=args.failure_cardinality_number,
            ))
        else:
            failure = None

        result = waiter_client.Create(
            messages.RuntimeconfigProjectsConfigsWaitersCreateRequest(
                projectsId=project,
                configsId=config,
                waiter=messages.Waiter(
                    name=util.WaiterPath(project, config, name),
                    timeout='{0}s'.format(args.timeout),
                    success=success,
                    failure=failure,
                )))

        log.CreatedResource(waiter_resource)

        if args. async:
            # In async mode, we return the current waiter representation.
            # The waiter resource exists immediately after creation; the
            # operation resource returned from CreateWaiter only tracks the
            # waiting process.
            self._async_resource = waiter_resource
            result = waiter_client.Get(waiter_resource.Request())
        else:
            self._async_resource = None
            result = util.WaitForWaiter(waiter_resource)
            if util.IsFailedWaiter(result):
                self.exit_code = 2  # exit with code 2 if the result waiter failed.

        return util.FormatWaiter(result)