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

Module backend

source code

Functions used by the node daemon

Classes [hide private]
  RPCFail
Class denoting RPC failure.
  HooksRunner
Hook runner.
  IAllocatorRunner
IAllocator runner.
  DevCacheManager
Simple class for managing a cache of block device information.
Functions [hide private]
 
_Fail(msg, *args, **kwargs)
Log an error and the raise an RPCFail exception.
source code
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
tuple
JobQueuePurge()
Removes job queue files and archived jobs.
source code
tuple
GetMasterInfo()
Returns master information.
source code
 
RunLocalHooks(hook_opcode, hooks_path, env_builder_fn)
Decorator that runs hooks before and after the decorated function.
source code
 
_BuildMasterIpEnv(master_params, use_external_mip_script=None)
Builds environment variables for master IP hooks.
source code
 
_RunMasterSetupScript(master_params, action, use_external_mip_script)
Execute the master IP address setup script.
source code
 
ActivateMasterIp(master_params, use_external_mip_script)
Activate the IP address of the master daemon.
source code
None
StartMasterDaemons(no_voting)
Activate local node as master node.
source code
 
DeactivateMasterIp(master_params, use_external_mip_script)
Deactivate the master IP on this node.
source code
None
StopMasterDaemons()
Stop the master daemons on this node.
source code
 
ChangeMasterNetmask(old_netmask, netmask, master_ip, master_netdev)
Change the netmask of the master IP.
source code
 
EtcHostsModify(mode, host, ip)
Modify a host entry in /etc/hosts.
source code
 
LeaveCluster(modify_ssh_setup)
Cleans up and remove the current node.
source code
 
_GetVgInfo(name)
Retrieves information about a LVM volume group.
source code
 
_GetHvInfo(name)
Retrieves node information from a hypervisor.
source code
None or dict
_GetNamedNodeInfo(names, fn)
Calls fn for all names in names and returns a dictionary.
source code
tuple; (string, None/dict, None/dict)
GetNodeInfo(vg_names, hv_names)
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
GetBlockDevSizes(devices)
Return the size of the given block devices
source code
dict
GetVolumeList(vg_names)
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
 
_InstanceLogName(kind, os_name, instance, component)
Compute the OS log filename for a given instance and operation.
source code
None
InstanceOsAdd(instance, reinstall, debug)
Add an OS to an instance.
source code
boolean
RunRenameInstance(instance, old_name, debug)
Run the OS rename script for an instance.
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
None
StartInstance(instance, startup_paused)
Start an instance.
source code
None
InstanceShutdown(instance, timeout)
Shut an instance down.
source code
None
InstanceReboot(instance, reboot_type, shutdown_timeout)
Reboot an instance.
source code
None
InstanceBalloonMemory(instance, memory)
Resize an instance's memory.
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
 
FinalizeMigrationDst(instance, info, success)
Finalize any preparation to accept an instance.
source code
 
MigrateInstance(instance, target, live)
Migrates an instance to another node.
source code
 
FinalizeMigrationSource(instance, success, live)
Finalize the instance migration on the source node.
source code
objects.MigrationStatus
GetMigrationStatus(instance)
Get the migration status
source code
 
BlockdevCreate(disk, size, owner, on_primary, info)
Creates a block device for an instance.
source code
 
_WipeDevice(path, offset, size)
This function actually wipes the device.
source code
 
BlockdevWipe(disk, offset, size)
Wipes a block device.
source code
 
BlockdevPauseResumeSync(disks, pause)
Pause or resume the sync of the block device.
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, idx)
Activate a block device for an instance.
source code
None
BlockdevShutdown(disk)
Shut down a block device.
source code
None
BlockdevAddchildren(parent_cdev, new_cdevs)
Extend a mirrored block device.
source code
None
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
disk
BlockdevGetmirrorstatusMulti(disks)
Get the mirroring status of a list of devices.
source code
 
_RecursiveFindBD(disk)
Check if a device is activated.
source code
 
