module documentation

Functions used by the node daemon

Class DevCacheManager Simple class for managing a cache of block device information.
Class HooksRunner Hook runner.
Class IAllocatorRunner IAllocator runner.
Exception RPCFail Class denoting RPC failure.
Function AbortImportExport Sends SIGTERM to a running import/export daemon.
Function AcceptInstance Prepare the node to accept an instance.
Function ActivateMasterIp Activate the IP address of the master daemon.
Function AddNodeSshKey Distributes a node's public SSH key across the cluster.
Function AddNodeSshKeyBulk Distributes a node's public SSH key across the cluster.
Function BlockdevAddchildren Extend a mirrored block device.
Function BlockdevAssemble Activate a block device for an instance.
Function BlockdevClose Closes the given block devices.
Function BlockdevConvert Copies data from source block device to target.
Function BlockdevCreate Creates a block device for an instance.
Function BlockdevFind Check if a device is activated.
Function BlockdevGetdimensions Computes the size of the given disks.
Function BlockdevGetmirrorstatus Get the mirroring status of a list of devices.
Function BlockdevGetmirrorstatusMulti Get the mirroring status of a list of devices.
Function BlockdevGrow Grow a stack of block devices.
Function BlockdevImage Images a block device either by dumping a local file or downloading a URL.
Function BlockdevOpen Opens the given block devices.
Function BlockdevPauseResumeSync Pause or resume the sync of the block device.
Function BlockdevRemove Remove a block device.
Function BlockdevRemovechildren Shrink a mirrored block device.
Function BlockdevRename Rename a list of block devices.
Function BlockdevSetInfo Sets 'metadata' information on block devices.
Function BlockdevShutdown Shut down a block device.
Function BlockdevSnapshot Create a snapshot copy of a block device.
Function BlockdevWipe Wipes a block device.
Function BridgesExist Check if a list of bridges exist on the current node.
Function ChangeMasterNetmask Change the netmask of the master IP.
Function CleanupImportExport Cleanup after an import or export.
Function ConfigureOVS Creates a OpenvSwitch on the node.
Function CreateFileStorageDir Create file storage directory.
Function CreateX509Certificate Creates a new X509 certificate for SSL/TLS.
Function DeactivateMasterIp Deactivate the master IP on this node.
Function DemoteFromMC Demotes the current node from master candidate role.
Function DiagnoseExtStorage Compute the validity for all ExtStorage Providers.
Function DiagnoseOS Compute the validity for all OSes.
Function DrbdAttachNet Attaches the network on a list of drbd devices.
Function DrbdDisconnectNet Disconnects the network on a list of drbd devices.
Function DrbdNeedsActivation Checks which of the passed disks needs activation and returns their UUIDs.
Function DrbdWaitSync Wait until DRBDs have synchronized.
Function EnsureDaemon Ensures the given daemon is running or stopped.
Function EtcHostsModify Modify a host entry in /etc/hosts.
Function ExportInfo Get export configuration information.
Function ExportOS Creates a GZIPed tarball with an OS definition and environment.
Function FinalizeExport Write out the export configuration information.
Function FinalizeMigrationDst Finalize any preparation to accept an instance.
Function FinalizeMigrationSource Finalize the instance migration on the source node.
Function GetAllInstancesInfo Gather data about all instances.
Function GetBlockDevSizes Return the size of the given block devices
Function GetCryptoTokens Perform actions on the node's cryptographic tokens.
Function GetDrbdUsermodeHelper Returns DRBD usermode helper currently configured.
Function GetFileInfo Checks if a file exists and returns information related to it.
Function GetImportExportStatus Returns import/export daemon status.
Function GetInstanceConsoleInfo Gather data about the console access of a set of instances of this node.
Function GetInstanceInfo Gives back the information about an instance as a dictionary.
Function GetInstanceList Provides a list of instances.
Function GetInstanceListForHypervisor Provides a list of instances of the given hypervisor.
Function GetInstanceMigratable Computes whether an instance can be migrated.
Function GetMasterNodeName Returns the master node name.
Function GetMigrationStatus Get the migration status
Function GetNodeInfo Gives back a hash with different information about the node.
Function GetVolumeList Compute list of logical volumes and their size.
Function HotplugDevice Hotplug a device
Function HotplugSupported Checks if hotplug is generally supported.
Function InstanceBalloonMemory Resize an instance's memory.
Function InstanceOsAdd Add an OS to an instance.
Function InstanceReboot Reboot an instance.
Function InstanceShutdown Shut an instance down.
Function JobQueuePurge Removes job queue files and archived jobs.
Function JobQueueRename Renames a job queue file.
Function JobQueueUpdate Updates a file in the queue directory.
Function LeaveCluster Cleans up and remove the current node.
Function ListExports Return a list of exports currently available on this machine.
Function ListVolumeGroups List the volume groups and their size.
Function MigrateInstance Migrates an instance to another node.
Function MigrationInfo Gather information about an instance to be migrated.
Function ModifyInstanceMetadata Sends instance data to the metadata daemon.
Function NodeVolumes List all volumes on this node.
Function OSCoreEnv Calculate the basic environment for an os script.
Function OSEnvironment Calculate the environment for an os script.
Function OSFromDisk Create an OS instance from disk.
Function PowercycleNode Hard-powercycle the node.
Function RemoveExport Remove an existing export from the node.
Function RemoveFileStorageDir Remove file storage directory.
Function RemoveNodeSshKey Removes the node's SSH keys from the key files and distributes those.
Function RemoveNodeSshKeyBulk Removes the node's SSH keys from the key files and distributes those.
Function RemoveX509Certificate Removes a X509 certificate.
Function RenameFileStorageDir Rename the file storage directory.
Function RenewSshKeys Renews all SSH keys and updates authorized_keys and ganeti_pub_keys.
Function RunLocalHooks Decorator that runs hooks before and after the decorated function.
Function RunOob Executes oob_program with given command on given node.
Function RunRenameInstance Run the OS rename script for an instance.
Function RunRestrictedCmd Executes a restricted command after performing strict tests.
Function SetWatcherPause Creates or removes the watcher pause file.
Function StartImportExportDaemon Starts an import or export daemon.
Function StartInstance Start an instance.
Function StartMasterDaemons Activate local node as master node.
Function StopMasterDaemons Stop the master daemons on this node.
Function UploadFile Write a file to the filesystem.
Function ValidateHVParams Validates the given hypervisor parameters.
Function ValidateOS Validate the given OS parameters.
Function VerifyMasterIP Verify master IP is reachable.
Function VerifyNode Verify the status of the local node.
Function VerifyNodeNetTest Verify nodes are reachable.
Variable SshAddNodeInfo Undocumented
Variable SshRemoveNodeInfo Undocumented
Function _ApplyStorageInfoFunction Looks up and applies the correct function to calculate free and total storage for the given storage type.
Function _BuildMasterIpEnv Builds environment variables for master IP hooks.
Function _BuildUploadFileList Build the list of allowed upload files.
Function _CalculateDeviceURI Get the URI for the device.
Function _CheckExclusivePvs Check that PVs are not shared among LVs
Function _CheckForPlainDisk Check within a disk and its children if there is a plain disk type.
Function _CheckLvmStorageParams Performs sanity check for the 'exclusive storage' flag.
Function _CheckOSPList Check whether a list of parameters is supported by the OS.
Function _CheckOSVariant Check whether an OS name conforms to the os variants specification.
Function _CheckStorageParams Performs sanity checks for storage parameters.
Function _CleanDirectory Removes all regular files in a directory.
Function _CommonRestrictedCmdCheck Common checks for restricted command file system directories and files.
Function _CreateImportExportStatusDir Creates status directory for import/export.
Function _Decompress Unpacks data compressed by the RPC client.
Function _DownloadAndDumpDevice This function images a device using a downloaded image file.
Function _DumpDevice This function images/wipes the device using a local file.
Function _EnsureJobQueueFile Checks whether the given filename is in the queue directory.
Function _Fail Log an error and the raise an RPCFail exception.
Function _FindDisks Finds attached BlockDevs for the given disks.
Function _GatherAndLinkBlockDevs Set up an instance's block device(s).
Function _GenerateNodeSshKey Generates the root SSH key pair on the node.
Function _GetBlockDevSymlinkPath Returns symlink path for block device.
Function _GetConfig Simple wrapper to return a SimpleStore.
Function _GetFileStorageSpaceInfo Wrapper around filestorage.GetSpaceInfo.
Function _GetHvInfo Retrieves node information from a hypervisor.
Function _GetHvInfoAll Retrieves node information for all hypervisors.
Function _GetImportExportIoCommand Returns the command for the requested input/output.
Function _GetInstanceInfo Helper function GetInstanceInfo
Function _GetInstReasonFilename Path of the file containing the reason of the instance status change.
Function _GetLvmPvSpaceInfo Wrapper around _GetVgSpindlesInfo with sanity checks.
Function _GetLvmVgSpaceInfo Wrapper around _GetVgInfo which checks the storage parameters.
Function _GetMasterNodeUUID Undocumented
Function _GetNamedNodeInfo Calls fn for all names in names and returns a list of dictionaries.
Function _GetNewMasterKey Undocumented
Function _GetOldMasterKeys Undocumented
Function _GetSshRunner Simple wrapper to return an SshRunner.
Function _GetVgInfo Retrieves information about a LVM volume group.
Function _GetVgSpindlesInfo Retrieves information about spindles in an LVM volume group.
Function _GetX509Filenames Returns the full paths for the private key and certificate.
Function _InitSshUpdateData Undocumented
Function _InstanceLogName Compute the OS log filename for a given instance and operation.
Function _IsInstanceUserDown Undocumented
Function _OpenRealBD Opens the underlying block device of a disk.
Function _OSOndiskAPIVersion Compute and return the API version of a given OS.
Function _PrepareRestrictedCmd Performs a number of tests on a restricted command.
Function _RecursiveAssembleBD Activate a block device for an instance.
Function _RecursiveFindBD Check if a device is activated.
Function _RemoveBlockDevLinks Remove the block device symlinks belonging to the given instance.
Function _ReplaceMasterKeyOnMaster Undocumented
Function _RunMasterSetupScript Execute the master IP address setup script.
Function _StoreInstReasonTrail Serialize a reason trail related to an instance change of state to file.
Function _SymlinkBlockDev Set up symlinks to a instance's block device.
Function _TransformFileStorageDir Checks whether given file_storage_dir is valid.
Function _TryOSFromDisk Create an OS instance from disk.
Function _VerifyClientCertificate Verify the existance and validity of the client SSL certificate.
Function _VerifyHvparams Verifies the hvparams. Appends the results to the 'results' list.
Function _VerifyHypervisors Verifies the hypervisor. Appends the results to the 'results' list.
Function _VerifyInstanceList Verifies the instance list.
Function _VerifyNodeInfo Verifies the node info.
Function _VerifyRestrictedCmd Verifies a whole restricted command and returns its executable filename.
Function _VerifyRestrictedCmdDirectory Verifies restricted command directory.
Function _VerifyRestrictedCmdName Verifies a restricted command name.
Function _VerifySshClutter Verifies that the 'authorized_keys' files are not cluttered up.
Function _VerifySshSetup Verifies the state of the SSH key files.
Constant _ALLOWED_CLEAN_DIRS denotes which directories are accepted in the _CleanDirectory function
Constant _ALLOWED_UPLOAD_FILES denotes which files are accepted in the UploadFile function
Constant _BOOT_ID_PATH Undocumented
Constant _IES_CA_FILE Undocumented
Constant _IES_PID_FILE Undocumented
Constant _IES_STATUS_FILE Undocumented
Constant _LVSLINE_REGEX Undocumented
Constant _MASTER_START Undocumented
Constant _MASTER_STOP Undocumented
Constant _MAX_SSL_CERT_VALIDITY Undocumented
Constant _RCMD_INVALID_DELAY Undocumented
Constant _RCMD_LOCK_TIMEOUT Undocumented
Constant _RCMD_MAX_MODE Undocumented
Constant _STORAGE_TYPE_INFO_FN Undocumented
Constant _X509_CERT_FILE Undocumented
Constant _X509_KEY_FILE Undocumented
def AbortImportExport(name):

