Package ganeti :: Package rapi :: Module baserlib
[hide private]
[frames] | no frames]

Module baserlib

source code

Remote API base resources library.

Classes [hide private]
  OpcodeAttributes
Acts as a structure containing the per-method attribute names.
  ResourceBase
Generic class for resources.
  _MetaOpcodeResource
Meta class for RAPI resources.
  OpcodeResource
Base class for opcode-based RAPI resources.
Functions [hide private]
 
_BuildOpcodeAttributes()
Builds list of attributes used for per-handler opcodes.
source code
 
BuildUriList(ids, uri_format, uri_fields=("name","uri"))
Builds a URI list as used by index resources.
source code
 
MapFields(names, data)
Maps two lists into one dictionary.
source code
 
MapBulkFields(itemslist, fields)
Map value to field name in to one dictionary.
source code
 
FillOpcode(opcls, body, static, rename=None)
Fills an opcode with body parameters.
source code
 
HandleItemQueryErrors(fn, *args, **kwargs)
Converts errors when querying a single item.
source code
 
FeedbackFn(msg)
Feedback logging function for jobs.
source code
 
CheckType(value, exptype, descr)
Abort request if value type doesn't match expected type.
source code
 
CheckParameter(data, name, default=_DEFAULT, exptype=_DEFAULT)
Check and return the value for a given parameter.
source code
 
GetResourceOpcodes(cls)
Returns all opcodes used by a resource.
source code
string or None
GetHandlerAccess(handler, method)
Returns the access rights for a method on a handler.
source code
 
GetHandler(get_fn, aliases) source code
 
ProduceForbiddenParamDict(class_name, method_name, param_list)
Turns a list of parameter names and possibly values into a dictionary.
source code
 
InspectParams(params_dict, forbidden_params, rename_dict)
Inspects a dictionary of params, looking for forbidden values.
source code
Variables [hide private]
  _DEFAULT = object()
  _SUPPORTED_METHODS = compat.UniqueFrozenset([http.HTTP_DELETE,...
Supported HTTP methods
  OPCODE_ATTRS = _BuildOpcodeAttributes()
  ALL_VALUES_FORBIDDEN = "all_values_forbidden"

Imports: logging, luxi, rpcerr, rapi, http, errors, compat, constants, utils


Function Details [hide private]

BuildUriList(ids, uri_format, uri_fields=("name","uri"))

source code 

Builds a URI list as used by index resources.

Parameters:
  • ids - list of ids as strings
  • uri_format - format to be applied for URI
  • uri_fields - optional parameter for field IDs

MapFields(names, data)

source code 

Maps two lists into one dictionary.

Example:

   >>> MapFields(["a", "b"], ["foo", 123])
   {'a': 'foo', 'b': 123}
Parameters:
  • names - field names (list of strings)
  • data - field data (list)

MapBulkFields(itemslist, fields)

source code 

Map value to field name in to one dictionary.

Parameters:
  • itemslist - a list of items values
  • fields - a list of items names
Returns:
a list of mapped dictionaries

FillOpcode(opcls, body, static, rename=None)

source code 

Fills an opcode with body parameters.

Parameter types are checked.

Parameters:
  • opcls (opcodes.OpCode) - Opcode class
  • body (dict) - Body parameters as received from client
  • static (dict) - Static parameters which can't be modified by client
  • rename (dict) - Renamed parameters, key as old name, value as new name
Returns:
Opcode object

FeedbackFn(msg)

source code 

Feedback logging function for jobs.

We don't have a stdout for printing log messages, so log them to the http log at least.

Parameters:
  • msg - the message

CheckType(value, exptype, descr)

source code 

Abort request if value type doesn't match expected type.

Parameters:
  • value - Value
  • exptype (type) - Expected type
  • descr (string) - Description of value
Returns:
Value (allows inline usage)

CheckParameter(data, name, default=_DEFAULT, exptype=_DEFAULT)

source code 

Check and return the value for a given parameter.

If no default value was given and the parameter doesn't exist in the input data, an error is raise.

Parameters:
  • data (dict) - Dictionary containing input data
  • name (string) - Parameter name
  • default - Default value (can be None)
  • exptype - Expected type (can be None)

GetHandlerAccess(handler, method)

source code 

Returns the access rights for a method on a handler.

Parameters:
Returns: string or None

ProduceForbiddenParamDict(class_name, method_name, param_list)

source code 

Turns a list of parameter names and possibly values into a dictionary.

Parameters:
  • class_name (string) - The name of the handler class
  • method_name (string) - The name of the HTTP method
  • param_list (list of string or tuple of (string, list of any)) - A list of forbidden parameters, specified in the RAPI handler class
Returns:
The dictionary of forbidden param names to values or ALL_VALUES_FORBIDDEN

InspectParams(params_dict, forbidden_params, rename_dict)

source code 

Inspects a dictionary of params, looking for forbidden values.

Parameters:
  • params_dict (dict of string to anything) - A dictionary of supplied parameters
  • forbidden_params (dict of string to string or list of any) - The forbidden parameters, with a list of forbidden values or the constant ALL_VALUES_FORBIDDEN signifying that all values are forbidden
  • rename_dict (None or dict of string to string) - The list of parameter renamings used by the method
Raises:

Variables Details [hide private]

_SUPPORTED_METHODS

Supported HTTP methods

Value:
compat.UniqueFrozenset([http.HTTP_DELETE, http.HTTP_GET, http.HTTP_POS\
T, http.HTTP_PUT,])