Package ganeti :: Module backend
[hide private]
[frames] | no frames]

Module backend

source code

Functions used by the node daemon

Classes [hide private]
  HooksRunner
Hook runner.
  IAllocatorRunner
IAllocator runner.
  DevCacheManager
Simple class for managing a cache of block device information.
Functions [hide private]
ssconf.SimpleStore
_GetConfig()
Simple wrapper to return a SimpleStore.
source code
ssh.SshRunner
_GetSshRunner(cluster_name)
Simple wrapper to return an SshRunner.
source code
str
_Decompress(data)
Unpacks data compressed by the RPC client.
source code
 
_CleanDirectory(path, exclude=None)
Removes all regular files in a directory.
source code
 
_BuildUploadFileList()
Build the list of allowed upload files.
source code
None
JobQueuePurge()
Removes job queue files and archived jobs.
source code
tuple
GetMasterInfo()
Returns master information.
source code
None
StartMaster(start_daemons, no_voting)
Activate local node as master node.
source code
None
StopMaster(stop_daemons)
Deactivate this node as master.
source code
boolean
AddNode(dsa, dsapub, rsa, rsapub, sshkey, sshpub)
Joins this node to the cluster.
source code
 
LeaveCluster()
Cleans up and remove the current node.
source code
dict
GetNodeInfo(vgname, hypervisor_type)
Gives back a hash with different information about the node.
source code
dict
VerifyNode(what, cluster_name)
Verify the status of the local node.
source code
dict
GetVolumeList(vg_name)
Compute list of logical volumes and their size.
source code
dict
ListVolumeGroups()
List the volume groups and their size.
source code
list
NodeVolumes()
List all volumes on this node.
source code
boolean
BridgesExist(bridges_list)
Check if a list of bridges exist on the current node.
source code
list
GetInstanceList(hypervisor_list)
Provides a list of instances.
source code
dict
GetInstanceInfo(instance, hname)
Gives back the information about an instance as a dictionary.
source code
tuple
GetInstanceMigratable(instance)
Gives whether an instance can be migrated.
source code
dict
GetAllInstancesInfo(hypervisor_list)
Gather data about all instances.
source code
boolean
InstanceOsAdd(instance)
Add an OS to an instance.
source code
boolean
RunRenameInstance(instance, old_name)
Run the OS rename script for an instance.
source code
dict
_GetVGInfo(vg_name)
Get information about the volume group.
source code
 
_GetBlockDevSymlinkPath(instance_name, idx) source code
 
_SymlinkBlockDev(instance_name, device_path, idx)
Set up symlinks to a instance's block device.
source code
 
_RemoveBlockDevLinks(instance_name, disks)
Remove the block device symlinks belonging to the given instance.
source code
list
_GatherAndLinkBlockDevs(instance)
Set up an instance's block device(s).
source code
boolean
StartInstance(instance)
Start an instance.
source code
boolean
InstanceShutdown(instance)
Shut an instance down.
source code
boolean
InstanceReboot(instance, reboot_type)
Reboot an instance.
source code
 
MigrationInfo(instance)
Gather information about an instance to be migrated.
source code
 
AcceptInstance(instance, info, target)
Prepare the node to accept an instance.
source code
 
FinalizeMigration(instance, info, success)
Finalize any preparation to accept an instance.
source code
tuple
MigrateInstance(instance, target, live)
Migrates an instance to another node.
source code
 
BlockdevCreate(disk, size, owner, on_primary, info)
Creates a block device for an instance.
source code
boolean
BlockdevRemove(disk)
Remove a block device.
source code
 
_RecursiveAssembleBD(disk, owner, as_primary)
Activate a block device for an instance.
source code
str or boolean
BlockdevAssemble(disk, owner, as_primary)
Activate a block device for an instance.
source code
boolean
BlockdevShutdown(disk)
Shut down a block device.
source code
boolean
BlockdevAddchildren(parent_cdev, new_cdevs)
Extend a mirrored block device.
source code
boolean
BlockdevRemovechildren(parent_cdev, new_cdevs)
Shrink a mirrored block device.
source code
disk
BlockdevGetmirrorstatus(disks)
Get the mirroring status of a list of devices.
source code
 