Sends SIGTERM to a running import/export daemon.

def AcceptInstance(instance, info, target):

Prepare the node to accept an instance.

Parameters
instance:objects.Instancethe instance definition
info:string/data (opaque)migration information, from the source node
target:stringtarget host (usually ip), on this node
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, 'master-ip-turnup', _BuildMasterIpEnv)
def ActivateMasterIp(master_params, use_external_mip_script):

Activate the IP address of the master daemon.

Parameters
master_params:objects.MasterNetworkParametersnetwork parameters of the master
use_external_mip_script:booleanwhether to use an external master IP address setup script
Raises
RPCFailin case of errors during the IP startup
def AddNodeSshKey(node_uuid, node_name, potential_master_candidates, to_authorized_keys=False, to_public_keys=False, get_public_keys=False, pub_key_file=pathutils.SSH_PUB_KEYS, ssconf_store=None, noded_cert_file=pathutils.NODED_CERT_FILE, run_cmd_fn=ssh.RunSshCmdWithStdin):

Distributes a node's public SSH key across the cluster.

Note that this function should only be executed on the master node, which then will copy the new node's key to all nodes in the cluster via SSH.

Also note: at least one of the flags to_authorized_keys, to_public_keys, and get_public_keys has to be set to True for the function to actually perform any actions.

Parameters
node_uuid:strthe UUID of the node whose key is added
node_name:strthe name of the node whose key is added
potential_master_candidates:list of strlist of node names of potential master candidates; this should match the list of uuids in the public key file
to_authorized_keys:booleanwhether the key should be added to the authorized_keys file of all nodes
to_public_keys:booleanwhether the keys should be added to the public key file
get_public_keys:booleanwhether the node should add the clusters' public keys to its {ganeti_pub_keys} file
pub_key_fileUndocumented
ssconf_storeUndocumented
noded_cert_fileUndocumented
run_cmd_fnUndocumented
def AddNodeSshKeyBulk(node_list, potential_master_candidates, pub_key_file=pathutils.SSH_PUB_KEYS, ssconf_store=None, noded_cert_file=pathutils.NODED_CERT_FILE, run_cmd_fn=ssh.RunSshCmdWithStdin):

Distributes a node's public SSH key across the cluster.

Note that this function should only be executed on the master node, which then will copy the new node's key to all nodes in the cluster via SSH.

Also note: at least one of the flags to_authorized_keys, to_public_keys, and get_public_keys has to be set to True for the function to actually perform any actions.

Parameters
node_list:list of SshAddNodeInfo tupleslist of tuples containing the necessary node information for adding their keys
potential_master_candidates:list of strlist of node names of potential master candidates; this should match the list of uuids in the public key file
pub_key_fileUndocumented
ssconf_storeUndocumented
noded_cert_fileUndocumented
run_cmd_fnUndocumented
def BlockdevAddchildren(parent_cdev, new_cdevs):

Extend a mirrored block device.

Parameters
parent_cdev:objects.Diskthe disk to which we should add children
new_cdevs:list of objects.Diskthe list of children which we should add
Returns
NoneUndocumented
def BlockdevAssemble(disk, instance, as_primary, idx):

Activate a block device for an instance.

This is a wrapper over _RecursiveAssembleBD.

Returns
str or booleana tuple with the /dev/... path and the created symlink for primary nodes, and (True, True) for secondary nodes
def BlockdevClose(instance_name, disks):

Closes the given block devices.

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

Parameters
instance_nameif the argument is not empty, the symlinks of this instance will be removed
disks:list of objects.Diskthe 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
def BlockdevConvert(src_disk, target_disk):

Copies data from source block device to target.

