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

Module baserlib

source code

Remote API base resources library.

Classes [hide private]
  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
Variables [hide private]
  _DEFAULT = object()
  _SUPPORTED_METHODS = compat.UniqueFrozenset([http.HTTP_DELETE,...
Supported HTTP methods
  OPCODE_ATTRS = _BuildOpcodeAttributes()

Imports: logging, luxi, rapi, http, errors, compat, constants, pathutils, 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

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,])