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

Module baserlib

source code

Remote API base resources library.

Classes [hide private]
  R_Generic
Generic class for resources.
Functions [hide private]
 
BuildUriList(ids, uri_format, uri_fields=("name","uri"))
Builds a URI list as used by index resources.
source code
 
ExtractField(sequence, index)
Creates a list containing one column out of a list of lists.
source code
 
MapFields(names, data)
Maps two lists into one dictionary.
source code
 
_Tags_GET(kind, name)
Helper function to retrieve tags.
source code
 
_Tags_PUT(kind, tags, name, dry_run)
Helper function to set tags.
source code
 
_Tags_DELETE(kind, tags, name, dry_run)
Helper function to delete tags.
source code
 
MapBulkFields(itemslist, fields)
Map value to field name in to one dictionary.
source code
dict
MakeParamsDict(opts, params)
Makes params dictionary out of a option set.
source code
string
SubmitJob(op, cl=None)
Generic wrapper for submit job, for better http compatibility.
source code
 
HandleItemQueryErrors(fn, *args, **kwargs)
Converts errors when querying a single item.
source code
 
GetClient()
Geric wrapper for luxi.Client(), for better http compatiblity.
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
Variables [hide private]
  _DEFAULT = object()

Imports: logging, luxi, rapi, http, ssconf, constants, opcodes, errors


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

ExtractField(sequence, index)

source code 

Creates a list containing one column out of a list of lists.

Parameters:
  • sequence - sequence of lists
  • index - index of field

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

MakeParamsDict(opts, params)

source code 

Makes params dictionary out of a option set.

This function returns a dictionary needed for hv or be parameters. But only those fields which provided in the option set. Takes parameters frozensets from constants.

Parameters:
  • opts (dict) - selected options
  • params (frozenset) - subset of options
Returns: dict
dictionary of options, filtered by given subset.

SubmitJob(op, cl=None)

source code 

Generic wrapper for submit job, for better http compatibility.

Parameters:
  • op (list) - the list of opcodes for the job
  • cl (None or luxi.Client) - optional luxi client to use
Returns: string
the job ID

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)