This function gets the export and import commands from the source and target devices respectively, and then concatenates them to a single command using a pipe ("|"). Finally, executes the unified command that will transfer the data between the devices during the disk template conversion operation.

Parameters
src_disk:objects.Diskthe disk object we want to copy from
target_disk:objects.Diskthe disk object we want to copy to
Returns
NoneTypeNone
Raises
RPCFailin case of failure
def BlockdevCreate(disk, size, owner, on_primary, info, excl_stor):

Creates a block device for an instance.

Parameters
disk:objects.Diskthe object describing the disk we should create
size:intthe size of the physical underlying device, in MiB
owner:strthe name of the instance for which disk is created, used for device cache data
on_primary:booleanindicates if it is the primary node or not
info:stringstring that will be sent to the physical device creation, used for example to set (LVM) tags on LVs
excl_stor:booleanWhether exclusive_storage is active
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.
def BlockdevFind(disk):

Check if a device is activated.

If it is, return information about the real device.

Parameters
disk:objects.Diskthe disk to find
Returns
None or objects.BlockDevStatusNone if the disk cannot be found, otherwise a the current information
def BlockdevGetdimensions(disks):

Computes the size of the given disks.

If a disk is not found, returns None instead.

Parameters
disks:list of objects.Diskthe list of disk to compute the size for
Returns
listlist with elements None if the disk cannot be found, otherwise the pair (size, spindles), where spindles is None if the device doesn't support that
def BlockdevGetmirrorstatus(disks):

Get the mirroring status of a list of devices.

Parameters
disks:list of objects.Diskthe list of disks which we should query
Returns
diskList of objects.BlockDevStatus, one for each disk
Raises
errors.BlockDeviceErrorif any of the disks cannot be found
def BlockdevGetmirrorstatusMulti(disks):

Get the mirroring status of a list of devices.

Parameters
disks:list of objects.Diskthe list of disks which we should query
Returns
diskList of tuples, (bool, status), one for each disk; bool denotes success/failure, status is objects.BlockDevStatus on success, string otherwise
def BlockdevGrow(disk, amount, dryrun, backingstore, excl_stor):

Grow a stack of block devices.

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

Parameters
disk:objects.Diskthe disk to be grown
amount:integerthe amount (in mebibytes) to grow with
dryrun:booleanwhether to execute the operation in simulation mode only, without actually increasing the size
backingstorewhether to execute the operation on backing storage only, or on "logical" storage only; e.g. DRBD is logical storage, whereas LVM, file, RBD are backing storage
excl_stor:booleanWhether exclusive_storage is active
Returns
(status, result)a tuple with the status of the operation (True/False), and the errors message if status is False
def BlockdevImage(disk, image, size):

Images a block device either by dumping a local file or downloading a URL.

Parameters
disk:objects.Diskthe disk object we want to image
image:stringfile path to the disk image be dumped
size:intThe size in MiB to write
Returns
NoneTypeNone
Raises
RPCFailin case of failure
def BlockdevOpen(instance_name, disks, exclusive):

Opens the given block devices.

def BlockdevPauseResumeSync(disks, pause):

Pause or resume the sync of the block device.

Parameters
disks:list of objects.Diskthe disks object we want to pause/resume
pause:boolWheater to pause or resume
def BlockdevRemove(disk):

Remove a block device.

Parameters
disk:objects.Diskthe disk object we should remove
Returns
booleanthe success of the operation
Note
This is intended to be called recursively.
def BlockdevRemovechildren(parent_cdev, new_cdevs):

Shrink a mirrored block device.

Parameters
parent_cdev:objects.Diskthe disk from which we should remove children
new_cdevs:list of objects.Diskthe list of children which we should remove
Returns
NoneUndocumented
def BlockdevRename(devlist):

Rename a list of block devices.

Parameters
devlist:list of tupleslist of tuples of the form (disk, new_unique_id); disk is an objects.Disk object describing the current disk, and new unique_id is the name we rename it to
Returns
booleanTrue if all renames succeeded, False otherwise
def BlockdevSetInfo(disk, info):

Sets 'metadata' information on block devices.

This function sets 'info' metadata on block devices. Initial information is set at device creation; this function should be used for example after renames.

Parameters
disk:objects.Diskthe disk to be grown
info:stringnew 'info' metadata
Returns
(status, result)a tuple with the status of the operation (True/False), and the errors message if status is False
def BlockdevShutdown(disk):

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.Diskthe description of the disk we should shutdown
Returns
NoneUndocumented
def BlockdevSnapshot(disk, snap_name, snap_size):

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
disk:objects.Diskthe disk to be snapshotted
snap_name:stringthe name of the snapshot
snap_size:intthe size of the snapshot
Returns
stringsnapshot disk ID as (vg, lv)
def BlockdevWipe(disk, offset, size):

Wipes a block device.

Parameters
disk:objects.Diskthe disk object we want to wipe
offset:intThe offset in MiB in the file
size:intThe size in MiB to write
def BridgesExist(bridges_list):

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

Returns
booleanTrue if all of them exist, False otherwise
def ChangeMasterNetmask(old_netmask, netmask, master_ip, master_netdev):

Change the netmask of the master IP.

Parameters
old_netmaskthe old value of the netmask
netmaskthe new value of the netmask
master_ipthe master IP
master_netdevthe master network device
def CleanupImportExport(name):

Cleanup after an import or export.

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

def ConfigureOVS(ovs_name, ovs_link):

Creates a OpenvSwitch on the node.

This function sets up a OpenvSwitch on the node with given name nad connects it via a given eth device.

Parameters
ovs_name:stringName of the OpenvSwitch to create.
ovs_link:None or stringEthernet device for outside connection (can be missing)
def CreateFileStorageDir(file_storage_dir):

Create file storage directory.

Parameters
file_storage_dir:strdirectory to create
Returns
tupletuple with first element a boolean indicating wheter dir creation was successful or not
def CreateX509Certificate(validity, cryptodir=pathutils.CRYPTO_KEYS_DIR):

Creates a new X509 certificate for SSL/TLS.

Parameters
validity:intValidity in seconds
cryptodirUndocumented
Returns
tuple; (string, string)Certificate name and public part
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNDOWN, 'master-ip-turndown', _BuildMasterIpEnv)
def DeactivateMasterIp(master_params, use_external_mip_script):

Deactivate the master IP on this node.

Parameters
master_params:objects.MasterNetworkParametersnetwork parameters of the master
use_external_mip_script:booleanwhether to use an external master IP address setup script
Raises
RPCFailin case of errors during the IP turndown
def DemoteFromMC():

Demotes the current node from master candidate role.

def DiagnoseExtStorage(top_dirs=None):

Compute the validity for all ExtStorage Providers.

Parameters
top_dirs:listthe list of directories in which to search (if not given defaults to pathutils.ES_SEARCH_PATH)
Returns
list of objects.ExtStorage

a list of tuples (name, path, status, diagnose, parameters) for all (potential) ExtStorage Providers under all search paths, where:

  • name is the (potential) ExtStorage Provider
  • path is the full path to the ExtStorage Provider
  • status True/False is the validity of the ExtStorage Provider
  • diagnose is the error message for an invalid ExtStorage Provider, otherwise empty
  • parameters is a list of (name, help) parameters, if any
def DiagnoseOS(top_dirs=None):

Compute the validity for all OSes.

Parameters
top_dirs:listthe list of directories in which to search (if not given defaults to pathutils.OS_SEARCH_PATH)
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
def DrbdAttachNet(disks, multimaster):

Attaches the network on a list of drbd devices.

def DrbdDisconnectNet(disks):

Disconnects the network on a list of drbd devices.

def DrbdNeedsActivation(disks):

Checks which of the passed disks needs activation and returns their UUIDs.

def DrbdWaitSync(disks):

Wait until DRBDs have synchronized.

def EnsureDaemon(daemon_name, run):

Ensures the given daemon is running or stopped.