_RecursiveFindBD(disk)
Check if a device is activated.
source code
None or tuple
BlockdevFind(disk)
Check if a device is activated.
source code
list
BlockdevGetsize(disks)
Computes the size of the given disks.
source code
boolean
UploadFile(file_name, data, mode, uid, gid, atime, mtime)
Write a file to the filesystem.
source code
 
WriteSsconfFiles(values)
Update all ssconf files.
source code
 
_ErrnoOrStr(err)
Format an EnvironmentError exception.
source code
int or None
_OSOndiskVersion(name, os_dir)
Compute and return the API version of a given OS.
source code
list of objects.OS
DiagnoseOS(top_dirs=None)
Compute the validity for all OSes.
source code
objects.OS
OSFromDisk(name, base_dir=None)
Create an OS instance from disk.
source code
dict
OSEnvironment(instance, debug=0)
Calculate the environment for an os script.
source code
(status, result)
BlockdevGrow(disk, amount)
Grow a stack of block devices.
source code
string
BlockdevSnapshot(disk)
Create a snapshot copy of a block device.
source code
boolean
ExportSnapshot(disk, dest_node, instance, cluster_name, idx)
Export a block device snapshot to a remote node.
source code
boolean
FinalizeExport(instance, snap_disks)
Write out the export configuration information.
source code
objects.SerializableConfigParser
ExportInfo(dest)
Get export configuration information.
source code
list of boolean
ImportOSIntoInstance(instance, src_node, src_images, cluster_name)
Import an os image into an instance.
source code
list
ListExports()
Return a list of exports currently available on this machine.
source code
boolean
RemoveExport(export)
Remove an existing export from the node.
source code
boolean
BlockdevRename(devlist)
Rename a list of block devices.
source code
 
_TransformFileStorageDir(file_storage_dir)
Checks whether given file_storage_dir is valid.
source code
tuple
CreateFileStorageDir(file_storage_dir)
Create file storage directory.
source code
tuple (success,)
RemoveFileStorageDir(file_storage_dir)
Remove file storage directory.
source code
tuple (success,)
RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir)
Rename the file storage directory.
source code
boolean
_IsJobQueueFile(file_name)
Checks whether the given filename is in the queue directory.
source code
boolean
JobQueueUpdate(file_name, content)
Updates a file in the queue directory.
source code
boolean
JobQueueRename(old, new)
Renames a job queue file.
source code
boolean
JobQueueSetDrainFlag(drain_flag)
Set the drain flag for the queue.
source code
tuple (success, message)
BlockdevClose(instance_name, disks)
Closes the given block devices.
source code
tuple (success, message)
ValidateHVParams(hvname, hvparams)
Validates the given hypervisor parameters.
source code
 
DemoteFromMC()
Demotes the current node from master candidate role.
source code
 
_FindDisks(nodes_ip, disks)
Sets the physical ID on disks and returns the block devices.
source code
 
DrbdDisconnectNet(nodes_ip, disks)
Disconnects the network on a list of drbd devices.
source code
 
DrbdAttachNet(nodes_ip, disks, instance_name, multimaster)
Attaches the network on a list of drbd devices.
source code
 
DrbdWaitSync(nodes_ip, disks)
Wait until DRBDs have synchronized.
source code
Variables [hide private]
  _ALLOWED_UPLOAD_FILES = _BuildUploadFileList()
denotes which files are accepted in the UploadFile function

Imports: os, shutil, time, stat, errno, re, subprocess, random, logging, tempfile, zlib, base64, errors, utils, ssh, hypervisor, constants, bdev, objects, ssconf


Function Details [hide private]

_GetConfig()

source code 

Simple wrapper to return a SimpleStore.

Returns: ssconf.SimpleStore
a SimpleStore instance

_GetSshRunner(cluster_name)

source code 

Simple wrapper to return an SshRunner.

Parameters:
  • cluster_name (str) - the cluster name, which is needed by the SshRunner constructor
