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

Class GanetiRapiClient

source code


Ganeti RAPI client.

Instance Methods [hide private]
 
__init__(self, host, port=GANETI_RAPI_PORT, username=None, password=None, logger=logging, curl_config_fn=None, curl_factory=None)
Initializes this class.
source code
 
_CreateCurl(self)
Creates a cURL object.
source code
str
_SendRequest(self, method, path, query, content)
Sends an HTTP request.
source code
int
GetVersion(self)
Gets the Remote API version running on the cluster.
source code
list
GetFeatures(self)
Gets the list of optional features supported by RAPI server.
source code
list of str
GetOperatingSystems(self)
Gets the Operating Systems running in the Ganeti cluster.
source code
dict
GetInfo(self)
Gets info about the cluster.
source code
string
RedistributeConfig(self)
Tells the cluster to redistribute its configuration files.
source code
string
ModifyCluster(self, **kwargs)
Modifies cluster parameters.
source code
list of str
GetClusterTags(self)
Gets the cluster tags.
source code
string
AddClusterTags(self, tags, dry_run=False)
Adds tags to the cluster.
source code
string
DeleteClusterTags(self, tags, dry_run=False)
Deletes tags from the cluster.
source code
list of dict or list of str
GetInstances(self, bulk=False)
Gets information about instances on the cluster.
source code
dict
GetInstance(self, instance)
Gets information about an instance.
source code
string
GetInstanceInfo(self, instance, static=None)
Gets information about an instance.
source code
string
CreateInstance(self, mode, name, disk_template, disks, nics, **kwargs)
Creates a new instance.
source code
string
DeleteInstance(self, instance, dry_run=False)
Deletes an instance.
source code
string
ModifyInstance(self, instance, **kwargs)
Modifies an instance.
source code
string
ActivateInstanceDisks(self, instance, ignore_size=None)
Activates an instance's disks.
source code
string
DeactivateInstanceDisks(self, instance)
Deactivates an instance's disks.
source code
string
GrowInstanceDisk(self, instance, disk, amount, wait_for_sync=None)
Grows a disk of an instance.
source code
list of str
GetInstanceTags(self, instance)
Gets tags for an instance.
source code
string
AddInstanceTags(self, instance, tags, dry_run=False)
Adds tags to an instance.
source code
string
DeleteInstanceTags(self, instance, tags, dry_run=False)
Deletes tags from an instance.
source code
string
RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None, dry_run=False)
Reboots an instance.
source code
string
ShutdownInstance(self, instance, dry_run=False, no_remember=False)
Shuts down an instance.
source code
string
StartupInstance(self, instance, dry_run=False, no_remember=False)
Starts up an instance.
source code
string
ReinstallInstance(self, instance, os=None, no_startup=False, osparams=None)
Reinstalls an instance.
source code
string
ReplaceInstanceDisks(self, instance, disks=None, mode=REPLACE_DISK_AUTO, remote_node=None, iallocator=None)
Replaces disks on an instance.
source code
string
PrepareExport(self, instance, mode)
Prepares an instance for an export.
source code
string
ExportInstance(self, instance, mode, destination, shutdown=None, remove_instance=None, x509_key_name=None, destination_x509_ca=None)
Exports an instance.
source code
string
MigrateInstance(self, instance, mode=None, cleanup=None)
Migrates an instance.
source code
string
FailoverInstance(self, instance, iallocator=None, ignore_consistency=None, target_node=None)
Does a failover of an instance.
source code
string
RenameInstance(self, instance, new_name, ip_check=None, name_check=None)
Changes the name of an instance.
source code
dict
GetInstanceConsole(self, instance)
Request information for connecting to instance's console.
source code
list of int
GetJobs(self)
Gets all jobs for the cluster.
source code
dict
GetJobStatus(self, job_id)
Gets the status of a job.
source code
bool
WaitForJobCompletion(self, job_id, period=5, retries=-1)
Polls cluster for job status until completion.
source code
dict
WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial)
Waits for job changes.
source code
tuple
CancelJob(self, job_id, dry_run=False)
Cancels a job.
source code
list of dict or str
GetNodes(self, bulk=False)
Gets all nodes in the cluster.
source code
dict
GetNode(self, node)
Gets information about a node.
source code
string, or a list for pre-2.5 results
EvacuateNode(self, node, iallocator=None, remote_node=None, dry_run=False, early_release=None, mode=None, accept_old=False)
Evacuates instances from a Ganeti node.
source code
string
MigrateNode(self, node, mode=None, dry_run=False, iallocator=None, target_node=None)
Migrates all primary instances from a node.
source code
str
GetNodeRole(self, node)
Gets the current role for a node.
source code
string
SetNodeRole(self, node, role, force=False)
Sets the role for a node.
source code
string
GetNodeStorageUnits(self, node, storage_type, output_fields)
Gets the storage units for a node.
source code
string
ModifyNodeStorageUnits(self, node, storage_type, name, allocatable=None)
Modifies parameters of storage units on the node.
source code
string
RepairNodeStorageUnits(self, node, storage_type, name)
Repairs a storage unit on the node.
source code
list of str
GetNodeTags(self, node)
Gets the tags for a node.
source code
string
AddNodeTags(self, node, tags, dry_run=False)
Adds tags to a node.
source code
string
DeleteNodeTags(self, node, tags, dry_run=False)
Delete tags from a node.
source code
list of dict or str
GetGroups(self, bulk=False)
Gets all node groups in the cluster.
source code
dict
GetGroup(self, group)
Gets information about a node group.
source code
string
CreateGroup(self, name, alloc_policy=None, dry_run=False)
Creates a new node group.
source code
string
ModifyGroup(self, group, **kwargs)
Modifies a node group.
source code
string
DeleteGroup(self, group, dry_run=False)
Deletes a node group.
source code
string
RenameGroup(self, group, new_name)
Changes the name of a node group.
source code
string
AssignGroupNodes(self, group, nodes, force=False, dry_run=False)
Assigns nodes to a group.
source code
list of strings
GetGroupTags(self, group)
Gets tags for a node group.
source code
string
AddGroupTags(self, group, tags, dry_run=False)
Adds tags to a node group.
source code
string
DeleteGroupTags(self, group, tags, dry_run=False)
Deletes tags from a node group.
source code
string
Query(self, what, fields, filter_=None)
Retrieves information about resources.
source code
string
QueryFields(self, what, fields=None)
Retrieves available fields for a resource.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
list
_EncodeQuery(query)
Encode query values for RAPI URL.
source code
Class Variables [hide private]
  USER_AGENT = "Ganeti RAPI Client"
  _json_encoder = simplejson.JSONEncoder(sort_keys= True)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, host, port=GANETI_RAPI_PORT, username=None, password=None, logger=logging, curl_config_fn=None, curl_factory=None)