Parameters
daemon_name:stringname of the daemon (e.g., constants.KVMD)
run:boolwhether to start or stop the daemon
Returns
bool'True' if daemon successfully started/stopped, 'False' otherwise
def EtcHostsModify(mode, host, ip):

Modify a host entry in /etc/hosts.

Parameters
modeThe mode to operate. Either add or remove entry
hostThe host to operate on
ipThe ip associated with the entry
def ExportInfo(dest):

Get export configuration information.

Parameters
dest:strdirectory containing the export
Returns
objects.SerializableConfigParsera serializable config file containing the export info
def ExportOS(instance, override_env):

Creates a GZIPed tarball with an OS definition and environment.

The archive contains a file with the environment variables needed by the OS scripts.

Parameters
instance:objects.Instanceinstance for which the OS definition is exported
override_env:dict of string to stringif supplied, it overrides the environment on a key-by-key basis that is part of the archive
Returns
stringfilepath of the archive
def FinalizeExport(instance, snap_disks):

Write out the export configuration information.

Parameters
instance:objects.Instancethe instance which we export, used for saving configuration
snap_disks:list of objects.Disklist of snapshot block devices, which will be used to get the actual name of the dump file
Returns
NoneUndocumented
def FinalizeMigrationDst(instance, info, success):

Finalize any preparation to accept an instance.

Parameters
instance:objects.Instancethe instance definition
info:string/data (opaque)migration information, from the source node
success:booleanwhether the migration was a success or a failure
def FinalizeMigrationSource(instance, success, live):

Finalize the instance migration on the source node.

Parameters
instance:objects.Instancethe instance definition of the migrated instance
success:boolwhether the migration succeeded or not
live:boolwhether the user requested a live migration or not
Raises
RPCFailIf the execution fails for some reason
def GetAllInstancesInfo(hypervisor_list, all_hvparams):

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:listlist of hypervisors to query for instance data
all_hvparams:dict of dict of stringsmapping of hypervisor names to hvparams
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
def GetBlockDevSizes(devices):

Return the size of the given block devices

Parameters
devices:listlist 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}

def GetCryptoTokens(token_requests):

Perform actions on the node's cryptographic tokens.

Token types can be 'ssl' or 'ssh'. So far only some actions are implemented for 'ssl'. Action 'get' returns the digest of the public client ssl certificate. Action 'create' creates a new client certificate and private key and also returns the digest of the certificate. The third parameter of a token request are optional parameters for the actions, so far only the filename is supported.

Parameters
token_requests:list of tuples of (string, string, dict), where the first string is in constants.CRYPTO_TYPES, the second in constants.CRYPTO_ACTIONS. The third parameter is a dictionary of string to string.list of requests of cryptographic tokens and actions to perform on them. The actions come with a dictionary of options.
Returns
list of tuples (string, string)list of tuples of the token type and the public crypto token
def GetDrbdUsermodeHelper():

Returns DRBD usermode helper currently configured.

def GetFileInfo(file_path):

Checks if a file exists and returns information related to it.

Currently returned information:

  • file size: int, size in bytes
Parameters
file_path:stringName of file to examine.
Returns
tuple of bool, dictWhether the file exists, and a dictionary of information about the file gathered by os.stat.
def GetImportExportStatus(names):

Returns import/export daemon status.

Parameters
names:sequenceList of names
Returns
List of dictsReturns a list of the state of each named import/export or None if a status couldn't be read
def GetInstanceConsoleInfo(instance_param_dict, get_hv_fn=hypervisor.GetHypervisor):

Gather data about the console access of a set of instances of this node.

This function assumes that the caller already knows which instances are on this node, by calling a function such as GetAllInstancesInfo or GetInstanceList.

For every instance, a large amount of configuration data needs to be provided to the hypervisor interface in order to receive the console information. Whether this could or should be cut down can be discussed. The information is provided in a dictionary indexed by instance name, allowing any number of instance queries to be done.

Parameters
instance_param_dict:dict of string to tuple of dictionaries, where the dictionaries represent: objects.Instance, objects.Node, objects.NodeGroup, HvParams, BeParamsmapping of instance name to parameters necessary for console information retrieval
get_hv_fnUndocumented
Returns
dict

dictionary of instance: data, with data having the following keys:

  • instance: instance name
  • kind: console kind
  • message: used with kind == CONS_MESSAGE, indicates console to be unavailable, supplies error message
  • host: host to connect to
  • port: port to use
  • user: user for login
  • command: the command, broken into parts as an array
  • display: unknown, potentially unused?
def GetInstanceInfo(instance, hname, hvparams=None):

Gives back the information about an instance as a dictionary.

Parameters
instance:stringthe instance name
hname:stringthe hypervisor type of the instance
hvparams:dict of stringsthe instance's hvparams
Returns
dict

dictionary with the following keys:

  • memory: memory size of instance (int)
  • state: state of instance (HvInstanceState)
  • time: cpu time of instance (float)
  • vcpus: the number of vcpus (int)
def GetInstanceList(hypervisor_list, all_hvparams=None, get_hv_fn=hypervisor.GetHypervisor):

Provides a list of instances.

Parameters
hypervisor_list:listthe list of hypervisors to query information
all_hvparams:dict of dict of stringsa dictionary mapping hypervisor types to respective cluster-wide hypervisor parameters
get_hv_fn:functionfunction that returns a hypervisor for the given hypervisor name; optional parameter to increase testability
Returns
list

a list of all running instances on the current node

  • instance1.example.com
  • instance2.example.com
def GetInstanceListForHypervisor(hname, hvparams=None, get_hv_fn=hypervisor.GetHypervisor):

Provides a list of instances of the given hypervisor.

Parameters
hname:stringname of the hypervisor
hvparams:dict of stringshypervisor parameters for the given hypervisor
get_hv_fn:functionfunction that returns a hypervisor for the given hypervisor name; optional parameter to increase testability
Returns
list

a list of all running instances on the current node

  • instance1.example.com
  • instance2.example.com
def GetInstanceMigratable(instance):

Computes whether an instance can be migrated.

Parameters
instance:objects.Instanceobject representing the instance to be checked.
Returns
tuple

tuple of (result, description) where:

  • result: whether the instance can be migrated or not
  • description: a description of the issue, if relevant
def GetMasterNodeName():

Returns the master node name.

Returns
stringname of the master node
Raises
RPCFailin case of errors
def GetMigrationStatus(instance):

Get the migration status

Parameters
instance:objects.Instancethe instance that is being migrated
Returns
objects.MigrationStatusthe 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
RPCFailIf the migration status cannot be retrieved
def GetNodeInfo(storage_units, hv_specs):

Gives back a hash with different information about the node.

Parameters
storage_units:list of tuples (string, string, list)List of tuples (storage unit, identifier, parameters) to ask for disk space information. In case of lvm-vg, the identifier is the VG name. The parameters can contain additional, storage-type-specific parameters, for example exclusive storage for lvm storage.
hv_specs:list of pairs (string, dict of strings)list of pairs of a hypervisor's name and its hvparams
Returns
tuple; (string, None/list of dict, None/dict)Tuple containing boot ID, volume group information and hypervisor information
def GetVolumeList(vg_names):

Compute list of logical volumes and their size.

Parameters
vg_names:listthe 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.

def HotplugDevice(instance, action, dev_type, device, extra, seq):

Hotplug a device

Hotplug is currently supported only for KVM Hypervisor.

Parameters
instance:objects.Instancethe instance to which we hotplug a device
action:stringthe hotplug action to perform
dev_type:stringthe device type to hotplug
device:either objects.NIC or objects.Diskthe device object to hotplug
extra:tupleextra info used for disk hotplug (disk link, drive uri)
seq:intthe index of the device from master perspective
Raises
RPCFailin case instance does not have KVM hypervisor
def HotplugSupported(instance):

Checks if hotplug is generally supported.

def InstanceBalloonMemory(instance, memory):

Resize an instance's memory.

Parameters
instance:objects.Instancethe instance object
memory:intnew memory amount in MB
Returns
NoneUndocumented
def InstanceOsAdd(instance, reinstall, debug):