Returns: ssh.SshRunner
an SshRunner instance

_Decompress(data)

source code 

Unpacks data compressed by the RPC client.

Parameters:
  • data (list or tuple) - Data sent by RPC client
Returns: str
Decompressed data

_CleanDirectory(path, exclude=None)

source code 

Removes all regular files in a directory.

Parameters:
  • path (str) - the directory to clean
  • exclude (list) - list of files to be excluded, defaults to the empty list

_BuildUploadFileList()

source code 

Build the list of allowed upload files.

This is abstracted so that it's built only once at module import time.

GetMasterInfo()

source code 

Returns master information.

This is an utility function to compute master information, either for consumption here or from the node daemon.

Returns: tuple
(master_netdev, master_ip, master_name) if we have a good configuration, otherwise (None, None, None)

StartMaster(start_daemons, no_voting)

source code 

Activate local node as master node.

The function will always try activate the IP address of the master (unless someone else has it). It will also start the master daemons, based on the start_daemons parameter.

Parameters:
  • start_daemons (boolean) - whther to also start the master daemons (ganeti-masterd and ganeti-rapi)
  • no_voting (boolean) - whether to start ganeti-masterd without a node vote (if start_daemons is True), but still non-interactively
Returns: None

StopMaster(stop_daemons)

source code 

Deactivate this node as master.

The function will always try to deactivate the IP address of the master. It will also stop the master daemons depending on the stop_daemons parameter.

Parameters:
  • stop_daemons (boolean) - whether to also stop the master daemons (ganeti-masterd and ganeti-rapi)
Returns: None

AddNode(dsa, dsapub, rsa, rsapub, sshkey, sshpub)

source code 

Joins this node to the cluster.

This does the following:

  • updates the hostkeys of the machine (rsa and dsa)
  • adds the ssh private key to the user
  • adds the ssh public key to the users' authorized_keys file
Parameters:
  • dsa (str) - the DSA private key to write
  • dsapub (str) - the DSA public key to write
  • rsa (str) - the RSA private key to write
  • rsapub (str) - the RSA public key to write
  • sshkey (str) - the SSH private key to write
  • sshpub (str) - the SSH public key to write
Returns: boolean
the success of the operation

LeaveCluster()

source code 

Cleans up and remove the current node.

This function cleans up and prepares the current node to be removed from the cluster.

If processing is successful, then it raises an errors.QuitGanetiException which is used as a special case to shutdown the node daemon.

GetNodeInfo(vgname, hypervisor_type)

source code 

Gives back a hash with different information about the node.

Parameters:
  • vgname (string) - the name of the volume group to ask for disk space information
  • hypervisor_type (str) - the name of the hypervisor to ask for memory information
Returns: dict
dictionary with the following keys:
  • vg_size is the size of the configured volume group in MiB
  • vg_free is the free size of the volume group in MiB
  • memory_dom0 is the memory allocated for domain0 in MiB
  • memory_free is the currently available (free) ram in MiB
  • memory_total is the total number of ram in MiB

VerifyNode(what, cluster_name)

source code 

Verify the status of the local node.

Based on the input what parameter, various checks are done on the local node.

If the filelist key is present, this list of files is checksummed and the file/checksum pairs are returned.

If the nodelist key is present, we check that we have connectivity via ssh with the target nodes (and check the hostname report).

If the node-net-test key is present, we check that we have connectivity to the given nodes via both primary IP and, if applicable, secondary IPs.

Parameters:
  • what (dict) - a dictionary of things to check:
    • filelist: list of files for which to compute checksums
    • nodelist: list of nodes we should check ssh communication with
    • node-net-test: list of nodes we should check node daemon port connectivity with
    • hypervisor: list with hypervisors to run the verify for
Returns: dict
a dictionary with the same keys as the input dict, and values representing the result of the checks

GetVolumeList(vg_name)

source code 

Compute list of logical volumes and their size.

Parameters:
  • vg_name (str) - the volume group whose LVs we should list