_OpenRealBD(disk)
Opens the underlying block device of a disk.
source code
None or objects.BlockDevStatus
BlockdevFind(disk)
Check if a device is activated.
source code
list
BlockdevGetsize(disks)
Computes the size of the given disks.
source code
None
BlockdevExport(disk, dest_node, dest_path, cluster_name)
Export a block device to a remote node.
source code
None
UploadFile(file_name, data, mode, uid, gid, atime, mtime)
Write a file to the filesystem.
source code
 
RunOob(oob_program, command, node, timeout)
Executes oob_program with given command on given node.
source code
 
WriteSsconfFiles(values)
Update all ssconf files.
source code
tuple
_OSOndiskAPIVersion(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
tuple
_TryOSFromDisk(name, base_dir=None)
Create an OS instance from disk.
source code
objects.OS
OSFromDisk(name, base_dir=None)
Create an OS instance from disk.
source code
dict
OSCoreEnv(os_name, inst_os, os_params, debug=0)
Calculate the basic environment for an os script.
source code
dict
OSEnvironment(instance, inst_os, debug=0)
Calculate the environment for an os script.
source code
(status, result)
BlockdevGrow(disk, amount, dryrun)
Grow a stack of block devices.
source code
string
BlockdevSnapshot(disk)
Create a snapshot copy of a block device.
source code
None
FinalizeExport(instance, snap_disks)
Write out the export configuration information.
source code
objects.SerializableConfigParser
ExportInfo(dest)
Get export configuration information.
source code
list
ListExports()
Return a list of exports currently available on this machine.
source code
None
RemoveExport(export)
Remove an existing export from the node.
source code
boolean
BlockdevRename(devlist)
Rename a list of block devices.
source code
 
_TransformFileStorageDir(fs_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
None
_EnsureJobQueueFile(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
tuple
JobQueueRename(old, new)
Renames a job queue file.
source code
tuple (success, message)
BlockdevClose(instance_name, disks)
Closes the given block devices.
source code
None
ValidateHVParams(hvname, hvparams)
Validates the given hypervisor parameters.
source code
 
_CheckOSPList(os_obj, parameters)
Check whether a list of parameters is supported by the OS.
source code
boolean
ValidateOS(required, osname, checks, osparams)
Validate the given OS' parameters.
source code
 
DemoteFromMC()
Demotes the current node from master candidate role.
source code
 
_GetX509Filenames(cryptodir, name)
Returns the full paths for the private key and certificate.
source code
tuple; (string, string)
CreateX509Certificate(validity, cryptodir=constants.CRYPTO_KEYS_DIR)
Creates a new X509 certificate for SSL/TLS.
source code
 
RemoveX509Certificate(name, cryptodir=constants.CRYPTO_KEYS_DIR)
Removes a X509 certificate.
source code
 
_GetImportExportIoCommand(instance, mode, ieio, ieargs)
Returns the command for the requested input/output.
source code
 
_CreateImportExportStatusDir(prefix)
Creates status directory for import/export.
source code
 
StartImportExportDaemon(mode, opts, host, port, instance, component, ieio, ieioargs)
Starts an import or export daemon.
source code
List of dicts
GetImportExportStatus(names)
Returns import/export daemon status.
source code
 
AbortImportExport(name)
Sends SIGTERM to a running import/export daemon.
source code
 
CleanupImportExport(name)
Cleanup after an import or export.
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
 
GetDrbdUsermodeHelper()
Returns DRBD usermode helper currently configured.
source code
 
PowercycleNode(hypervisor_type)
Hard-powercycle the node.
source code
Variables [hide private]
  _BOOT_ID_PATH = "/proc/sys/kernel/random/boot_id"
  _ALLOWED_CLEAN_DIRS = frozenset([constants.DATA_DIR, constants...
denotes which directories are accepted in the _CleanDirectory function
  _MAX_SSL_CERT_VALIDITY = 7* 24* 60* 60
  _X509_KEY_FILE = "key"
  _X509_CERT_FILE = "cert"
  _IES_STATUS_FILE = "status"
  _IES_PID_FILE = "pid"
  _IES_CA_FILE = "ca"
  _LVSLINE_REGEX = re.compile("^ *([^|]+)\|([^|]+)\|([0-9.]+)\|(...
Valid LVS output line regex
  _MASTER_START = "start"
  _MASTER_STOP = "stop"
  _ALLOWED_UPLOAD_FILES = _BuildUploadFileList()
denotes which files are accepted in the UploadFile function

Imports: os, shutil, time, stat, errno, re, random, logging, tempfile, zlib, base64, signal, errors, utils, ssh, hypervisor, constants, bdev, objects, ssconf, serializer, netutils, runtime, mcpu, compat


Function Details [hide private]

_Fail(msg, *args, **kwargs)

source code 

Log an error and the raise an RPCFail exception.

This exception is then handled specially in the ganeti daemon and turned into a 'failed' return type. As such, this function is a useful shortcut for logging the error and returning it to the master daemon.

Parameters:
  • msg (string) - the text of the exception @raise RPCFail

_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.

JobQueuePurge()

source code 

Removes job queue files and archived jobs.

Returns: tuple
True, None

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, primary_ip_family, master_netmask
Raises:

RunLocalHooks(hook_opcode, hooks_path, env_builder_fn)

source code 

Decorator that runs hooks before and after the decorated function.

Parameters:
  • hook_opcode (string) - opcode of the hook
  • hooks_path (string) - path of the hooks
  • env_builder_fn (function) - function that returns a dictionary containing the environment variables for the hooks. Will get all the parameters of the decorated function.
Raises:
  • RPCFail - in case of pre-hook failure

_BuildMasterIpEnv(master_params, use_external_mip_script=None)

source code 

Builds environment variables for master IP hooks.

Parameters:
  • master_params (objects.MasterNetworkParameters) - network parameters of the master
  • use_external_mip_script (boolean) - whether to use an external master IP address setup script (unused, but necessary per the implementation of the _RunLocalHooks decorator)

_RunMasterSetupScript(master_params, action, use_external_mip_script)

source code 

Execute the master IP address setup script.

Parameters:
Raises:

ActivateMasterIp(master_params, use_external_mip_script)

source code 

Activate the IP address of the master daemon.

Parameters:
  • master_params (objects.MasterNetworkParameters) - network parameters of the master
  • use_external_mip_script (boolean) - whether to use an external master IP address setup script
Decorators:
  • @RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup", _BuildMasterIpEnv)
Raises:
  • RPCFail - in case of errors during the IP startup

StartMasterDaemons(no_voting)

source code 

Activate local node as master node.

The function will start the master daemons (ganeti-masterd and ganeti-rapi).

Parameters:
  • no_voting (boolean) - whether to start ganeti-masterd without a node vote but still non-interactively
Returns: None

DeactivateMasterIp(master_params, use_external_mip_script)

source code 

Deactivate the master IP on this node.

Parameters:
  • master_params (objects.MasterNetworkParameters) - network parameters of the master
  • use_external_mip_script (boolean) - whether to use an external master IP address setup script
Decorators:
  • @RunLocalHooks(constants.FAKE_OP_MASTER_TURNDOWN, "master-ip-turndown", _BuildMasterIpEnv)
Raises:
  • RPCFail - in case of errors during the IP turndown

StopMasterDaemons()

source code 

Stop the master daemons on this node.

Stop the master daemons (ganeti-masterd and ganeti-rapi) on this node.

Returns: None

ChangeMasterNetmask(old_netmask, netmask, master_ip, master_netdev)

source code 

Change the netmask of the master IP.

Parameters:
  • old_netmask - the old value of the netmask
  • netmask - the new value of the netmask
  • master_ip - the master IP
  • master_netdev - the master network device

EtcHostsModify(mode, host, ip)

source code 

Modify a host entry in /etc/hosts.

Parameters:
  • mode - The mode to operate. Either add or remove entry
  • host - The host to operate on
  • ip - The ip associated with the entry

LeaveCluster(modify_ssh_setup)

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.

Parameters:
  • modify_ssh_setup - boolean

_GetHvInfo(name)

source code 

Retrieves node information from a hypervisor.

The information returned depends on the hypervisor. Common items:

  • 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
  • hv_version: the hypervisor version, if available

GetNodeInfo(vg_names, hv_names)

source code 

Gives back a hash with different information about the node.

Parameters:
  • vg_names (list of string) - Names of the volume groups to ask for disk space information
  • hv_names (list of string) - Names of the hypervisors to ask for node information
Returns: tuple; (string, None/dict, None/dict)
Tuple containing boot ID, volume group information and hypervisor information

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

GetBlockDevSizes(devices)

source code 

Return the size of the given block devices

Parameters:
  • devices (list) - list of block device nodes to query
Returns: dict
dictionary of all block devices under /dev (key). The value is their size in MiB.

{'/dev/disk/by-uuid/123456-12321231-312312-312': 124}

GetVolumeList(vg_names)

source code 

Compute list of logical volumes and their size.

Parameters:
  • vg_names (list) - the volume groups whose LVs we should list, or empty for all volume groups
Returns: dict
dictionary of all partions (key) with value being a tuple of their size (in MiB), inactive and online status:
 {'xenvg/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

_InstanceLogName(kind, os_name, instance, component)

source code 

Compute the OS log filename for a given instance and operation.

The instance name and os name are passed in as strings since not all operations have these as part of an instance object.

Parameters:
  • kind (string) - the operation type (e.g. add, import, etc.)
  • os_name (string) - the os name
  • instance (string) - the name of the instance being imported/added/etc.
  • component (string or None) - the name of the component of the instance being transferred

InstanceOsAdd(instance, reinstall, debug)

source code 

Add an OS to an instance.

Parameters:
  • instance (objects.Instance) - Instance whose OS is to be installed
  • reinstall (boolean) - whether this is an instance reinstall
  • debug (integer) - debug level, passed to the OS scripts
Returns: None

RunRenameInstance(instance, old_name, debug)

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
  • debug (integer) - debug level, passed to the OS scripts
Returns: boolean
the success of the operation

_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, startup_paused)

source code 

Start an instance.

Parameters:
Returns: None

InstanceShutdown(instance, timeout)

source code 

Shut an instance down.

Parameters:
  • instance (objects.Instance) - the instance object
  • timeout (integer) - maximum timeout for soft shutdown
Returns: None

Note: this functions uses polling with a hardcoded timeout.

InstanceReboot(instance, reboot_type, shutdown_timeout)

source code 

Reboot an instance.

Parameters:
  • instance (objects.Instance) - the instance object to reboot
  • reboot_type (str) - the type of reboot, one the following constants:
  • shutdown_timeout (integer) - maximum timeout for soft shutdown
Returns: None

InstanceBalloonMemory(instance, memory)

source code 

Resize an instance's memory.

Parameters:
  • instance (objects.Instance) - the instance object
  • memory (int) - new memory amount in MB
Returns: None

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

FinalizeMigrationDst(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)
Raises:
  • RPCFail - if migration fails for some reason

FinalizeMigrationSource(instance, success, live)

source code 

Finalize the instance migration on the source node.

Parameters:
  • instance (objects.Instance) - the instance definition of the migrated instance
  • success (bool) - whether the migration succeeded or not
  • live (bool) - whether the user requested a live migration or not
Raises:
  • RPCFail - If the execution fails for some reason

GetMigrationStatus(instance)

source code 

Get the migration status

Parameters:
Returns: objects.MigrationStatus
the status of the current migration (one of constants.HV_MIGRATION_VALID_STATUSES), plus any additional progress info that can be retrieved from the hypervisor
Raises:
  • RPCFail - If the migration status cannot be retrieved

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.

_WipeDevice(path, offset, size)

source code 

This function actually wipes the device.

Parameters:
  • path - The path to the device to wipe
  • offset - The offset in MiB in the file
  • size - The size in MiB to write

BlockdevWipe(disk, offset, size)

source code 

Wipes a block device.

Parameters:
  • disk (objects.Disk) - the disk object we want to wipe
  • offset (int) - The offset in MiB in the file
  • size (int) - The size in MiB to write

BlockdevPauseResumeSync(disks, pause)

source code 

Pause or resume the sync of the block device.

Parameters:
  • disks (list of objects.Disk) - the disks object we want to pause/resume
  • pause (bool) - Wheater to pause or resume

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, idx)

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: None

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: None

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: None

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
List of objects.BlockDevStatus, one for each disk
Raises:

BlockdevGetmirrorstatusMulti(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
List of tuples, (bool, status), one for each disk; bool denotes success/failure, status is objects.BlockDevStatus on success, string otherwise

_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

_OpenRealBD(disk)

source code 

Opens the underlying block device of a disk.

Parameters:

BlockdevFind(disk)

source code 

Check if a device is activated.

If it is, return information about the real device.

Parameters:
Returns: None or objects.BlockDevStatus
None if the disk cannot be found, otherwise a the current information

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

BlockdevExport(disk, dest_node, dest_path, cluster_name)

source code 

Export a block device to a remote node.

Parameters:
  • disk (objects.Disk) - the description of the disk to export
  • dest_node (str) - the destination node to export to
  • dest_path (str) - the destination path on the target node
  • cluster_name (str) - the cluster name, needed for SSH hostalias
Returns: None

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 (string) - the owner of the file
  • gid (string) - the group of the file
  • 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: None

RunOob(oob_program, command, node, timeout)

source code 

Executes oob_program with given command on given node.

Parameters:
  • oob_program - The path to the executable oob_program
  • command - The command to invoke on oob_program
  • node - The node given as an argument to the program
  • timeout - Timeout after which we kill the oob program
Returns:
stdout
Raises:
  • RPCFail - If execution fails for some reason

WriteSsconfFiles(values)

source code 

Update all ssconf files.

Wrapper around the SimpleStore.WriteFiles.

_OSOndiskAPIVersion(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 residing in the 'os_dir' directory.

Parameters:
  • os_dir (str) - the directory in which we should look for the OS
Returns: tuple
tuple (status, data) with status denoting the validity and data holding either the vaid versions or an error message

DiagnoseOS(top_dirs=None)

source code 

Compute the validity for all OSes.

Parameters:
Returns: list of objects.OS
a list of tuples (name, path, status, diagnose, variants, parameters, api_version) for all (potential) OSes under all search paths, where:
  • name is the (potential) OS name
  • path is the full path to the OS
  • status True/False is the validity of the OS
  • diagnose is the error message for an invalid OS, otherwise empty
  • variants is a list of supported OS variants, if any
  • parameters is a list of (name, help) parameters, if any
  • api_version is a list of support OS API versions

_TryOSFromDisk(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.

Parameters:
  • base_dir (string) - Base directory containing OS installations. Defaults to a search in all the OS_SEARCH_PATH dirs.
Returns: tuple
success and either the OS instance if we find a valid one, or error message

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 RPCFail exception, detailing why this is not a valid OS.

This is just a wrapper over _TryOSFromDisk, which doesn't raise an exception but returns true/false status data.

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:
  • RPCFail - if we don't find a valid OS

OSCoreEnv(os_name, inst_os, os_params, debug=0)

source code 

Calculate the basic environment for an os script.

Parameters:
  • os_name (str) - full operating system name (including variant)
  • inst_os (objects.OS) - operating system for which the environment is being built
  • os_params (dict) - the OS parameters
  • debug (integer) - debug level (0 or 1, for OS Api 10)
Returns: dict
dict of environment variables
Raises:

OSEnvironment(instance, inst_os, debug=0)

source code 

Calculate the environment for an os script.

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

BlockdevGrow(disk, amount, dryrun)

source code 

Grow a stack of block devices.

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

Parameters:
  • disk (objects.Disk) - the disk to be grown
  • amount (integer) - the amount (in mebibytes) to grow with
  • dryrun (boolean) - whether to execute the operation in simulation mode only, without actually increasing the size
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 ID as (vg, lv)

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: None

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

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: None

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(fs_dir)

source code 

Checks whether given file_storage_dir is valid.

Checks wheter the given fs_dir is within the cluster-wide default file_storage_dir or the shared_file_storage_dir, which are stored in SimpleStore. Only paths under those directories are allowed.

Parameters:
  • fs_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

_EnsureJobQueueFile(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: None
Raises:
  • RPCFail - if the file is not valid

JobQueueUpdate(file_name, content)

source code 

Updates a file in the queue directory.

This is just a wrapper over utils.io.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: tuple
the success of the operation and payload

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: None

_CheckOSPList(os_obj, parameters)

source code 

Check whether a list of parameters is supported by the OS.

Parameters:
  • os_obj (objects.OS) - OS object to check
  • parameters (list) - the list of parameters to check

ValidateOS(required, osname, checks, osparams)

source code 

Validate the given OS' parameters.

Parameters:
  • required (boolean) - whether absence of the OS should translate into failure or not
  • osname (string) - the OS to be validated
  • checks (list) - list of the checks to run (currently only 'parameters')
  • osparams (dict) - dictionary with OS parameters
Returns: boolean
True if the validation passed, or False if the OS was not found and required was false

CreateX509Certificate(validity, cryptodir=constants.CRYPTO_KEYS_DIR)

source code 

Creates a new X509 certificate for SSL/TLS.

Parameters:
  • validity (int) - Validity in seconds
Returns: tuple; (string, string)
Certificate name and public part

RemoveX509Certificate(name, cryptodir=constants.CRYPTO_KEYS_DIR)

source code 

Removes a X509 certificate.

Parameters:
  • name (string) - Certificate name

_GetImportExportIoCommand(instance, mode, ieio, ieargs)

source code 

Returns the command for the requested input/output.

Parameters:
  • instance (objects.Instance) - The instance object
  • mode - Import/export mode
  • ieio - Input/output type
  • ieargs - Input/output arguments

StartImportExportDaemon(mode, opts, host, port, instance, component, ieio, ieioargs)

source code 

Starts an import or export daemon.

Parameters:
  • mode - Import/output mode
  • opts (objects.ImportExportOptions) - Daemon options
  • host (string) - Remote host for export (None for import)
  • port (int) - Remote port for export (None for import)
  • instance (objects.Instance) - Instance object
  • component (string) - which part of the instance is transferred now, e.g. 'disk/0'
  • ieio - Input/output type
  • ieioargs - Input/output arguments

GetImportExportStatus(names)

source code 

Returns import/export daemon status.

Parameters:
  • names (sequence) - List of names
Returns: List of dicts
Returns a list of the state of each named import/export or None if a status couldn't be read

CleanupImportExport(name)

source code 

Cleanup after an import or export.

If the import/export daemon is still running it's killed. Afterwards the whole status directory is removed.

PowercycleNode(hypervisor_type)

source code 

Hard-powercycle the node.

Because we need to return first, and schedule the powercycle in the background, we won't be able to report failures nicely.


Variables Details [hide private]

_ALLOWED_CLEAN_DIRS

denotes which directories are accepted in the _CleanDirectory function
Value:
frozenset([constants.DATA_DIR, constants.JOB_QUEUE_ARCHIVE_DIR, consta\
nts.QUEUE_DIR, constants.CRYPTO_KEYS_DIR,])

_LVSLINE_REGEX

Valid LVS output line regex

Value:
re.compile("^ *([^|]+)\|([^|]+)\|([0-9.]+)\|([^|]{6,})\|?$")