Add an OS to an instance.

Parameters
instance:objects.InstanceInstance whose OS is to be installed
reinstall:booleanwhether this is an instance reinstall
debug:integerdebug level, passed to the OS scripts
Returns
NoneUndocumented
def InstanceReboot(instance, reboot_type, shutdown_timeout, reason):

Reboot an instance.

Parameters
instance:objects.Instancethe instance object to reboot
reboot_type:str

the type of reboot, one the following constants:

shutdown_timeout:integermaximum timeout for soft shutdown
reason:list of reasonsthe reason trail for this reboot
Returns
NoneUndocumented
def InstanceShutdown(instance, timeout, reason, store_reason=True):

Shut an instance down.

Parameters
instance:objects.Instancethe instance object
timeout:integermaximum timeout for soft shutdown
reason:list of reasonsthe reason trail for this shutdown
store_reason:booleanwhether to store the shutdown reason trail on file
Returns
NoneUndocumented
Note
this functions uses polling with a hardcoded timeout.
def JobQueuePurge():

Removes job queue files and archived jobs.

Returns
tupleTrue, None
def JobQueueRename(old, new):

Renames a job queue file.

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

Parameters
old:strthe old (actual) file name
new:strthe desired file name
Returns
tuplethe success of the operation and payload
def JobQueueUpdate(file_name, content):

Updates a file in the queue directory.

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

Parameters
file_name:strthe job file name
content:strthe new job contents
Returns
booleanthe success of the operation
def LeaveCluster(modify_ssh_setup):

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_setupboolean
def ListExports():

Return a list of exports currently available on this machine.

Returns
listlist of the exports
def ListVolumeGroups():

List the volume groups and their size.

Returns
dictdictionary with keys volume name and values the size of the volume
def MigrateInstance(cluster_name, instance, target, live):

Migrates an instance to another node.

Parameters
cluster_name:stringname of the cluster
instance:objects.Instancethe instance definition
target:stringthe target node name
live:booleanwhether the migration should be done live or not (the interpretation of this parameter is left to the hypervisor)
Raises
RPCFailif migration fails for some reason
def MigrationInfo(instance):

Gather information about an instance to be migrated.

Parameters
instance:objects.Instancethe instance definition
def ModifyInstanceMetadata(metadata):

Sends instance data to the metadata daemon.

Uses the Luxi transport layer to communicate with the metadata daemon configuration server. It starts the metadata daemon if it is not running. The daemon must be enabled during at configuration time.

Parameters
metadata:dictinstance metadata obtained by calling objects.Instance.ToDict on an instance object
def NodeVolumes():

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.

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

Calculate the basic environment for an os script.

Parameters
os_name:strfull operating system name (including variant)
inst_os:objects.OSoperating system for which the environment is being built
os_params:dictthe OS parameters
debug:integerdebug level (0 or 1, for OS Api 10)
Returns
dictdict of environment variables
Raises
errors.BlockDeviceErrorif the block device cannot be found
def OSEnvironment(instance, inst_os, debug=0):

Calculate the environment for an os script.

Parameters
instance:objects.Instancetarget instance for the os script run
inst_os:objects.OSoperating system for which the environment is being built
debug:integerdebug level (0 or 1, for OS Api 10)
Returns
dictdict of environment variables
Raises
errors.BlockDeviceErrorif the block device cannot be found
def OSFromDisk(name, base_dir=None):

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
nameUndocumented
base_dir:stringBase directory containing OS installations. Defaults to a search in all the OS_SEARCH_PATH dirs.
Returns
objects.OSthe OS instance if we find a valid one
Raises
RPCFailif we don't find a valid OS
def PowercycleNode(hypervisor_type, hvparams=None):

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.

def RemoveExport(export):

Remove an existing export from the node.

Parameters
export:strthe name of the export to remove
Returns
NoneUndocumented
def RemoveFileStorageDir(file_storage_dir):

Remove file storage directory.

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

Parameters
file_storage_dir:strthe directory we should cleanup
Returns
tuple (success,)tuple of one element, success, denoting whether the operation was successful
def RemoveNodeSshKey(node_uuid, node_name, master_candidate_uuids, potential_master_candidates, master_uuid=None, keys_to_remove=None, from_authorized_keys=False, from_public_keys=False, clear_authorized_keys=False, clear_public_keys=False, pub_key_file=pathutils.SSH_PUB_KEYS, ssconf_store=None, noded_cert_file=pathutils.NODED_CERT_FILE, readd=False, run_cmd_fn=ssh.RunSshCmdWithStdin):

Removes the node's SSH keys from the key files and distributes those.

Note that at least one of the flags from_authorized_keys, from_public_keys, clear_authorized_keys, and clear_public_keys has to be set to True for the function to perform any action at all. Not doing so will trigger an assertion in the function.

Parameters
node_uuid:strUUID of the node whose key is removed
node_name:strname of the node whose key is remove
master_candidate_uuids:list of strlist of UUIDs of the current master candidates
potential_master_candidates:list of strlist of names of potential master candidates
master_uuidUndocumented
keys_to_remove:dict of str to list of stra dictionary mapping node UUIDS to lists of SSH keys to be removed. This list is supposed to be used only if the keys are not in the public keys file. This is for example the case when removing a master node's key.
from_authorized_keys:booleanwhether or not the key should be removed from the authorized_keys file
from_public_keys:booleanwhether or not the key should be remove from the ganeti_pub_keys file
clear_authorized_keys:booleanwhether or not the authorized_keys file should be cleared on the node whose keys are removed
clear_public_keys:booleanwhether to clear the node's ganeti_pub_key file
pub_key_fileUndocumented
ssconf_storeUndocumented
noded_cert_fileUndocumented
readd:booleanwhether this is called during a readd operation.
run_cmd_fnUndocumented
Returns
list of stringlist of feedback messages
def RemoveNodeSshKeyBulk(node_list, master_candidate_uuids, potential_master_candidates, master_uuid=None, keys_to_remove=None, pub_key_file=pathutils.SSH_PUB_KEYS, ssconf_store=None, noded_cert_file=pathutils.NODED_CERT_FILE, readd=False, run_cmd_fn=ssh.RunSshCmdWithStdin):

Removes the node's SSH keys from the key files and distributes those.

Note that at least one of the flags from_authorized_keys, from_public_keys, clear_authorized_keys, and clear_public_keys of at least one node has to be set to True for the function to perform any action at all. Not doing so will trigger an assertion in the function.

Parameters
node_list:list of SshRemoveNodeInfo.list of information about nodes whose keys are being removed
master_candidate_uuids:list of strlist of UUIDs of the current master candidates
potential_master_candidates:list of strlist of names of potential master candidates
master_uuidUndocumented
keys_to_remove:dict of str to list of stra dictionary mapping node UUIDS to lists of SSH keys to be removed. This list is supposed to be used only if the keys are not in the public keys file. This is for example the case when removing a master node's key.
pub_key_fileUndocumented
ssconf_storeUndocumented
noded_cert_fileUndocumented
readd:booleanwhether this is called during a readd operation.
run_cmd_fnUndocumented
Returns
list of stringlist of feedback messages
def RemoveX509Certificate(name, cryptodir=pathutils.CRYPTO_KEYS_DIR):

Removes a X509 certificate.

Parameters
name:stringCertificate name
cryptodirUndocumented
def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir):

Rename the file storage directory.

Parameters
old_file_storage_dir:strthe current path
new_file_storage_dir:strthe name we should rename to
Returns
tuple (success,)tuple of one element, success, denoting whether the operation was successful
def RenewSshKeys(node_uuids, node_names, master_candidate_uuids, potential_master_candidates, old_key_type, new_key_type, new_key_bits, ganeti_pub_keys_file=pathutils.SSH_PUB_KEYS, ssconf_store=None, noded_cert_file=pathutils.NODED_CERT_FILE, run_cmd_fn=ssh.RunSshCmdWithStdin):