Returns: dict
dictionary of all partions (key) with value being a tuple of their size (in MiB), inactive and online status:
 {'test1': ('20.06', True, True)}

in case of errors, a string is returned with the error details.

ListVolumeGroups()

source code 

List the volume groups and their size.

Returns: dict
dictionary with keys volume name and values the size of the volume

NodeVolumes()

source code 

List all volumes on this node.

Returns: list
A list of dictionaries, each having four keys:
  • name: the logical volume name,
  • size: the size of the logical volume
  • dev: the physical device on which the LV lives
  • vg: the volume group to which it belongs

In case of errors, we return an empty list and log the error.

Note that since a logical volume can live on multiple physical volumes, the resulting list might include a logical volume multiple times.

BridgesExist(bridges_list)

source code 

Check if a list of bridges exist on the current node.

Returns: boolean
True if all of them exist, False otherwise

GetInstanceList(hypervisor_list)

source code 

Provides a list of instances.

Parameters:
  • hypervisor_list (list) - the list of hypervisors to query information
Returns: list
a list of all running instances on the current node
  • instance1.example.com
  • instance2.example.com

GetInstanceInfo(instance, hname)

source code 

Gives back the information about an instance as a dictionary.

Parameters:
  • instance (string) - the instance name
  • hname (string) - the hypervisor type of the instance
Returns: dict
dictionary with the following keys:
  • memory: memory size of instance (int)
  • state: xen state of instance (string)
  • time: cpu time of instance (float)

GetInstanceMigratable(instance)

source code 

Gives whether an instance can be migrated.

Parameters:
Returns: tuple
tuple of (result, description) where:
  • result: whether the instance can be migrated or not
  • description: a description of the issue, if relevant

GetAllInstancesInfo(hypervisor_list)

source code 

Gather data about all instances.

This is the equivalent of GetInstanceInfo, except that it computes data for all instances at once, thus being faster if one needs data about more than one instance.

Parameters:
  • hypervisor_list (list) - list of hypervisors to query for instance data
Returns: dict
dictionary of instance: data, with data having the following keys:
  • memory: memory size of instance (int)
  • state: xen state of instance (string)
  • time: cpu time of instance (float)
  • vcpus: the number of vcpus

InstanceOsAdd(instance)

source code 

Add an OS to an instance.

Parameters:
Returns: boolean
the success of the operation

RunRenameInstance(instance, old_name)

source code 

Run the OS rename script for an instance.

Parameters:
  • instance (objects.Instance) - Instance whose OS is to be installed
  • old_name (string) - previous instance name
Returns: boolean
the success of the operation

_GetVGInfo(vg_name)

source code 

Get information about the volume group.

Parameters:
  • vg_name (str) - the volume group which we query
Returns: dict
A dictionary with the following keys:
  • vg_size is the total size of the volume group in MiB
  • vg_free is the free size of the volume group in MiB
  • pv_count are the number of physical disks in that VG

If an error occurs during gathering of data, we return the same dict with keys all set to None.

_SymlinkBlockDev(instance_name, device_path, idx)

source code 

Set up symlinks to a instance's block device.

This is an auxiliary function run when an instance is start (on the primary node) or when an instance is migrated (on the target node).

Parameters:
  • instance_name - the name of the target instance
  • device_path - path of the physical block device, on the node
  • idx - the disk index
Returns:
absolute path to the disk's symlink

_GatherAndLinkBlockDevs(instance)

source code 

Set up an instance's block device(s).

This is run on the primary node at instance startup. The block devices must be already assembled.

Parameters:
Returns: list
list of (disk_object, device_path)

StartInstance(instance)

source code 

Start an instance.

Parameters:
Returns: boolean
whether the startup was successful or not

InstanceShutdown(instance)

source code 

Shut an instance down.

Parameters:
Returns: boolean
whether the startup was successful or not

Note: this functions uses polling with a hardcoded timeout.

InstanceReboot(instance, reboot_type)

source code 

Reboot an instance.

Parameters:
Returns: boolean
the success of the operation

MigrationInfo(instance)

source code 

Gather information about an instance to be migrated.

