* Added @rtype and/or @return where missing
* Standardized on Python type names, replacing:
* "string", "String" and "strings" with "str"
* "Integer" and "ints" with "int"
* "dicts" with "dict"
* Fixed @type and @param for Query() filter parameter
---
lib/rapi/client.py | 167
++++++++++++++++++++++++++++++----------------------
1 files changed, 96 insertions(+), 71 deletions(-)
diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 7a0f6fa..a2adf88 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -268,13 +268,13 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
curl_config_fn=None, curl_factory=None):
"""Initializes this class.
- @type host: string
+ @type host: str
@param host: the ganeti cluster master to interact with
@type port: int
@param port: the port on which the RAPI is running (default is
5080)
- @type username: string
+ @type username: str
@param username: the username to connect with
- @type password: string
+ @type password: str
@param password: the password to connect with
@type curl_config_fn: callable
@param curl_config_fn: Function to configure C{pycurl.Curl} object
@@ -373,9 +373,9 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
This constructs a full URL, encodes and decodes HTTP bodies, and
handles invalid responses in a pythonic way.
- @type method: string
+ @type method: str
@param method: HTTP method to use
- @type path: string
+ @type path: str
@param path: HTTP URL path
@type query: list of two-tuples
@param query: query arguments to pass to urllib.urlencode
@@ -504,6 +504,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def RedistributeConfig(self):
"""Tells the cluster to redistribute its configuration files.
+ @rtype: str
@return: job id
"""
@@ -516,7 +517,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
More details for parameters can be found in the RAPI documentation.
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -543,7 +544,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -561,6 +562,8 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@param tags: tags to delete
@type dry_run: bool
@param dry_run: whether to perform a dry run
+ @rtype: str
+ @return: job id
"""
query = [("tag", t) for t in tags]
@@ -609,10 +612,10 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def GetInstanceInfo(self, instance, static=None):
"""Gets information about an instance.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @rtype: string
- @return: Job ID
+ @rtype: str
+ @return: job id
"""
if static is not None:
@@ -630,21 +633,21 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
More details for parameters can be found in the RAPI documentation.
- @type mode: string
+ @type mode: str
@param mode: Instance creation mode
- @type name: string
+ @type name: str
@param name: Hostname of the instance to create
- @type disk_template: string
+ @type disk_template: str
@param disk_template: Disk template for instance (e.g. plain,
diskless,
file, or drbd)
- @type disks: list of dicts
+ @type disks: list of dict
@param disks: List of disk definitions
- @type nics: list of dicts
+ @type nics: list of dict
@param nics: List of NIC definitions
@type dry_run: bool
@keyword dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -758,7 +761,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type instance: str
@param instance: the instance to delete
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -775,9 +778,9 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
More details for parameters can be found in the RAPI documentation.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -790,10 +793,11 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def ActivateInstanceDisks(self, instance, ignore_size=None):
"""Activates an instance's disks.
- @type instance: string
+ @type instance: str
@param instance: Instance name
@type ignore_size: bool
@param ignore_size: Whether to ignore recorded size
+ @rtype: str
@return: job id
"""
@@ -808,8 +812,9 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def DeactivateInstanceDisks(self, instance):
"""Deactivates an instance's disks.
- @type instance: string
+ @type instance: str
@param instance: Instance name
+ @rtype: str
@return: job id
"""
@@ -822,15 +827,15 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
More details for parameters can be found in the RAPI documentation.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @type disk: integer
+ @type disk: int
@param disk: Disk index
- @type amount: integer
+ @type amount: int
@param amount: Grow disk by this amount (MiB)
@type wait_for_sync: bool
@param wait_for_sync: Wait for disk to synchronize
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -870,7 +875,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -891,6 +896,8 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@param tags: tags to delete
@type dry_run: bool
@param dry_run: whether to perform a dry run
+ @rtype: str
+ @return: job id
"""
query = [("tag", t) for t in tags]
@@ -914,6 +921,8 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
while re-assembling disks (in hard-reboot mode only)
@type dry_run: bool
@param dry_run: whether to perform a dry run
+ @rtype: str
+ @return: job id
"""
query = []
@@ -935,6 +944,8 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@param instance: the instance to shut down
@type dry_run: bool
@param dry_run: whether to perform a dry run
+ @rtype: str
+ @return: job id
"""
query = []
@@ -952,6 +963,8 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@param instance: the instance to start up
@type dry_run: bool
@param dry_run: whether to perform a dry run
+ @rtype: str
+ @return: job id
"""
query = []
@@ -973,6 +986,8 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
current operating system will be installed again
@type no_startup: bool
@param no_startup: Whether to start the instance automatically
+ @rtype: str
+ @return: job id
"""
if _INST_REINSTALL_REQV1 in self.GetFeatures():
@@ -1007,7 +1022,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type instance: str
@param instance: instance whose disks to replace
- @type disks: list of ints
+ @type disks: list of int
@param disks: Indexes of disks to replace
@type mode: str
@param mode: replacement mode to use (defaults to replace_auto)
@@ -1020,7 +1035,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1047,12 +1062,12 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def PrepareExport(self, instance, mode):
"""Prepares an instance for an export.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @type mode: string
+ @type mode: str
@param mode: Export mode
- @rtype: string
- @return: Job ID
+ @rtype: str
+ @return: job id
"""
query = [("mode", mode)]
@@ -1065,12 +1080,12 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
x509_key_name=None, destination_x509_ca=None):
"""Exports an instance.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @type mode: string
+ @type mode: str
@param mode: Export mode
- @rtype: string
- @return: Job ID
+ @rtype: str
+ @return: job id
"""
body = {
@@ -1097,12 +1112,14 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def MigrateInstance(self, instance, mode=None, cleanup=None):
"""Migrates an instance.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @type mode: string
+ @type mode: str
@param mode: Migration mode
@type cleanup: bool
@param cleanup: Whether to clean up a previously failed migration
+ @rtype: str
+ @return: job id
"""
body = {}
@@ -1120,14 +1137,16 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def RenameInstance(self, instance, new_name, ip_check=None,
name_check=None):
"""Changes the name of an instance.
- @type instance: string
+ @type instance: str
@param instance: Instance name
- @type new_name: string
+ @type new_name: str
@param new_name: New instance name
@type ip_check: bool
@param ip_check: Whether to ensure instance's IP address is
inactive
@type name_check: bool
@param name_check: Whether to ensure instance's name is resolvable
+ @rtype: str
+ @return: job id
"""
body = {
@@ -1147,8 +1166,10 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def GetInstanceConsole(self, instance):
"""Request information for connecting to instance's console.
- @type instance: string
+ @type instance: str
@param instance: Instance name
+ @rtype: dict
+ @return: dictionary containing information about the instance's
console
"""
return self._SendRequest(HTTP_GET,
@@ -1170,7 +1191,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def GetJobStatus(self, job_id):
"""Gets the status of a job.
- @type job_id: string
+ @type job_id: str
@param job_id: job id whose status to query
@rtype: dict
@@ -1187,7 +1208,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
Completion is defined as any of the following states listed in
L{JOB_STATUS_FINALIZED}.
- @type job_id: string
+ @type job_id: str
@param job_id: job id to watch
@type period: int
@param period: how often to poll for status (optional, default 5s)
@@ -1221,8 +1242,10 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def WaitForJobChange(self, job_id, fields, prev_job_info,
prev_log_serial):
"""Waits for job changes.
- @type job_id: string
+ @type job_id: str
@param job_id: Job ID for which to wait
+ @return: None if no changes have been detected and a dict with two
keys, job_info and log_entries otherwise.
+ @rtype: dict
"""
body = {
@@ -1238,10 +1261,12 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def CancelJob(self, job_id, dry_run=False):
"""Cancels a job.
- @type job_id: string
+ @type job_id: str
@param job_id: id of the job to delete
@type dry_run: bool
@param dry_run: whether to perform a dry run
+ @rtype: tuple
+ @return: tuple containing the result, and a message (bool, str)
"""
query = []
@@ -1334,13 +1359,13 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type node: str
@param node: node to migrate
- @type mode: string
+ @type mode: str
@param mode: if passed, it will overwrite the live migration type,
otherwise the hypervisor default will be used
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1378,7 +1403,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type force: bool
@param force: whether to force the role change
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1400,7 +1425,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type output_fields: str
@param output_fields: storage type fields to return
- @rtype: string
+ @rtype: str
@return: job id where results can be retrieved
"""
@@ -1426,7 +1451,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@param allocatable: Whether to set the "allocatable" flag on the
storage
unit (None=no modification, True=set,
False=unset)
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1452,7 +1477,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type name: str
@param name: name of the storage unit to repair
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1489,7 +1514,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1511,7 +1536,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to perform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1569,7 +1594,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to peform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1590,9 +1615,9 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
More details for parameters can be found in the RAPI documentation.
- @type group: string
+ @type group: str
@param group: Node group name
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1608,7 +1633,7 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
@type dry_run: bool
@param dry_run: whether to peform a dry run
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1623,12 +1648,12 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def RenameGroup(self, group, new_name):
"""Changes the name of a node group.
- @type group: string
+ @type group: str
@param group: Node group name
- @type new_name: string
+ @type new_name: str
@param new_name: New node group name
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1643,12 +1668,12 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def AssignGroupNodes(self, group, nodes, force=False, dry_run=False):
"""Assigns nodes to a group.
- @type group: string
+ @type group: str
@param group: Node gropu name
- @type nodes: list of strings
+ @type nodes: list of str
@param nodes: List of nodes to assign to the group
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1671,14 +1696,14 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def Query(self, what, fields, filter_=None):
"""Retrieves information about resources.
- @type what: string
+ @type what: str
@param what: Resource name, one of L{constants.QR_VIA_RAPI}
- @type fields: list of string
+ @type fields: list of str
@param fields: Requested fields
- @type filter_: None or list
- @param filter_ Query filter
+ @type filter: None or list
+ @param filter: Query filter
- @rtype: string
+ @rtype: str
@return: job id
"""
@@ -1696,12 +1721,12 @@ class GanetiRapiClient(object): # pylint:
disable-msg=R0904
def QueryFields(self, what, fields=None):
"""Retrieves available fields for a resource.
- @type what: string
+ @type what: str
@param what: Resource name, one of L{constants.QR_VIA_RAPI}
- @type fields: list of string
+ @type fields: list of str
@param fields: Requested fields
- @rtype: string
+ @rtype: str
@return: job id
"""
--
1.7.1