(Constructor)

source code 

Initializes this class.

Parameters:
  • host (string) - the ganeti cluster master to interact with
  • port (int) - the port on which the RAPI is running (default is 5080)
  • username (string) - the username to connect with
  • password (string) - the password to connect with
  • curl_config_fn (callable) - Function to configure pycurl.Curl object
  • logger - Logging object
Overrides: object.__init__

_EncodeQuery(query)
Static Method

source code 

Encode query values for RAPI URL.

Parameters:
  • query (list of two-tuples) - Query arguments
Returns: list
Query list with encoded values

_SendRequest(self, method, path, query, content)

source code 

Sends an HTTP request.

This constructs a full URL, encodes and decodes HTTP bodies, and handles invalid responses in a pythonic way.

Parameters:
  • method (string) - HTTP method to use
  • path (string) - HTTP URL path
  • query (list of two-tuples) - query arguments to pass to urllib.urlencode
  • content (str or None) - HTTP body content
Returns: str
JSON-Decoded response
Raises:

GetVersion(self)

source code 

Gets the Remote API version running on the cluster.

Returns: int
Ganeti Remote API version

GetFeatures(self)

source code 

Gets the list of optional features supported by RAPI server.

Returns: list
List of optional features

GetOperatingSystems(self)

source code 

Gets the Operating Systems running in the Ganeti cluster.

Returns: list of str
operating systems

GetInfo(self)

source code 

Gets info about the cluster.

Returns: dict
information about the cluster

RedistributeConfig(self)

source code 

Tells the cluster to redistribute its configuration files.

Returns: string
job id

ModifyCluster(self, **kwargs)

source code 

Modifies cluster parameters.

More details for parameters can be found in the RAPI documentation.

Returns: string
job id

GetClusterTags(self)

source code 

Gets the cluster tags.

Returns: list of str
cluster tags

AddClusterTags(self, tags, dry_run=False)

source code 

Adds tags to the cluster.

Parameters:
  • tags (list of str) - tags to add to the cluster
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

DeleteClusterTags(self, tags, dry_run=False)

source code 

Deletes tags from the cluster.

Parameters:
  • tags (list of str) - tags to delete
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

GetInstances(self, bulk=False)

source code 

Gets information about instances on the cluster.

Parameters:
  • bulk (bool) - whether to return all information about all instances
