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) if args.newer_than: newer_than = times.FormatDateTime(args.newer_than) else: newer_than = None with progress_tracker.ProgressTracker( 'Waiting for variable [{0}] to change'.format( var_resource.Name())): try: return util.FormatVariable( variable_client.Watch( messages. RuntimeconfigProjectsConfigsVariablesWatchRequest( name=var_resource.RelativeName(), 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
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)
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)
def Run(self, args): result = super(Describe, self).Run(args) return util.FormatVariable(result)