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

Module client

source code

Ganeti RAPI client.


Attention: To use the RAPI client, the application must call pycurl.global_init during initialization and pycurl.global_cleanup before exiting the process. This is very important in multi-threaded programs. See curl_global_init(3) and curl_global_cleanup(3) for details. The decorator UsesRapiClient can be used.

Classes [hide private]
  Error
Base error class for this module.
  GanetiApiError
Generic error raised from Ganeti API.
  CertificateError
Raised when a problem is found with the SSL certificate.
  GanetiRapiClient
Ganeti RAPI client.
Functions [hide private]
 
EpochNano()
Return the current timestamp expressed as number of nanoseconds since the unix epoch
source code
 
_AppendIf(container, condition, value)
Appends to a list if a condition evaluates to truth.
source code
 
_AppendDryRunIf(container, condition)
Appends a "dry-run" parameter if a condition evaluates to truth.
source code
 
_AppendForceIf(container, condition)
Appends a "force" parameter if a condition evaluates to truth.
source code
 
_AppendReason(container, reason)
Appends an element to the reason trail.
source code
 
_SetItemIf(container, condition, item, value)
Sets an item if a condition evaluates to truth.
source code
 
UsesRapiClient(fn)
Decorator for code using RAPI client to initialize pycURL.
source code
 