Returns: list of dict or list of str
if bulk is True, info about the instances, else a list of instances

GetInstance(self, instance)

source code 

Gets information about an instance.

Parameters:
  • instance (str) - instance whose info to return
Returns: dict
info about the instance

GetInstanceInfo(self, instance, static=None)

source code 

Gets information about an instance.

Parameters:
  • instance (string) - Instance name
Returns: string
Job ID

CreateInstance(self, mode, name, disk_template, disks, nics, **kwargs)

source code 

Creates a new instance.

More details for parameters can be found in the RAPI documentation.

Parameters:
  • mode (string) - Instance creation mode
  • name (string) - Hostname of the instance to create
  • disk_template (string) - Disk template for instance (e.g. plain, diskless, file, or drbd)
  • disks (list of dicts) - List of disk definitions
  • nics (list of dicts) - List of NIC definitions
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

DeleteInstance(self, instance, dry_run=False)

source code 

Deletes an instance.

Parameters:
  • instance (str) - the instance to delete
Returns: string
job id

ModifyInstance(self, instance, **kwargs)

source code 

Modifies an instance.

More details for parameters can be found in the RAPI documentation.

Parameters:
  • instance (string) - Instance name
Returns: string
job id

ActivateInstanceDisks(self, instance, ignore_size=None)

source code 

Activates an instance's disks.

Parameters:
  • instance (string) - Instance name
  • ignore_size (bool) - Whether to ignore recorded size
Returns: string
job id

DeactivateInstanceDisks(self, instance)

source code 

Deactivates an instance's disks.

Parameters:
  • instance (string) - Instance name
Returns: string
job id

GrowInstanceDisk(self, instance, disk, amount, wait_for_sync=None)

source code 

Grows a disk of an instance.

More details for parameters can be found in the RAPI documentation.

Parameters:
  • instance (string) - Instance name
  • disk (integer) - Disk index
  • amount (integer) - Grow disk by this amount (MiB)
  • wait_for_sync (bool) - Wait for disk to synchronize
Returns: string
job id

GetInstanceTags(self, instance)

source code 

Gets tags for an instance.

Parameters:
  • instance (str) - instance whose tags to return
Returns: list of str
tags for the instance

AddInstanceTags(self, instance, tags, dry_run=False)

source code 

Adds tags to an instance.

Parameters:
  • instance (str) - instance to add tags to
  • tags (list of str) - tags to add to the instance
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

DeleteInstanceTags(self, instance, tags, dry_run=False)

source code 

Deletes tags from an instance.

Parameters:
  • instance (str) - instance to delete tags from
  • tags (list of str) - tags to delete
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None, dry_run=False)

source code 

Reboots an instance.

Parameters:
  • instance (str) - instance to rebot
  • reboot_type (str) - one of: hard, soft, full
  • ignore_secondaries (bool) - if True, ignores errors for the secondary node while re-assembling disks (in hard-reboot mode only)
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

ShutdownInstance(self, instance, dry_run=False, no_remember=False)

source code 

Shuts down an instance.

Parameters:
  • instance (str) - the instance to shut down
  • dry_run (bool) - whether to perform a dry run
  • no_remember (bool) - if true, will not record the state change
Returns: string
job id

StartupInstance(self, instance, dry_run=False, no_remember=False)

source code 

Starts up an instance.

Parameters:
  • instance (str) - the instance to start up
  • dry_run (bool) - whether to perform a dry run
  • no_remember (bool) - if true, will not record the state change
Returns: string
job id

ReinstallInstance(self, instance, os=None, no_startup=False, osparams=None)

source code 

Reinstalls an instance.

Parameters:
  • instance (str) - The instance to reinstall
  • os (str or None) - The operating system to reinstall. If None, the instance's current operating system will be installed again
  • no_startup (bool) - Whether to start the instance automatically
Returns: string
job id

ReplaceInstanceDisks(self, instance, disks=None, mode=REPLACE_DISK_AUTO, remote_node=None, iallocator=None)

source code 

Replaces disks on an instance.

Parameters:
  • instance (str) - instance whose disks to replace
  • disks (list of ints) - Indexes of disks to replace
  • mode (str) - replacement mode to use (defaults to replace_auto)
  • remote_node (str or None) - new secondary node to use (for use with replace_new_secondary mode)
  • iallocator (str or None) - instance allocator plugin to use (for use with replace_auto mode)
Returns: string
job id

PrepareExport(self, instance, mode)

source code 

Prepares an instance for an export.

Parameters:
  • instance (string) - Instance name
  • mode (string) - Export mode