Parameters:

AcceptInstance(instance, info, target)

source code 

Prepare the node to accept an instance.

Parameters:
  • instance (objects.Instance) - the instance definition
  • info (string/data (opaque)) - migration information, from the source node
  • target (string) - target host (usually ip), on this node

FinalizeMigration(instance, info, success)

source code 

Finalize any preparation to accept an instance.

Parameters:
  • instance (objects.Instance) - the instance definition
  • info (string/data (opaque)) - migration information, from the source node
  • success (boolean) - whether the migration was a success or a failure

MigrateInstance(instance, target, live)

source code 

Migrates an instance to another node.

Parameters:
  • instance (objects.Instance) - the instance definition
  • target (string) - the target node name
  • live (boolean) - whether the migration should be done live or not (the interpretation of this parameter is left to the hypervisor)
Returns: tuple
a tuple of (success, msg) where:
  • succes is a boolean denoting the success/failure of the operation
  • msg is a string with details in case of failure

BlockdevCreate(disk, size, owner, on_primary, info)

source code 

Creates a block device for an instance.

Parameters:
  • disk (objects.Disk) - the object describing the disk we should create
  • size (int) - the size of the physical underlying device, in MiB
  • owner (str) - the name of the instance for which disk is created, used for device cache data
  • on_primary (boolean) - indicates if it is the primary node or not
  • info (string) - string that will be sent to the physical device creation, used for example to set (LVM) tags on LVs
Returns:
the new unique_id of the device (this can sometime be computed only after creation), or None. On secondary nodes, it's not required to return anything.

BlockdevRemove(disk)

source code 

Remove a block device.

Parameters:
Returns: boolean
the success of the operation

Note: This is intended to be called recursively.

_RecursiveAssembleBD(disk, owner, as_primary)

source code 

Activate a block device for an instance.

This is run on the primary and secondary nodes for an instance.

Parameters:
  • disk (objects.Disk) - the disk we try to assemble
  • owner (str) - the name of the instance which owns the disk
  • as_primary (boolean) - if we should make the block device read/write
Returns:
the assembled device or None (in case no device was assembled)
Raises:

Note: this function is called recursively.

BlockdevAssemble(disk, owner, as_primary)

source code 

Activate a block device for an instance.

This is a wrapper over _RecursiveAssembleBD.

Returns: str or boolean
a /dev/... path for primary nodes, and True for secondary nodes

BlockdevShutdown(disk)

source code 

Shut down a block device.

First, if the device is assembled (Attach() is successful), then the device is shutdown. Then the children of the device are shutdown.

This function is called recursively. Note that we don't cache the children or such, as oppossed to assemble, shutdown of different devices doesn't require that the upper device was active.

Parameters:
  • disk (objects.Disk) - the description of the disk we should shutdown
Returns: boolean
the success of the operation

BlockdevAddchildren(parent_cdev, new_cdevs)

source code 

Extend a mirrored block device.

Parameters:
  • parent_cdev (objects.Disk) - the disk to which we should add children
  • new_cdevs (list of objects.Disk) - the list of children which we should add
Returns: boolean
the success of the operation

BlockdevRemovechildren(parent_cdev, new_cdevs)

source code 

Shrink a mirrored block device.

Parameters:
  • parent_cdev (objects.Disk) - the disk from which we should remove children
  • new_cdevs (list of objects.Disk) - the list of children which we should remove
Returns: boolean
the success of the operation

BlockdevGetmirrorstatus(disks)

source code 

Get the mirroring status of a list of devices.

Parameters:
  • disks (list of objects.Disk) - the list of disks which we should query
Returns: disk
a list of (mirror_done, estimated_time) tuples, which are the result of bdev.BlockDev.CombinedSyncStatus
Raises:

_RecursiveFindBD(disk)

source code 

Check if a device is activated.

If so, return information about the real device.

Parameters:
Returns:
None if the device can't be found, otherwise the device instance

BlockdevFind(disk)

source code 

Check if a device is activated.

If it is, return information about the real device.