Renews all SSH keys and updates authorized_keys and ganeti_pub_keys.

Parameters
node_uuids:list of strlist of node UUIDs whose keys should be renewed
node_names:list of strlist of node names whose keys should be removed. This list should match the node_uuids parameter
master_candidate_uuids:list of strlist of UUIDs of master candidates or master node
potential_master_candidatesUndocumented
old_key_type:One of constants.SSHK_ALLthe type of SSH key already present on nodes
new_key_type:One of constants.SSHK_ALLthe type of SSH key to be generated
new_key_bits:intthe length of the key to be generated
ganeti_pub_keys_file:strfile path of the the public key file
ssconf_storeUndocumented
noded_cert_file:strpath of the noded SSL certificate file
run_cmd_fn:functionfunction to run commands on remote nodes via SSH
Raises
ProgrammerErrorif node_uuids and node_names don't match; SshUpdateError if a node's key is missing from the public key file, if a node's new SSH key could not be fetched from it, if there is none or more than one entry in the public key list for the master node.
def RunLocalHooks(hook_opcode, hooks_path, env_builder_fn):

Decorator that runs hooks before and after the decorated function.

Parameters
hook_opcode:stringopcode of the hook
hooks_path:stringpath of the hooks
env_builder_fn:functionfunction that returns a dictionary containing the environment variables for the hooks. Will get all the parameters of the decorated function.
Raises
RPCFailin case of pre-hook failure
def RunOob(oob_program, command, node, timeout):

Executes oob_program with given command on given node.

Parameters
oob_programThe path to the executable oob_program
commandThe command to invoke on oob_program
nodeThe node given as an argument to the program
timeoutTimeout after which we kill the oob program
Returns
stdout
Raises
RPCFailIf execution fails for some reason
def RunRenameInstance(instance, old_name, debug):

Run the OS rename script for an instance.

Parameters
instance:objects.InstanceInstance whose OS is to be installed
old_name:stringprevious instance name
debug:integerdebug level, passed to the OS scripts
Returns
booleanthe success of the operation
def RunRestrictedCmd(cmd, _lock_timeout=_RCMD_LOCK_TIMEOUT, _lock_file=pathutils.RESTRICTED_COMMANDS_LOCK_FILE, _path=pathutils.RESTRICTED_COMMANDS_DIR, _sleep_fn=time.sleep, _prepare_fn=_PrepareRestrictedCmd, _runcmd_fn=utils.RunCmd, _enabled=constants.ENABLE_RESTRICTED_COMMANDS):

Executes a restricted command after performing strict tests.

Parameters
cmd:stringCommand name
_lock_timeoutUndocumented
_lock_fileUndocumented
_pathUndocumented
_sleep_fnUndocumented
_prepare_fnUndocumented
_runcmd_fnUndocumented
_enabledUndocumented
Returns
stringCommand output
Raises
RPCFailIn case of an error
def SetWatcherPause(until, _filename=pathutils.WATCHER_PAUSEFILE):

Creates or removes the watcher pause file.

Parameters
until:None or numberUnix timestamp saying until when the watcher shouldn't run
_filenameUndocumented
def StartImportExportDaemon(mode, opts, host, port, instance, component, ieio, ieioargs):

Starts an import or export daemon.

Parameters
modeImport/output mode
opts:objects.ImportExportOptionsDaemon options
host:stringRemote host for export (None for import)
port:intRemote port for export (None for import)
instance:objects.InstanceInstance object
component:stringwhich part of the instance is transferred now, e.g. 'disk/0'
ieioInput/output type
ieioargsInput/output arguments
def StartInstance(instance, startup_paused, reason, store_reason=True):

Start an instance.

Parameters
instance:objects.Instancepause instance at startup?
startup_paused:boolUndocumented
reason:list of reasonsthe reason trail for this startup
store_reason:booleanwhether to store the shutdown reason trail on file
Returns
NoneUndocumented
def StartMasterDaemons(no_voting):

Activate local node as master node.

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

Parameters
no_voting:booleanwhether to start ganeti-masterd without a node vote but still non-interactively
Returns
NoneUndocumented
def StopMasterDaemons():

Stop the master daemons on this node.

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

Returns
NoneUndocumented
def UploadFile(file_name, data, mode, uid, gid, atime, mtime):

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:strthe target file name
data:strthe new contents of the file
mode:intthe mode to give the file (can be None)
uid:stringthe owner of the file
gid:stringthe group of the file
atime:floatthe atime to set on the file (can be None)
mtime:floatthe mtime to set on the file (can be None)
Returns
NoneUndocumented
def ValidateHVParams(hvname, hvparams):

Validates the given hypervisor parameters.

Parameters
hvname:stringthe hypervisor name
hvparams:dictthe hypervisor parameters to be validated
Returns
NoneUndocumented
def ValidateOS(required, osname, checks, osparams, force_variant):

Validate the given OS parameters.

Parameters
required:booleanwhether absence of the OS should translate into failure or not
osname:stringthe OS to be validated
checks:listlist of the checks to run (currently only 'parameters')
osparams:dictdictionary with OS parameters, some of which may be private.
force_variantUndocumented
Returns
booleanTrue if the validation passed, or False if the OS was not found and required was false
def VerifyMasterIP(my_name, test_config):

Verify master IP is reachable.

Parameters
my_name:stringname of the node this test is running on
test_config:tuple (master_name, master_up, master_candidates)configuration for test as passed from LUClusterVerify() in what[constants.NV_MASTERIP]
Returns
bool or NoneBoolean test result, None if skipped
def VerifyNode(what, cluster_name, all_hvparams):

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
cluster_name:stringthe cluster's name
all_hvparams:dict of dict of stringsa dictionary mapping hypervisor names to hvparams
Returns
dicta dictionary with the same keys as the input dict, and values representing the result of the checks
def VerifyNodeNetTest(my_name, test_config):

Verify nodes are reachable.

Parameters
my_name:stringname of the node this test is running on
test_config:tuple (node_list, master_candidate_list)configuration for test as passed from LUClusterVerify() in what[constants.NV_NODENETTEST]
Returns
dicta dictionary with node names as keys and error messages as values
SshAddNodeInfo =

Undocumented

SshRemoveNodeInfo =

Undocumented

def _ApplyStorageInfoFunction(storage_type, storage_key, *args):

Looks up and applies the correct function to calculate free and total storage for the given storage type.

Parameters
storage_type:stringthe storage type for which the storage shall be reported.
storage_key:stringidentifier of a storage unit, e.g. the volume group name of an LVM storage unit
*args:anyvarious parameters that can be used for storage reporting. These parameters and their semantics vary from storage type to storage type and are just propagated in this function.
Returns
the results of the application of the storage space function (see _STORAGE_TYPE_INFO_FN) if storage space reporting is implemented for that storage type
Raises
NotImplementedErrorfor storage types who don't support space reporting yet
def _BuildMasterIpEnv(master_params, use_external_mip_script=None):

Builds environment variables for master IP hooks.

Parameters
master_params:objects.MasterNetworkParametersnetwork parameters of the master
use_external_mip_script:booleanwhether to use an external master IP address setup script (unused, but necessary per the implementation of the _RunLocalHooks decorator)
def _BuildUploadFileList():

Build the list of allowed upload files.

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

def _CalculateDeviceURI(instance, disk, device):

Get the URI for the device.

Parameters
instance:objects.Instancethe instance which disk belongs to
disk:objects.Diskthe target disk object
device:bdev.BlockDevthe corresponding BlockDevice
Returns
stringthe device uri if any else None
def _CheckExclusivePvs(pvi_list):

Check that PVs are not shared among LVs

Parameters
pvi_list:list of objects.LvmPvInfo objectsinformation about the PVs
Returns
list of tuples (string, list of strings)offending volumes, as tuples: (pv_name, [lv1_name, lv2_name...])
def _CheckForPlainDisk(disk):

Check within a disk and its children if there is a plain disk type.