Returns: string
Job ID

ExportInstance(self, instance, mode, destination, shutdown=None, remove_instance=None, x509_key_name=None, destination_x509_ca=None)

source code 

Exports an instance.

Parameters:
  • instance (string) - Instance name
  • mode (string) - Export mode
Returns: string
Job ID

MigrateInstance(self, instance, mode=None, cleanup=None)

source code 

Migrates an instance.

Parameters:
  • instance (string) - Instance name
  • mode (string) - Migration mode
  • cleanup (bool) - Whether to clean up a previously failed migration
Returns: string
job id

FailoverInstance(self, instance, iallocator=None, ignore_consistency=None, target_node=None)

source code 

Does a failover of an instance.

Parameters:
  • instance (string) - Instance name
  • iallocator (string) - Iallocator for deciding the target node for shared-storage instances
  • ignore_consistency (bool) - Whether to ignore disk consistency
  • target_node (string) - Target node for shared-storage instances
Returns: string
job id

RenameInstance(self, instance, new_name, ip_check=None, name_check=None)

source code 

Changes the name of an instance.

Parameters:
  • instance (string) - Instance name
  • new_name (string) - New instance name
  • ip_check (bool) - Whether to ensure instance's IP address is inactive
  • name_check (bool) - Whether to ensure instance's name is resolvable
Returns: string
job id

GetInstanceConsole(self, instance)

source code 

Request information for connecting to instance's console.

Parameters:
  • instance (string) - Instance name
Returns: dict
dictionary containing information about instance's console

GetJobs(self)

source code 

Gets all jobs for the cluster.

Returns: list of int
job ids for the cluster

GetJobStatus(self, job_id)

source code 

Gets the status of a job.

Parameters:
  • job_id (string) - job id whose status to query
Returns: dict
job status

WaitForJobCompletion(self, job_id, period=5, retries=-1)

source code 

Polls cluster for job status until completion.

Completion is defined as any of the following states listed in JOB_STATUS_FINALIZED.

Parameters:
  • job_id (string) - job id to watch
  • period (int) - how often to poll for status (optional, default 5s)
  • retries (int) - how many time to poll before giving up (optional, default -1 means unlimited)
Returns: bool
True if job succeeded or False if failed/status timeout

Deprecated: It is recommended to use WaitForJobChange wherever possible; WaitForJobChange returns immediately after a job changed and does not use polling

WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial)

source code 

Waits for job changes.

Parameters:
  • job_id (string) - Job ID for which to wait
Returns: dict
None if no changes have been detected and a dict with two keys, job_info and log_entries otherwise.

CancelJob(self, job_id, dry_run=False)

source code 

Cancels a job.

Parameters:
  • job_id (string) - id of the job to delete
  • dry_run (bool) - whether to perform a dry run
Returns: tuple
tuple containing the result, and a message (bool, string)

GetNodes(self, bulk=False)

source code 

Gets all nodes in the cluster.

Parameters:
  • bulk (bool) - whether to return all information about all instances
Returns: list of dict or str
if bulk is true, info about nodes in the cluster, else list of nodes in the cluster

GetNode(self, node)

source code 

Gets information about a node.

Parameters:
  • node (str) - node whose info to return
Returns: dict
info about the node

EvacuateNode(self, node, iallocator=None, remote_node=None, dry_run=False, early_release=None, mode=None, accept_old=False)

source code 

Evacuates instances from a Ganeti node.

Parameters:
  • node (str) - node to evacuate
  • iallocator (str or None) - instance allocator to use
  • remote_node (str) - node to evaucate to
  • dry_run (bool) - whether to perform a dry run
  • early_release (bool) - whether to enable parallelization
  • mode (string) - Node evacuation mode
  • accept_old (bool) - Whether caller is ready to accept old-style (pre-2.5) results
Returns: string, or a list for pre-2.5 results
Job ID or, if accept_old is set and server is pre-2.5, list of (job ID, instance name, new secondary node); if dry_run was specified, then the actual move jobs were not submitted and the job IDs will be None
Raises:
  • GanetiApiError - if an iallocator and remote_node are both specified

MigrateNode(self, node, mode=None, dry_run=False, iallocator=None, target_node=None)

source code 

Migrates all primary instances from a node.

Parameters:
  • node (str) - node to migrate
  • mode (string) - if passed, it will overwrite the live migration type, otherwise the hypervisor default will be used
  • dry_run (bool) - whether to perform a dry run
  • iallocator (string) - instance allocator to use
  • target_node (string) - Target node for shared-storage instances