Parameters:
Returns: None or tuple
None if the disk cannot be found, otherwise a tuple (device_path, major, minor, sync_percent, estimated_time, is_degraded)

BlockdevGetsize(disks)

source code 

Computes the size of the given disks.

If a disk is not found, returns None instead.

Parameters:
  • disks (list of objects.Disk) - the list of disk to compute the size for
Returns: list
list with elements None if the disk cannot be found, otherwise the size

UploadFile(file_name, data, mode, uid, gid, atime, mtime)

source code 

Write a file to the filesystem.

This allows the master to overwrite(!) a file. It will only perform the operation if the file belongs to a list of configuration files.

Parameters:
  • file_name (str) - the target file name
  • data (str) - the new contents of the file
  • mode (int) - the mode to give the file (can be None)
  • uid (int) - the owner of the file (can be -1 for default)
  • gid (int) - the group of the file (can be -1 for default)
  • atime (float) - the atime to set on the file (can be None)
  • mtime (float) - the mtime to set on the file (can be None)
Returns: boolean
the success of the operation; errors are logged in the node daemon log

WriteSsconfFiles(values)

source code 

Update all ssconf files.

Wrapper around the SimpleStore.WriteFiles.

_ErrnoOrStr(err)

source code 

Format an EnvironmentError exception.

If the err argument has an errno attribute, it will be looked up and converted into a textual E... description. Otherwise the string representation of the error will be returned.

Parameters:
  • err (EnvironmentError) - the exception to format

_OSOndiskVersion(name, os_dir)

source code 

Compute and return the API version of a given OS.

This function will try to read the API version of the OS given by the 'name' parameter and residing in the 'os_dir' directory.

Parameters:
  • name (str) - the OS name we should look for
  • os_dir (str) - the directory inwhich we should look for the OS
Returns: int or None
Either an integer denoting the version or None in the case when this is not a valid OS name.
Raises:

DiagnoseOS(top_dirs=None)

source code 

Compute the validity for all OSes.

Parameters:
Returns: list of objects.OS
an OS object for each name in all the given directories

OSFromDisk(name, base_dir=None)

source code 

Create an OS instance from disk.

This function will return an OS instance if the given name is a valid OS name. Otherwise, it will raise an appropriate errors.InvalidOS exception, detailing why this is not a valid OS.

Parameters:
  • base_dir (string) - Base directory containing OS installations. Defaults to a search in all the OS_SEARCH_PATH dirs.
Returns: objects.OS
the OS instance if we find a valid one
Raises:

OSEnvironment(instance, debug=0)

source code 

Calculate the environment for an os script.

Parameters:
  • instance (objects.Instance) - target instance for the os script run
  • debug (integer) - debug level (0 or 1, for OS Api 10)
Returns: dict
dict of environment variables
Raises:

BlockdevGrow(disk, amount)

source code 

Grow a stack of block devices.

This function is called recursively, with the childrens being the first ones to resize.

Parameters:
Returns: (status, result)
a tuple with the status of the operation (True/False), and the errors message if status is False

BlockdevSnapshot(disk)

source code 

Create a snapshot copy of a block device.

This function is called recursively, and the snapshot is actually created just for the leaf lvm backend device.

Parameters:
Returns: string
snapshot disk path

ExportSnapshot(disk, dest_node, instance, cluster_name, idx)

source code 

Export a block device snapshot to a remote node.

Parameters:
  • disk (objects.Disk) - the description of the disk to export
  • dest_node (str) - the destination node to export to
  • instance (objects.Instance) - the instance object to whom the disk belongs
  • cluster_name (str) - the cluster name, needed for SSH hostalias
  • idx (int) - the index of the disk in the instance's disk list, used to export to the OS scripts environment
Returns: boolean
the success of the operation

FinalizeExport(instance, snap_disks)

source code 

Write out the export configuration information.

Parameters:
  • instance (objects.Instance) - the instance which we export, used for saving configuration
  • snap_disks (list of objects.Disk) - list of snapshot block devices, which will be used to get the actual name of the dump file
Returns: boolean
the success of the operation