Parameters
disk:objects.Diskthe disk we are checking
Returns
boolwhether or not there is a plain disk type
def _CheckLvmStorageParams(params):

Performs sanity check for the 'exclusive storage' flag.

See Also
_CheckStorageParams
def _CheckOSPList(os_obj, parameters):

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

Parameters
os_obj:objects.OSOS object to check
parameters:listthe list of parameters to check
def _CheckOSVariant(os_obj, name):

Check whether an OS name conforms to the os variants specification.

Parameters
os_obj:objects.OSOS object to check
name:stringOS name passed by the user, to check for validity
Returns
NoneTypeNone
Raises
RPCFailif OS variant is not valid
def _CheckStorageParams(params, num_params):

Performs sanity checks for storage parameters.

Parameters
params:listlist of storage parameters
num_params:intexpected number of parameters
def _CleanDirectory(path, exclude=None):

Removes all regular files in a directory.

Parameters
path:strthe directory to clean
exclude:listlist of files to be excluded, defaults to the empty list
def _CommonRestrictedCmdCheck(path, owner):

Common checks for restricted command file system directories and files.

Parameters
path:stringPath to check
ownerNone or tuple containing UID and GID
Returns
tuple; (boolean, string or os.stat result)The tuple's first element is the status; if False, the second element is an error message string, otherwise it's the result of os.stat
def _CreateImportExportStatusDir(prefix):

Creates status directory for import/export.

def _Decompress(data):

Unpacks data compressed by the RPC client.

Parameters
data:list or tupleData sent by RPC client
Returns
strDecompressed data
def _DownloadAndDumpDevice(source_url, target_path, size):

This function images a device using a downloaded image file.

Parameters
source_url:stringURL of image to dump to disk
target_path:stringpath of the device to image
size:intmaximum size in MiB to write (data source might be smaller)
Returns
NoneTypeNone
Raises
RPCFailin case of download or write failures
def _DumpDevice(source_path, target_path, offset, size, truncate):

This function images/wipes the device using a local file.

Parameters
source_path:stringpath of the image or data source (e.g., "/dev/zero")
target_path:stringpath of the device to image/wipe
offset:intoffset in MiB in the output file
size:intmaximum size in MiB to write (data source might be smaller)
truncate:boolwhether the file should be truncated
Returns
None
Raises
RPCFailin case of failure
def _EnsureJobQueueFile(file_name):

Checks whether the given filename is in the queue directory.

Parameters
file_name:strthe file name we should check
Returns
NoneUndocumented
Raises
RPCFailif the file is not valid
def _Fail(msg, *args, **kwargs):

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:stringthe text of the exception @raise RPCFail
*argsUndocumented
**kwargsUndocumented
def _FindDisks(disks):

Finds attached BlockDevs for the given disks.

Parameters
disks:list of objects.Diskthe disk objects we need to find
Returns
list of BlockDev objects or None if a given disk was not found or was no attached.
def _GatherAndLinkBlockDevs(instance):

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
instance:objects.Instancethe instance whose disks we should assemble
Returns
listlist of (disk_object, link_name, drive_uri)
def _GenerateNodeSshKey(node_uuid, node_name, ssh_port_map, ssh_key_type, ssh_key_bits, pub_key_file=pathutils.SSH_PUB_KEYS, ssconf_store=None, noded_cert_file=pathutils.NODED_CERT_FILE, run_cmd_fn=ssh.RunSshCmdWithStdin, suffix=''):

Generates the root SSH key pair on the node.

Parameters
node_uuid:strUUID of the node whose key is removed
node_name:strname of the node whose key is remove
ssh_port_map:dict of str to intmapping of node names to their SSH port
ssh_key_type:One of constants.SSHK_ALLthe type of SSH key to be generated
ssh_key_bits:intthe length of the key to be generated
pub_key_fileUndocumented
ssconf_storeUndocumented
noded_cert_fileUndocumented
run_cmd_fnUndocumented
suffixUndocumented
def _GetBlockDevSymlinkPath(instance_name, idx, _dir=None):

Returns symlink path for block device.

def _GetConfig():

Simple wrapper to return a SimpleStore.

Returns
ssconf.SimpleStorea SimpleStore instance
def _GetFileStorageSpaceInfo(path, params):

Wrapper around filestorage.GetSpaceInfo.

The purpose of this wrapper is to call filestorage.GetFileStorageSpaceInfo and ignore the *args parameter to not leak it into the filestorage module's code.

See Also
filestorage.GetFileStorageSpaceInfo for description of the parameters.
def _GetHvInfo(name, hvparams, get_hv_fn=hypervisor.GetHypervisor):

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
Parameters
nameUndocumented
hvparams:dict of stringthe hypervisor's hvparams
get_hv_fnUndocumented
def _GetHvInfoAll(hv_specs, get_hv_fn=hypervisor.GetHypervisor):

Retrieves node information for all hypervisors.

See _GetHvInfo for information on the output.

Parameters
hv_specs:list of pairs (string, dict of strings)list of pairs of a hypervisor's name and its hvparams
get_hv_fnUndocumented
def _GetImportExportIoCommand(instance, mode, ieio, ieargs):

Returns the command for the requested input/output.

Parameters
instance:objects.InstanceThe instance object
modeImport/export mode
ieioInput/output type
ieargsInput/output arguments
def _GetInstanceInfo(instance):

Helper function GetInstanceInfo

def _GetInstReasonFilename(instance_name):

Path of the file containing the reason of the instance status change.

Parameters
instance_name:stringThe name of the instance
Returns
stringThe path of the file
def _GetLvmPvSpaceInfo(name, params):

Wrapper around _GetVgSpindlesInfo with sanity checks.

See Also
_GetLvmVgSpaceInfo
def _GetLvmVgSpaceInfo(name, params):

Wrapper around _GetVgInfo which checks the storage parameters.

Parameters
name:stringname of the volume group
params:listlist of storage parameters, which in this case should be containing only one for exclusive storage
def _GetMasterNodeUUID(node_uuid_name_map, master_node_name):

Undocumented

def _GetNamedNodeInfo(names, fn):

Calls fn for all names in names and returns a list of dictionaries.

Returns
None or list of dictUndocumented
def _GetNewMasterKey(root_keyfiles, master_node_uuid):

Undocumented

def _GetOldMasterKeys(master_node_uuid, pub_key_file):

Undocumented

def _GetSshRunner(cluster_name):

Simple wrapper to return an SshRunner.

Parameters
cluster_name:strthe cluster name, which is needed by the SshRunner constructor
Returns
ssh.SshRunneran SshRunner instance
def _GetVgInfo(name, excl_stor, info_fn=bdev.LogicalVolume.GetVGInfo):

Retrieves information about a LVM volume group.

def _GetVgSpindlesInfo(name, excl_stor, info_fn=bdev.LogicalVolume.GetVgSpindlesInfo):

Retrieves information about spindles in an LVM volume group.

Parameters
name:stringVG name
excl_stor:boolexclusive storage
info_fnUndocumented
Returns
dictdictionary whose keys are "name", "vg_free", "vg_size" for VG name, free spindles, total spindles respectively
def _GetX509Filenames(cryptodir, name):

Returns the full paths for the private key and certificate.

def _InitSshUpdateData(data, noded_cert_file, ssconf_store):

Undocumented

def _InstanceLogName(kind, os_name, instance, component):

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:stringthe operation type (e.g. add, import, etc.)
os_name:stringthe os name
instance:stringthe name of the instance being imported/added/etc.
component:string or Nonethe name of the component of the instance being transferred
def _IsInstanceUserDown(instance_info):

Undocumented

def _OpenRealBD(disk):

Opens the underlying block device of a disk.

Parameters
disk:objects.Diskthe disk object we want to open
def _OSOndiskAPIVersion(os_dir):

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:strthe directory in which we should look for the OS
Returns
tupletuple (status, data) with status denoting the validity and data holding either the valid versions or an error message
def _PrepareRestrictedCmd(path, cmd, _verify_dir=_VerifyRestrictedCmdDirectory, _verify_name=_VerifyRestrictedCmdName, _verify_cmd=_VerifyRestrictedCmd):