Returns: string
job id

GetNodeRole(self, node)

source code 

Gets the current role for a node.

Parameters:
  • node (str) - node whose role to return
Returns: str
the current role for a node

SetNodeRole(self, node, role, force=False)

source code 

Sets the role for a node.

Parameters:
  • node (str) - the node whose role to set
  • role (str) - the role to set for the node
  • force (bool) - whether to force the role change
Returns: string
job id

GetNodeStorageUnits(self, node, storage_type, output_fields)

source code 

Gets the storage units for a node.

Parameters:
  • node (str) - the node whose storage units to return
  • storage_type (str) - storage type whose units to return
  • output_fields (str) - storage type fields to return
Returns: string
job id where results can be retrieved

ModifyNodeStorageUnits(self, node, storage_type, name, allocatable=None)

source code 

Modifies parameters of storage units on the node.

Parameters:
  • node (str) - node whose storage units to modify
  • storage_type (str) - storage type whose units to modify
  • name (str) - name of the storage unit
  • allocatable (bool or None) - Whether to set the "allocatable" flag on the storage unit (None=no modification, True=set, False=unset)
Returns: string
job id

RepairNodeStorageUnits(self, node, storage_type, name)

source code 

Repairs a storage unit on the node.

Parameters:
  • node (str) - node whose storage units to repair
  • storage_type (str) - storage type to repair
  • name (str) - name of the storage unit to repair
Returns: string
job id

GetNodeTags(self, node)

source code 

Gets the tags for a node.

Parameters:
  • node (str) - node whose tags to return
Returns: list of str
tags for the node

AddNodeTags(self, node, tags, dry_run=False)

source code 

Adds tags to a node.

Parameters:
  • node (str) - node to add tags to
  • tags (list of str) - tags to add to the node
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

DeleteNodeTags(self, node, tags, dry_run=False)

source code 

Delete tags from a node.

Parameters:
  • node (str) - node to remove tags from
  • tags (list of str) - tags to remove from the node
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

GetGroups(self, bulk=False)

source code 

Gets all node groups in the cluster.

Parameters:
  • bulk (bool) - whether to return all information about the groups
Returns: list of dict or str
if bulk is true, a list of dictionaries with info about all node groups in the cluster, else a list of names of those node groups

GetGroup(self, group)

source code 

Gets information about a node group.

Parameters:
  • group (str) - name of the node group whose info to return
Returns: dict
info about the node group

CreateGroup(self, name, alloc_policy=None, dry_run=False)

source code 

Creates a new node group.

Parameters:
  • name (str) - the name of node group to create
  • alloc_policy (str) - the desired allocation policy for the group, if any
  • dry_run (bool) - whether to peform a dry run
Returns: string
job id

ModifyGroup(self, group, **kwargs)

source code 

Modifies a node group.

More details for parameters can be found in the RAPI documentation.

Parameters:
  • group (string) - Node group name
Returns: string
job id

DeleteGroup(self, group, dry_run=False)

source code 

Deletes a node group.

Parameters:
  • group (str) - the node group to delete
  • dry_run (bool) - whether to peform a dry run
Returns: string
job id

RenameGroup(self, group, new_name)

source code 

Changes the name of a node group.

Parameters:
  • group (string) - Node group name
  • new_name (string) - New node group name
Returns: string
job id

AssignGroupNodes(self, group, nodes, force=False, dry_run=False)

source code 

Assigns nodes to a group.

Parameters:
  • group (string) - Node gropu name
  • nodes (list of strings) - List of nodes to assign to the group
Returns: string
job id

GetGroupTags(self, group)

source code 

Gets tags for a node group.

Parameters:
  • group (string) - Node group whose tags to return
Returns: list of strings
tags for the group

AddGroupTags(self, group, tags, dry_run=False)

source code 

Adds tags to a node group.

Parameters:
  • group (str) - group to add tags to
  • tags (list of string) - tags to add to the group
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

DeleteGroupTags(self, group, tags, dry_run=False)

source code 

Deletes tags from a node group.

Parameters:
  • group (str) - group to delete tags from
  • tags (list of string) - tags to delete
  • dry_run (bool) - whether to perform a dry run
Returns: string
job id

Query(self, what, fields, filter_=None)

source code 

Retrieves information about resources.

Parameters:
  • what (string) - Resource name, one of constants.QR_VIA_RAPI
  • fields (list of string) - Requested fields
  • filter_ (None or list) - Query filter
Returns: string
job id

QueryFields(self, what, fields=None)

source code 

Retrieves available fields for a resource.

Parameters:
Returns: string
job id