ExportInfo(dest)

source code 

Get export configuration information.

Parameters:
  • dest (str) - directory containing the export
Returns: objects.SerializableConfigParser
a serializable config file containing the export info

ImportOSIntoInstance(instance, src_node, src_images, cluster_name)

source code 

Import an os image into an instance.

Parameters:
  • instance (objects.Instance) - instance to import the disks into
  • src_node (string) - source node for the disk images
  • src_images (list of string) - absolute paths of the disk images
Returns: list of boolean
each boolean represent the success of importing the n-th disk

ListExports()

source code 

Return a list of exports currently available on this machine.

Returns: list
list of the exports

RemoveExport(export)

source code 

Remove an existing export from the node.

Parameters:
  • export (str) - the name of the export to remove
Returns: boolean
the success of the operation

BlockdevRename(devlist)

source code 

Rename a list of block devices.

Parameters:
  • devlist (list of tuples) - list of tuples of the form (disk, new_logical_id, new_physical_id); disk is an objects.Disk object describing the current disk, and new logical_id/physical_id is the name we rename it to
Returns: boolean
True if all renames succeeded, False otherwise

_TransformFileStorageDir(file_storage_dir)

source code 

Checks whether given file_storage_dir is valid.

Checks wheter the given file_storage_dir is within the cluster-wide default file_storage_dir stored in SimpleStore. Only paths under that directory are allowed.

Parameters:
  • file_storage_dir (str) - the path to check
Returns:
the normalized path if valid, None otherwise

CreateFileStorageDir(file_storage_dir)

source code 

Create file storage directory.

Parameters:
  • file_storage_dir (str) - directory to create
Returns: tuple
tuple with first element a boolean indicating wheter dir creation was successful or not

RemoveFileStorageDir(file_storage_dir)

source code 

Remove file storage directory.

Remove it only if it's empty. If not log an error and return.

Parameters:
  • file_storage_dir (str) - the directory we should cleanup
Returns: tuple (success,)
tuple of one element, success, denoting whether the operation was successful

RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir)

source code 

Rename the file storage directory.

Parameters:
  • old_file_storage_dir (str) - the current path
  • new_file_storage_dir (str) - the name we should rename to
Returns: tuple (success,)
tuple of one element, success, denoting whether the operation was successful

_IsJobQueueFile(file_name)

source code 

Checks whether the given filename is in the queue directory.

Parameters:
  • file_name (str) - the file name we should check
Returns: boolean
whether the file is under the queue directory

JobQueueUpdate(file_name, content)

source code 

Updates a file in the queue directory.

This is just a wrapper over utils.WriteFile, with proper checking.

Parameters:
  • file_name (str) - the job file name
  • content (str) - the new job contents
Returns: boolean
the success of the operation

JobQueueRename(old, new)

source code 

Renames a job queue file.

This is just a wrapper over os.rename with proper checking.

Parameters:
  • old (str) - the old (actual) file name
  • new (str) - the desired file name
Returns: boolean
the success of the operation

JobQueueSetDrainFlag(drain_flag)

source code 

Set the drain flag for the queue.

This will set or unset the queue drain flag.

Parameters:
  • drain_flag (boolean) - if True, will set the drain flag, otherwise reset it.
Returns: boolean
always True

Warning: the function always returns True

BlockdevClose(instance_name, disks)

source code 

Closes the given block devices.

This means they will be switched to secondary mode (in case of DRBD).

Parameters:
  • instance_name - if the argument is not empty, the symlinks of this instance will be removed
  • disks (list of objects.Disk) - the list of disks to be closed
Returns: tuple (success, message)
a tuple of success and message, where success indicates the succes of the operation, and message which will contain the error details in case we failed

ValidateHVParams(hvname, hvparams)

source code 

Validates the given hypervisor parameters.

Parameters:
  • hvname (string) - the hypervisor name
  • hvparams (dict) - the hypervisor parameters to be validated
Returns: tuple (success, message)
a tuple of success and message, where success indicates the succes of the operation, and message which will contain the error details in case we failed