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
 
RedistributeConfig(self)
Tells the cluster to redistribute its configuration files.
source code
int
ModifyCluster(self, **kwargs)
Modifies cluster parameters.
source code
list of str
GetClusterTags(self)
Gets the cluster tags.
source code
int
AddClusterTags(self, tags, dry_run=False)
Adds tags to the cluster.
source code
 
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
int
CreateInstance(self, mode, name, disk_template, disks, nics, **kwargs)
Creates a new instance.
source code
int
DeleteInstance(self, instance, dry_run=False)
Deletes an instance.
source code
int
ModifyInstance(self, instance, **kwargs)
Modifies an instance.
source code
 
ActivateInstanceDisks(self, instance, ignore_size=None)
Activates an instance's disks.
source code
 
DeactivateInstanceDisks(self, instance)
Deactivates an instance's disks.
source code
int
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
int
AddInstanceTags(self, instance, tags, dry_run=False)
Adds tags to an instance.
source code
 
DeleteInstanceTags(self, instance, tags, dry_run=False)
Deletes tags from an instance.
source code
 
RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None, dry_run=False)
Reboots an instance.
source code
 
ShutdownInstance(self, instance, dry_run=False, no_remember=False)
Shuts down an instance.
source code
 
StartupInstance(self, instance, dry_run=False, no_remember=False)
Starts up an instance.
source code
 
ReinstallInstance(self, instance, os=None, no_startup=False, osparams=None)
Reinstalls an instance.
source code
int
ReplaceInstanceDisks(self, instance, disks=None, mode=REPLACE_DISK_AUTO, remote_node=None, iallocator=None, dry_run=False)
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
 
MigrateInstance(self, instance, mode=None, cleanup=None)
Migrates an instance.
source code
 
RenameInstance(self, instance, new_name, ip_check=None, name_check=None)
Changes the name of an instance.
source code
 
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
 
WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial)
Waits for job changes.
source code
 
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
list
EvacuateNode(self, node, iallocator=None, remote_node=None, dry_run=False, early_release=False)
Evacuates instances from a Ganeti node.
source code
int
MigrateNode(self, node, mode=None, dry_run=False)
Migrates all primary instances from a node.
source code
str
GetNodeRole(self, node)
Gets the current role for a node.
source code
int
SetNodeRole(self, node, role, force=False)
Sets the role for a node.
source code
int
GetNodeStorageUnits(self, node, storage_type, output_fields)
Gets the storage units for a node.
source code
int
ModifyNodeStorageUnits(self, node, storage_type, name, allocatable=None)
Modifies parameters of storage units on the node.
source code
int
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
int
AddNodeTags(self, node, tags, dry_run=False)
Adds tags to a node.
source code
int
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
int
CreateGroup(self, name, alloc_policy=None, dry_run=False)
Creates a new node group.
source code
int
ModifyGroup(self, group, **kwargs)
Modifies a node group.
source code
int
DeleteGroup(self, group, dry_run=False)
Deletes a node group.
source code
int
RenameGroup(self, group, new_name)
Changes the name of a node group.
source code
int
AssignGroupNodes(self, group, nodes, force=False, dry_run=False)
Assigns nodes to a group.
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:
job id

ModifyCluster(self, **kwargs)

source code 

Modifies cluster parameters.

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

Returns: int
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: int
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

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: int
job id

DeleteInstance(self, instance, dry_run=False)

source code 

Deletes an instance.

Parameters:
  • instance (str) - the instance to delete
Returns: int
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: int
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:
job id

DeactivateInstanceDisks(self, instance)

source code 

Deactivates an instance's disks.

Parameters:
  • instance (string) - Instance name
Returns:
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: int
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: int
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

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

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

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

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

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

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)
  • dry_run (bool) - whether to perform a dry run
Returns: int
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

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

GetInstanceConsole(self, instance)

source code 

Request information for connecting to instance's console.

Parameters:
  • instance (string) - Instance name

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 (int) - job id whose status to query
Returns: dict
job status

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

source code 

Waits for job changes.

Parameters:
  • job_id (int) - Job ID for which to wait

CancelJob(self, job_id, dry_run=False)

source code 

Cancels a job.

Parameters:
  • job_id (int) - id of the job to delete
  • dry_run (bool) - whether to perform a dry run

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=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
Returns: list
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)

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
Returns: int
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: int
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: int
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: int
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: int
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: int
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: int
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: int
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: int
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: int
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: int
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: int
job id