GenericCurlConfig(verbose=False, use_signal=False, use_curl_cabundle=False, cafile=None, capath=None, proxy=None, verify_hostname=False, connect_timeout=None, timeout=None, _pycurl_version_fn=pycurl.version_info)
Curl configuration function generator.
source code
Variables [hide private]
  GANETI_RAPI_PORT = 5080
  GANETI_RAPI_VERSION = 2
  HTTP_DELETE = "DELETE"
  HTTP_GET = "GET"
  HTTP_PUT = "PUT"
  HTTP_POST = "POST"
  HTTP_OK = 200
  HTTP_NOT_FOUND = 404
  HTTP_APP_JSON = "application/json"
  REPLACE_DISK_PRI = "replace_on_primary"
  REPLACE_DISK_SECONDARY = "replace_on_secondary"
  REPLACE_DISK_CHG = "replace_new_secondary"
  REPLACE_DISK_AUTO = "replace_auto"
  NODE_EVAC_PRI = "primary-only"
  NODE_EVAC_SEC = "secondary-only"
  NODE_EVAC_ALL = "all"
  NODE_ROLE_DRAINED = "drained"
  NODE_ROLE_MASTER_CANDIDATE = "master-candidate"
  NODE_ROLE_MASTER = "master"
  NODE_ROLE_OFFLINE = "offline"
  NODE_ROLE_REGULAR = "regular"
  JOB_STATUS_QUEUED = "queued"
  JOB_STATUS_WAITING = "waiting"
  JOB_STATUS_CANCELING = "canceling"
  JOB_STATUS_RUNNING = "running"
  JOB_STATUS_CANCELED = "canceled"
  JOB_STATUS_SUCCESS = "success"
  JOB_STATUS_ERROR = "error"
  JOB_STATUS_PENDING = frozenset([JOB_STATUS_QUEUED, JOB_STATUS_...
  JOB_STATUS_FINALIZED = frozenset([JOB_STATUS_CANCELED, JOB_STA...
  JOB_STATUS_ALL = frozenset([JOB_STATUS_RUNNING,]) | JOB_STATUS...
  JOB_STATUS_WAITLOCK = "waiting"
  _REQ_DATA_VERSION_FIELD = "__version__"
  _QPARAM_DRY_RUN = "dry-run"
  _QPARAM_FORCE = "force"
  INST_CREATE_REQV1 = "instance-create-reqv1"
  INST_REINSTALL_REQV1 = "instance-reinstall-reqv1"
  NODE_MIGRATE_REQV1 = "node-migrate-reqv1"
  NODE_EVAC_RES1 = "node-evac-res1"
  _INST_CREATE_REQV1 = "instance-create-reqv1"
  _INST_REINSTALL_REQV1 = "instance-reinstall-reqv1"
  _NODE_MIGRATE_REQV1 = "node-migrate-reqv1"
  _NODE_EVAC_RES1 = "node-evac-res1"
  ECODE_RESOLVER = "resolver_error"
Resolver errors
  ECODE_NORES = "insufficient_resources"
Not enough resources (iallocator failure, disk space, memory, etc.)
  ECODE_TEMP_NORES = "temp_insufficient_resources"
Temporarily out of resources; operation can be tried again
  ECODE_INVAL = "wrong_input"
Wrong arguments (at syntax level)
  ECODE_STATE = "wrong_state"
Wrong entity state
  ECODE_NOENT = "unknown_entity"
Entity not found
  ECODE_EXISTS = "already_exists"
Entity already exists
  ECODE_NOTUNIQUE = "resource_not_unique"
Resource not unique (e.g.
  ECODE_FAULT = "internal_error"
Internal cluster error
  ECODE_ENVIRON = "environment_error"
Environment error (e.g.
  ECODE_ALL = frozenset([ECODE_RESOLVER, ECODE_NORES, ECODE_TEMP...
List of all failure types
  _CURLE_SSL_CACERT = 60
  _CURLE_SSL_CACERT_BADFILE = 77
  _CURL_SSL_CERT_ERRORS = frozenset([_CURLE_SSL_CACERT, _CURLE_S...

Imports: logging, simplejson, socket, urllib, threading, pycurl, time, StringIO


Function Details [hide private]

EpochNano()

source code 

Return the current timestamp expressed as number of nanoseconds since the unix epoch

Returns:
nanoseconds since the Unix epoch

_AppendReason(container, reason)

source code 

Appends an element to the reason trail.

If the user provided a reason, it is added to the reason trail.

GenericCurlConfig(verbose=False, use_signal=False, use_curl_cabundle=False, cafile=None, capath=None, proxy=None, verify_hostname=False, connect_timeout=None, timeout=None, _pycurl_version_fn=pycurl.version_info)

source code 

Curl configuration function generator.

Parameters:
  • verbose (bool) - Whether to set cURL to verbose mode
  • use_signal (bool) - Whether to allow cURL to use signals
  • use_curl_cabundle (bool) - Whether to use cURL's default CA bundle
  • cafile (string) - In which file we can find the certificates
  • capath (string) - In which directory we can find the certificates
  • proxy (string) - Proxy to use, None for default behaviour and empty string for disabling proxies (see curl_easy_setopt(3))
  • verify_hostname (bool) - Whether to verify the remote peer certificate's commonName
  • connect_timeout (number) - Timeout for establishing connection in seconds
  • timeout (number) - Timeout for complete transfer in seconds (see curl_easy_setopt(3)).

Variables Details [hide private]

JOB_STATUS_PENDING

Value:
frozenset([JOB_STATUS_QUEUED, JOB_STATUS_WAITING, JOB_STATUS_CANCELING\
,])

JOB_STATUS_FINALIZED

Value:
frozenset([JOB_STATUS_CANCELED, JOB_STATUS_SUCCESS, JOB_STATUS_ERROR,]\
)

JOB_STATUS_ALL

Value:
frozenset([JOB_STATUS_RUNNING,]) | JOB_STATUS_PENDING | JOB_STATUS_FIN\
ALIZED

ECODE_NOTUNIQUE

Resource not unique (e.g. MAC or IP duplication)

Value:
"resource_not_unique"

ECODE_ENVIRON

Environment error (e.g. node disk error)

Value:
"environment_error"

ECODE_ALL

List of all failure types

Value:
frozenset([ECODE_RESOLVER, ECODE_NORES, ECODE_TEMP_NORES, ECODE_INVAL,\
 ECODE_STATE, ECODE_NOENT, ECODE_EXISTS, ECODE_NOTUNIQUE, ECODE_FAULT,\
 ECODE_ENVIRON,])

_CURL_SSL_CERT_ERRORS

Value:
frozenset([_CURLE_SSL_CACERT, _CURLE_SSL_CACERT_BADFILE,])