Performs a number of tests on a restricted command.

Parameters
path:stringDirectory containing restricted commands
cmd:stringCommand name
_verify_dirUndocumented
_verify_nameUndocumented
_verify_cmdUndocumented
Returns
Same as _VerifyRestrictedCmd
def _RecursiveAssembleBD(disk, owner, as_primary):

Activate a block device for an instance.

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

Parameters
disk:objects.Diskthe disk we try to assemble
owner:strthe name of the instance which owns the disk
as_primary:booleanif we should make the block device read/write
Returns
the assembled device or None (in case no device was assembled)
Raises
errors.BlockDeviceErrorin case there is an error during the activation of the children or the device itself
Note
this function is called recursively.
def _RecursiveFindBD(disk, lvs_cache=None):

Check if a device is activated.

If so, return information about the real device.

Parameters
disk:objects.Diskthe disk object we need to find
lvs_cacheUndocumented
Returns
None if the device can't be found, otherwise the device instance
def _RemoveBlockDevLinks(instance_name, disks):

Remove the block device symlinks belonging to the given instance.

def _ReplaceMasterKeyOnMaster(root_keyfiles):

Undocumented

def _RunMasterSetupScript(master_params, action, use_external_mip_script):

Execute the master IP address setup script.

Parameters
master_params:objects.MasterNetworkParametersnetwork parameters of the master
action:stringaction to pass to the script. Must be one of backend._MASTER_START or backend._MASTER_STOP
use_external_mip_script:booleanwhether to use an external master IP address setup script
Raises
backend.RPCFailif there are errors during the execution of the script
def _StoreInstReasonTrail(instance_name, trail):

Serialize a reason trail related to an instance change of state to file.

The exact location of the file depends on the name of the instance and on the configuration of the Ganeti cluster defined at deploy time.

Parameters
instance_name:stringThe name of the instance
trail:list of reasonsreason trail
Returns
NoneUndocumented
def _SymlinkBlockDev(instance_name, device_path, idx):

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_namethe name of the target instance
device_pathpath of the physical block device, on the node
idxthe disk index
Returns
absolute path to the disk's symlink
def _TransformFileStorageDir(fs_dir):

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:strthe path to check
Returns
the normalized path if valid, None otherwise
def _TryOSFromDisk(name, base_dir=None):

Create an OS instance from disk.

This function will return an OS instance if the given name is a valid OS name.

Parameters
nameUndocumented
base_dir:stringBase directory containing OS installations. Defaults to a search in all the OS_SEARCH_PATH dirs.
Returns
tuplesuccess and either the OS instance if we find a valid one, or error message
def _VerifyClientCertificate(cert_file=pathutils.NODED_CLIENT_CERT_FILE):

Verify the existance and validity of the client SSL certificate.

Also, verify that the client certificate is not self-signed. Self- signed client certificates stem from Ganeti versions 2.12.0 - 2.12.4 and should be replaced by client certificates signed by the server certificate. Hence we output a warning when we encounter a self-signed one.

def _VerifyHvparams(what, vm_capable, result, get_hv_fn=hypervisor.GetHypervisor):

Verifies the hvparams. Appends the results to the 'results' list.

Parameters
what:dicta dictionary of things to check
vm_capable:booleanwhether or not this node is vm capable
result:dictdictionary of verification results; results of the verifications in this function will be added here
get_hv_fn:functionfunction to retrieve the hypervisor, to improve testability
def _VerifyHypervisors(what, vm_capable, result, all_hvparams, get_hv_fn=hypervisor.GetHypervisor):

Verifies the hypervisor. Appends the results to the 'results' list.

Parameters
what:dicta dictionary of things to check
vm_capable:booleanwhether or not this node is vm capable
result:dictdictionary of verification results; results of the verifications in this function will be added here
all_hvparams:dict of dict of stringdictionary mapping hypervisor names to hvparams
get_hv_fn:functionfunction to retrieve the hypervisor, to improve testability
def _VerifyInstanceList(what, vm_capable, result, all_hvparams):

Verifies the instance list.

Parameters
what:dicta dictionary of things to check
vm_capable:booleanwhether or not this node is vm capable
result:dictdictionary of verification results; results of the verifications in this function will be added here
all_hvparams:dict of dict of stringdictionary mapping hypervisor names to hvparams
def _VerifyNodeInfo(what, vm_capable, result, all_hvparams):

Verifies the node info.

Parameters
what:dicta dictionary of things to check
vm_capable:booleanwhether or not this node is vm capable
result:dictdictionary of verification results; results of the verifications in this function will be added here
all_hvparams:dict of dict of stringdictionary mapping hypervisor names to hvparams
def _VerifyRestrictedCmd(path, cmd, _owner=None):

Verifies a whole restricted command and returns its executable filename.

Parameters
path:stringDirectory containing restricted commands
cmd:stringCommand name
_ownerUndocumented
Returns
tuple; (boolean, string)The tuple's first element is the status; if False, the second element is an error message string, otherwise the second element is the absolute path to the executable
def _VerifyRestrictedCmdDirectory(path, _owner=None):

Verifies restricted command directory.

Parameters
path:stringPath to check
_ownerUndocumented
Returns
tuple; (boolean, string or None)The tuple's first element is the status; if False, the second element is an error message string, otherwise it's None
def _VerifyRestrictedCmdName(cmd):

Verifies a restricted command name.

Parameters
cmd:stringCommand name
Returns
tuple; (boolean, string or None)The tuple's first element is the status; if False, the second element is an error message string, otherwise it's None
def _VerifySshClutter(node_status_list, my_name):

Verifies that the 'authorized_keys' files are not cluttered up.

Parameters
node_status_list:list of tupleslist of nodes of the cluster associated with a couple of flags: (uuid, name, is_master_candidate, is_potential_master_candidate, online)
my_name:strname of this node
def _VerifySshSetup(node_status_list, my_name, ssh_key_type, ganeti_pub_keys_file=pathutils.SSH_PUB_KEYS):

Verifies the state of the SSH key files.

Parameters
node_status_list:list of tupleslist of nodes of the cluster associated with a couple of flags: (uuid, name, is_master_candidate, is_potential_master_candidate, online)
my_name:strname of this node
ssh_key_type:one of constants.SSHK_ALLtype of key used on nodes
ganeti_pub_keys_file:strfilename of the public keys file
_ALLOWED_CLEAN_DIRS =
_ALLOWED_UPLOAD_FILES =

denotes which files are accepted in the UploadFile function

Value
_BuildUploadFileList()
_BOOT_ID_PATH: str =

Undocumented

Value
'/proc/sys/kernel/random/boot_id'
_IES_CA_FILE: str =

Undocumented

Value
'ca'
_IES_PID_FILE: str =

Undocumented

Value
'pid'
_IES_STATUS_FILE: str =

Undocumented

Value
'status'
_LVSLINE_REGEX =

Undocumented

Value
re.compile(r'^ *([^\|]+)\|([^\|]+)\|([0-9\.]+)\|([^\|]{6,})\|?$')
_MASTER_START: str =

Undocumented

Value
'start'
_MASTER_STOP: str =

Undocumented

Value
'stop'
_MAX_SSL_CERT_VALIDITY =

Undocumented

Value
((7*24)*60)*60
_RCMD_INVALID_DELAY: int =

Undocumented

Value
10
_RCMD_LOCK_TIMEOUT =

Undocumented

Value
_RCMD_INVALID_DELAY*0.8
_RCMD_MAX_MODE =

Undocumented

Value
(((stat.S_IRWXU|stat.S_IRGRP)|stat.S_IXGRP)|stat.S_IROTH)|stat.S_IXOTH
_X509_CERT_FILE: str =

Undocumented

Value
'cert'
_X509_KEY_FILE: str =

Undocumented

Value
'key'