Functions used by the node daemon
Class |
|
Simple class for managing a cache of block device information. |
Class |
|
Hook runner. |
Class |
|
IAllocator runner. |
Exception |
|
Class denoting RPC failure. |
Function |
|
Sends SIGTERM to a running import/export daemon. |
Function |
|
Prepare the node to accept an instance. |
Function |
|
Activate the IP address of the master daemon. |
Function |
|
Distributes a node's public SSH key across the cluster. |
Function |
|
Distributes a node's public SSH key across the cluster. |
Function |
|
Extend a mirrored block device. |
Function |
|
Activate a block device for an instance. |
Function |
|
Closes the given block devices. |
Function |
|
Copies data from source block device to target. |
Function |
|
Creates a block device for an instance. |
Function |
|
Check if a device is activated. |
Function |
|
Computes the size of the given disks. |
Function |
|
Get the mirroring status of a list of devices. |
Function |
|
Get the mirroring status of a list of devices. |
Function |
|
Grow a stack of block devices. |
Function |
|
Images a block device either by dumping a local file or downloading a URL. |
Function |
|
Opens the given block devices. |
Function |
|
Pause or resume the sync of the block device. |
Function |
|
Remove a block device. |
Function |
|
Shrink a mirrored block device. |
Function |
|
Rename a list of block devices. |
Function |
|
Sets 'metadata' information on block devices. |
Function |
|
Shut down a block device. |
Function |
|
Create a snapshot copy of a block device. |
Function |
|
Wipes a block device. |
Function |
|
Check if a list of bridges exist on the current node. |
Function |
|
Change the netmask of the master IP. |
Function |
|
Cleanup after an import or export. |
Function |
|
Creates a OpenvSwitch on the node. |
Function |
|
Create file storage directory. |
Function |
|
Creates a new X509 certificate for SSL/TLS. |
Function |
|
Deactivate the master IP on this node. |
Function |
|
Demotes the current node from master candidate role. |
Function |
|
Compute the validity for all ExtStorage Providers. |
Function |
|
Compute the validity for all OSes. |
Function |
|
Attaches the network on a list of drbd devices. |
Function |
|
Disconnects the network on a list of drbd devices. |
Function |
|
Checks which of the passed disks needs activation and returns their UUIDs. |
Function |
|
Wait until DRBDs have synchronized. |
Function |
|
Ensures the given daemon is running or stopped. |
Function |
|
Modify a host entry in /etc/hosts. |
Function |
|
Get export configuration information. |
Function |
|
Creates a GZIPed tarball with an OS definition and environment. |
Function |
|
Write out the export configuration information. |
Function |
|
Finalize any preparation to accept an instance. |
Function |
|
Finalize the instance migration on the source node. |
Function |
|
Gather data about all instances. |
Function |
|
Return the size of the given block devices |
Function |
|
Perform actions on the node's cryptographic tokens. |
Function |
|
Returns DRBD usermode helper currently configured. |
Function |
|
Checks if a file exists and returns information related to it. |
Function |
|
Returns import/export daemon status. |
Function |
|
Gather data about the console access of a set of instances of this node. |
Function |
|
Gives back the information about an instance as a dictionary. |
Function |
|
Provides a list of instances. |
Function |
|
Provides a list of instances of the given hypervisor. |
Function |
|
Computes whether an instance can be migrated. |
Function |
|
Returns the master node name. |
Function |
|
Get the migration status |
Function |
|
Gives back a hash with different information about the node. |
Function |
|
Compute list of logical volumes and their size. |
Function |
|
Hotplug a device |
Function |
|
Checks if hotplug is generally supported. |
Function |
|
Resize an instance's memory. |
Function |
|
Add an OS to an instance. |
Function |
|
Reboot an instance. |
Function |
|
Shut an instance down. |
Function |
|
Removes job queue files and archived jobs. |
Function |
|
Renames a job queue file. |
Function |
|
Updates a file in the queue directory. |
Function |
|
Cleans up and remove the current node. |
Function |
|
Return a list of exports currently available on this machine. |
Function |
|
List the volume groups and their size. |
Function |
|
Migrates an instance to another node. |
Function |
|
Gather information about an instance to be migrated. |
Function |
|
Sends instance data to the metadata daemon. |
Function |
|
List all volumes on this node. |
Function |
|
Calculate the basic environment for an os script. |
Function |
|
Calculate the environment for an os script. |
Function |
|
Create an OS instance from disk. |
Function |
|
Hard-powercycle the node. |
Function |
|
Remove an existing export from the node. |
Function |
|
Remove file storage directory. |
Function |
|
Removes the node's SSH keys from the key files and distributes those. |
Function |
|
Removes the node's SSH keys from the key files and distributes those. |
Function |
|
Removes a X509 certificate. |
Function |
|
Rename the file storage directory. |
Function |
|
Renews all SSH keys and updates authorized_keys and ganeti_pub_keys. |
Function |
|
Decorator that runs hooks before and after the decorated function. |
Function |
|
Executes oob_program with given command on given node. |
Function |
|
Run the OS rename script for an instance. |
Function |
|
Executes a restricted command after performing strict tests. |
Function |
|
Creates or removes the watcher pause file. |
Function |
|
Starts an import or export daemon. |
Function |
|
Start an instance. |
Function |
|
Activate local node as master node. |
Function |
|
Stop the master daemons on this node. |
Function |
|
Write a file to the filesystem. |
Function |
|
Validates the given hypervisor parameters. |
Function |
|
Validate the given OS parameters. |
Function |
|
Verify master IP is reachable. |
Function |
|
Verify the status of the local node. |
Function |
|
Verify nodes are reachable. |
Variable |
|
Undocumented |
Variable |
|
Undocumented |
Function | _ |
Looks up and applies the correct function to calculate free and total storage for the given storage type. |
Function | _ |
Builds environment variables for master IP hooks. |
Function | _ |
Build the list of allowed upload files. |
Function | _ |
Get the URI for the device. |
Function | _ |
Check that PVs are not shared among LVs |
Function | _ |
Check within a disk and its children if there is a plain disk type. |
Function | _ |
Performs sanity check for the 'exclusive storage' flag. |
Function | _ |
Check whether a list of parameters is supported by the OS. |
Function | _ |
Check whether an OS name conforms to the os variants specification. |
Function | _ |
Performs sanity checks for storage parameters. |
Function | _ |
Removes all regular files in a directory. |
Function | _ |
Common checks for restricted command file system directories and files. |
Function | _ |
Creates status directory for import/export. |
Function | _ |
Unpacks data compressed by the RPC client. |
Function | _ |
This function images a device using a downloaded image file. |
Function | _ |
This function images/wipes the device using a local file. |
Function | _ |
Checks whether the given filename is in the queue directory. |
Function | _ |
Log an error and the raise an RPCFail exception. |
Function | _ |
Finds attached BlockDev s for the given disks. |
Function | _ |
Set up an instance's block device(s). |
Function | _ |
Generates the root SSH key pair on the node. |
Function | _ |
Returns symlink path for block device. |
Function | _ |
Simple wrapper to return a SimpleStore. |
Function | _ |
Wrapper around filestorage.GetSpaceInfo. |
Function | _ |
Retrieves node information from a hypervisor. |
Function | _ |
Retrieves node information for all hypervisors. |
Function | _ |
Returns the command for the requested input/output. |
Function | _ |
Helper function GetInstanceInfo |
Function | _ |
Path of the file containing the reason of the instance status change. |
Function | _ |
Wrapper around _GetVgSpindlesInfo with sanity checks. |
Function | _ |
Wrapper around _GetVgInfo which checks the storage parameters. |
Function | _ |
Undocumented |
Function | _ |
Calls fn for all names in names and returns a list of dictionaries. |
Function | _ |
Undocumented |
Function | _ |
Undocumented |
Function | _ |
Simple wrapper to return an SshRunner. |
Function | _ |
Retrieves information about a LVM volume group. |
Function | _ |
Retrieves information about spindles in an LVM volume group. |
Function | _ |
Returns the full paths for the private key and certificate. |
Function | _ |
Undocumented |
Function | _ |
Compute the OS log filename for a given instance and operation. |
Function | _ |
Undocumented |
Function | _ |
Opens the underlying block device of a disk. |
Function | _ |
Compute and return the API version of a given OS. |
Function | _ |
Performs a number of tests on a restricted command. |
Function | _ |
Activate a block device for an instance. |
Function | _ |
Check if a device is activated. |
Function | _ |
Remove the block device symlinks belonging to the given instance. |
Function | _ |
Undocumented |
Function | _ |
Execute the master IP address setup script. |
Function | _ |
Serialize a reason trail related to an instance change of state to file. |
Function | _ |
Set up symlinks to a instance's block device. |
Function | _ |
Checks whether given file_storage_dir is valid. |
Function | _ |
Create an OS instance from disk. |
Function | _ |
Verify the existance and validity of the client SSL certificate. |
Function | _ |
Verifies the hvparams. Appends the results to the 'results' list. |
Function | _ |
Verifies the hypervisor. Appends the results to the 'results' list. |
Function | _ |
Verifies the instance list. |
Function | _ |
Verifies the node info. |
Function | _ |
Verifies a whole restricted command and returns its executable filename. |
Function | _ |
Verifies restricted command directory. |
Function | _ |
Verifies a restricted command name. |
Function | _ |
Verifies that the 'authorized_keys' files are not cluttered up. |
Function | _ |
Verifies the state of the SSH key files. |
Constant | _ALLOWED |
denotes which directories are accepted in the _CleanDirectory function |
Constant | _ALLOWED |
denotes which files are accepted in the UploadFile function |
Constant | _BOOT |
Undocumented |
Constant | _IES |
Undocumented |
Constant | _IES |
Undocumented |
Constant | _IES |
Undocumented |
Constant | _LVSLINE |
Undocumented |
Constant | _MASTER |
Undocumented |
Constant | _MASTER |
Undocumented |
Constant | _MAX |
Undocumented |
Constant | _RCMD |
Undocumented |
Constant | _RCMD |
Undocumented |
Constant | _RCMD |
Undocumented |
Constant | _STORAGE |
Undocumented |
Constant | _X509 |
Undocumented |
Constant | _X509 |
Undocumented |
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 |
def ActivateMasterIp(master_params, use_external_mip_script): ¶
Activate the IP address of the master daemon.
Parameters | |
masterobjects.MasterNetworkParameters | network parameters of the master |
use | whether to use an external master IP address setup script |
Raises | |
RPCFail | in case of errors during the IP startup |
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 | the UUID of the node whose key is added |
node | the name of the node whose key is added |
potential | list of node names of potential master candidates; this should match the list of uuids in the public key file |
to | whether the key should be added to the authorized_keys file of all nodes |
to | whether the keys should be added to the public key file |
get | whether the node should add the clusters' public keys to its {ganeti_pub_keys} file |
pub | Undocumented |
ssconf | Undocumented |
noded | Undocumented |
run | Undocumented |
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 of tuples containing the necessary node information for adding their keys |
potential | list of node names of potential master candidates; this should match the list of uuids in the public key file |
pub | Undocumented |
ssconf | Undocumented |
noded | Undocumented |
run | Undocumented |
Extend a mirrored block device.
Parameters | |
parentobjects.Disk | the disk to which we should add children |
newobjects.Disk | the list of children which we should add |
Returns | |
None | Undocumented |
Activate a block device for an instance.
This is a wrapper over _RecursiveAssembleBD.
Returns | |
str or boolean | a tuple with the /dev/... path and the created symlink for primary nodes, and (True, True) for secondary nodes |
Closes the given block devices.
This means they will be switched to secondary mode (in case of DRBD).
Parameters | |
instance | 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 |
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 | |
srcobjects.Disk | the disk object we want to copy from |
targetobjects.Disk | the disk object we want to copy to |
Returns | |
NoneType | None |
Raises | |
RPCFail | in case of failure |
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 | 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 |
excl | Whether 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. |
Check if a device is activated.
If it is, return information about the real device.
Parameters | |
disk:objects.Disk | the disk to find |
Returns | |
None or objects.BlockDevStatus | None if the disk cannot be found, otherwise a the current information |
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 pair (size, spindles), where spindles is None if the device doesn't support that |
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 | |
errors.BlockDeviceError | if any of the disks cannot be found |
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 |
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 |
backingstore | whether 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 | Whether 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 |
Images a block device either by dumping a local file or downloading a URL.
Parameters | |
disk:objects.Disk | the disk object we want to image |
image:string | file path to the disk image be dumped |
size:int | The size in MiB to write |
Returns | |
NoneType | None |
Raises | |
RPCFail | in case of failure |
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 |
Remove a block device.
Parameters | |
disk:objects.Disk | the disk object we should remove |
Returns | |
boolean | the success of the operation |
Note | |
This is intended to be called recursively. |
Shrink a mirrored block device.
Parameters | |
parentobjects.Disk | the disk from which we should remove children |
newobjects.Disk | the list of children which we should remove |
Returns | |
None | Undocumented |
Rename a list of block devices.
Parameters | |
devlist:list of tuples | list 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 | |
boolean | True if all renames succeeded, False otherwise |
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.Disk | the disk to be grown |
info:string | new 'info' metadata |
Returns | |
(status, result) | a tuple with the status of the operation (True/False), and the errors message if status is False |
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 | Undocumented |
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.Disk | the disk to be snapshotted |
snap | the name of the snapshot |
snap | the size of the snapshot |
Returns | |
string | snapshot disk ID as (vg, lv) |
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 |
Check if a list of bridges exist on the current node.
Returns | |
boolean | True if all of them exist, False otherwise |
Change the netmask of the master IP.
Parameters | |
old | the old value of the netmask |
netmask | the new value of the netmask |
master | the master IP |
master | the master network device |
Cleanup after an import or export.
If the import/export daemon is still running it's killed. Afterwards the whole status directory is removed.
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 of the OpenvSwitch to create. |
ovs | Ethernet device for outside connection (can be missing) |
Create file storage directory.
Parameters | |
file | directory to create |
Returns | |
tuple | tuple with first element a boolean indicating wheter dir creation was successful or not |
Creates a new X509 certificate for SSL/TLS.
Parameters | |
validity:int | Validity in seconds |
cryptodir | Undocumented |
Returns | |
tuple; (string, string) | Certificate name and public part |
def DeactivateMasterIp(master_params, use_external_mip_script): ¶
Deactivate the master IP on this node.
Parameters | |
masterobjects.MasterNetworkParameters | network parameters of the master |
use | whether to use an external master IP address setup script |
Raises | |
RPCFail | in case of errors during the IP turndown |
Compute the validity for all ExtStorage Providers.
Parameters | |
top | the 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:
|
Compute the validity for all OSes.
Parameters | |
top | the 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:
|
Ensures the given daemon is running or stopped.
Parameters | |
daemon | name of the daemon (e.g., constants.KVMD) |
run:bool | whether to start or stop the daemon |
Returns | |
bool | 'True' if daemon successfully started/stopped, 'False' otherwise |
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 |
Get export configuration information.
Parameters | |
dest:str | directory containing the export |
Returns | |
objects.SerializableConfigParser | a serializable config file containing the export info |
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.Instance | instance for which the OS definition is exported |
override | if supplied, it overrides the environment on a key-by-key basis that is part of the archive |
Returns | |
string | filepath of the archive |
Write out the export configuration information.
Parameters | |
instance:objects.Instance | the instance which we export, used for saving configuration |
snapobjects.Disk | list of snapshot block devices, which will be used to get the actual name of the dump file |
Returns | |
None | Undocumented |
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 |
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 |
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 of hypervisors to query for instance data |
all | mapping of hypervisor names to hvparams |
Returns | |
dict | dictionary of instance: data, with data having the following keys:
|
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} |
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 | 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 |
Checks if a file exists and returns information related to it.
Currently returned information:
- file size: int, size in bytes
Parameters | |
file | Name of file to examine. |
Returns | |
tuple of bool, dict | Whether the file exists, and a dictionary of information about the file gathered by os.stat. |
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 |
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 | |
instanceobjects.Instance , objects.Node , objects.NodeGroup , HvParams, BeParams | mapping of instance name to parameters necessary for console information retrieval |
get | Undocumented |
Returns | |
dict | dictionary of instance: data, with data having the following keys:
|
Gives back the information about an instance as a dictionary.
Parameters | |
instance:string | the instance name |
hname:string | the hypervisor type of the instance |
hvparams:dict of strings | the instance's hvparams |
Returns | |
dict | dictionary with the following keys:
|
Provides a list of instances.
Parameters | |
hypervisor | the list of hypervisors to query information |
all | a dictionary mapping hypervisor types to respective cluster-wide hypervisor parameters |
get | function 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
|
Provides a list of instances of the given hypervisor.
Parameters | |
hname:string | name of the hypervisor |
hvparams:dict of strings | hypervisor parameters for the given hypervisor |
get | function 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
|
Computes whether an instance can be migrated.
Parameters | |
instance:objects.Instance | object representing the instance to be checked. |
Returns | |
tuple | tuple of (result, description) where:
|
Get the migration status
Parameters | |
instance:objects.Instance | the instance that is being migrated |
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 |
Gives back a hash with different information about the node.
Parameters | |
storage | 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 | 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 |
Compute list of logical volumes and their size.
Parameters | |
vg | 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. |
Hotplug a device
Hotplug is currently supported only for KVM Hypervisor.
Parameters | |
instance:objects.Instance | the instance to which we hotplug a device |
action:string | the hotplug action to perform |
dev | the device type to hotplug |
device:either objects.NIC or objects.Disk | the device object to hotplug |
extra:tuple | extra info used for disk hotplug (disk link, drive uri) |
seq:int | the index of the device from master perspective |
Raises | |
RPCFail | in case instance does not have KVM hypervisor |
Resize an instance's memory.
Parameters | |
instance:objects.Instance | the instance object |
memory:int | new memory amount in MB |
Returns | |
None | Undocumented |
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 | Undocumented |
Reboot an instance.
Parameters | |
instance:objects.Instance | the instance object to reboot |
reboot | the type of reboot, one the following constants:
|
shutdown | maximum timeout for soft shutdown |
reason:list of reasons | the reason trail for this reboot |
Returns | |
None | Undocumented |
Shut an instance down.
Parameters | |
instance:objects.Instance | the instance object |
timeout:integer | maximum timeout for soft shutdown |
reason:list of reasons | the reason trail for this shutdown |
store | whether to store the shutdown reason trail on file |
Returns | |
None | Undocumented |
Note | |
this functions uses polling with a hardcoded timeout. |
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 |
Updates a file in the queue directory.
This is just a wrapper over utils.io.WriteFile
, with proper checking.
Parameters | |
file | the job file name |
content:str | the new job contents |
Returns | |
boolean | the success of the operation |
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 | boolean |
List the volume groups and their size.
Returns | |
dict | dictionary with keys volume name and values the size of the volume |
Migrates an instance to another node.
Parameters | |
cluster | name of the cluster |
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 |
Gather information about an instance to be migrated.
Parameters | |
instance:objects.Instance | the instance definition |
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:dict | instance metadata obtained by calling objects.Instance.ToDict on an instance object |
List all volumes on this node.
Returns | |
list | A list of dictionaries, each having four keys:
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. |
Calculate the basic environment for an os script.
Parameters | |
os | full operating system name (including variant) |
instobjects.OS | operating system for which the environment is being built |
os | the OS parameters |
debug:integer | debug level (0 or 1, for OS Api 10) |
Returns | |
dict | dict of environment variables |
Raises | |
errors.BlockDeviceError | if the block device cannot be found |
Calculate the environment for an os script.
Parameters | |
instance:objects.Instance | target instance for the os script run |
instobjects.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 | |
errors.BlockDeviceError | if the block device cannot be found |
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 | |
name | Undocumented |
base | 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 |
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.
Remove an existing export from the node.
Parameters | |
export:str | the name of the export to remove |
Returns | |
None | Undocumented |
Remove file storage directory.
Remove it only if it's empty. If not log an error and return.
Parameters | |
file | the directory we should cleanup |
Returns | |
tuple (success,) | tuple of one element, success, denoting whether the operation was successful |
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 of the node whose key is removed |
node | name of the node whose key is remove |
master | list of UUIDs of the current master candidates |
potential | list of names of potential master candidates |
master | Undocumented |
keys | a 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 | whether or not the key should be removed from the authorized_keys file |
from | whether or not the key should be remove from the ganeti_pub_keys file |
clear | whether or not the authorized_keys file should be cleared on the node whose keys are removed |
clear | whether to clear the node's ganeti_pub_key file |
pub | Undocumented |
ssconf | Undocumented |
noded | Undocumented |
readd:boolean | whether this is called during a readd operation. |
run | Undocumented |
Returns | |
list of string | list of feedback messages |
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 of information about nodes whose keys are being removed |
master | list of UUIDs of the current master candidates |
potential | list of names of potential master candidates |
master | Undocumented |
keys | a 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 | Undocumented |
ssconf | Undocumented |
noded | Undocumented |
readd:boolean | whether this is called during a readd operation. |
run | Undocumented |
Returns | |
list of string | list of feedback messages |
Rename the file storage directory.
Parameters | |
old | the current path |
new | the name we should rename to |
Returns | |
tuple (success,) | tuple of one element, success, denoting whether the operation was successful |
Renews all SSH keys and updates authorized_keys and ganeti_pub_keys.
Parameters | |
node | list of node UUIDs whose keys should be renewed |
node | list of node names whose keys should be removed. This list should match the node_uuids parameter |
master | list of UUIDs of master candidates or master node |
potential | Undocumented |
oldconstants.SSHK_ALL | the type of SSH key already present on nodes |
newconstants.SSHK_ALL | the type of SSH key to be generated |
new | the length of the key to be generated |
ganeti | file path of the the public key file |
ssconf | Undocumented |
noded | path of the noded SSL certificate file |
run | function to run commands on remote nodes via SSH |
Raises | |
ProgrammerError | if 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. |
Decorator that runs hooks before and after the decorated function.
Parameters | |
hook | opcode of the hook |
hooks | path of the hooks |
env | 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 |
Executes oob_program with given command on given node.
Parameters | |
oob | 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 |
Run the OS rename script for an instance.
Parameters | |
instance:objects.Instance | Instance whose OS is to be installed |
old | previous instance name |
debug:integer | debug level, passed to the OS scripts |
Returns | |
boolean | the success of the operation |
Executes a restricted command after performing strict tests.
Parameters | |
cmd:string | Command name |
_lock | Undocumented |
_lock | Undocumented |
_path | Undocumented |
_sleep | Undocumented |
_prepare | Undocumented |
_runcmd | Undocumented |
_enabled | Undocumented |
Returns | |
string | Command output |
Raises | |
RPCFail | In case of an error |
Creates or removes the watcher pause file.
Parameters | |
until:None or number | Unix timestamp saying until when the watcher shouldn't run |
_filename | Undocumented |
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 |
Start an instance.
Parameters | |
instance:objects.Instance | pause instance at startup? |
startup | Undocumented |
reason:list of reasons | the reason trail for this startup |
store | whether to store the shutdown reason trail on file |
Returns | |
None | Undocumented |
Activate local node as master node.
The function will start the master daemons (ganeti-masterd and ganeti-rapi).
Parameters | |
no | whether to start ganeti-masterd without a node vote but still non-interactively |
Returns | |
None | Undocumented |
Stop the master daemons on this node.
Stop the master daemons (ganeti-masterd and ganeti-rapi) on this node.
Returns | |
None | Undocumented |
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 | 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 | Undocumented |
Validates the given hypervisor parameters.
Parameters | |
hvname:string | the hypervisor name |
hvparams:dict | the hypervisor parameters to be validated |
Returns | |
None | Undocumented |
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, some of which may be private. |
force | Undocumented |
Returns | |
boolean | True if the validation passed, or False if the OS was not found and required was false |
Verify master IP is reachable.
Parameters | |
my | name of the node this test is running on |
test | configuration for test as passed from LUClusterVerify() in what[constants.NV_MASTERIP] |
Returns | |
bool or None | Boolean test result, None if skipped |
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:
|
cluster | the cluster's name |
all | a dictionary mapping hypervisor names to hvparams |
Returns | |
dict | a dictionary with the same keys as the input dict, and values representing the result of the checks |
Verify nodes are reachable.
Parameters | |
my | name of the node this test is running on |
test | configuration for test as passed from LUClusterVerify() in what[constants.NV_NODENETTEST] |
Returns | |
dict | a dictionary with node names as keys and error messages as values |
Looks up and applies the correct function to calculate free and total storage for the given storage type.
Parameters | |
storage | the storage type for which the storage shall be reported. |
storage | identifier of a storage unit, e.g. the volume group name of an LVM storage unit |
*args:any | various 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 | |
NotImplementedError | for storage types who don't support space reporting yet |
Builds environment variables for master IP hooks.
Parameters | |
masterobjects.MasterNetworkParameters | network parameters of the master |
use | whether to use an external master IP address setup script (unused, but necessary per the implementation of the _RunLocalHooks decorator) |
Build the list of allowed upload files.
This is abstracted so that it's built only once at module import time.
Get the URI for the device.
Parameters | |
instance:objects.Instance | the instance which disk belongs to |
disk:objects.Disk | the target disk object |
device:bdev.BlockDev | the corresponding BlockDevice |
Returns | |
string | the device uri if any else None |
Check that PVs are not shared among LVs
Parameters | |
pviobjects.LvmPvInfo objects | information about the PVs |
Returns | |
list of tuples (string, list of strings) | offending volumes, as tuples: (pv_name, [lv1_name, lv2_name...]) |
Check within a disk and its children if there is a plain disk type.
Parameters | |
disk:objects.Disk | the disk we are checking |
Returns | |
bool | whether or not there is a plain disk type |
Check whether a list of parameters is supported by the OS.
Parameters | |
osobjects.OS | OS object to check |
parameters:list | the list of parameters to check |
Check whether an OS name conforms to the os variants specification.
Parameters | |
osobjects.OS | OS object to check |
name:string | OS name passed by the user, to check for validity |
Returns | |
NoneType | None |
Raises | |
RPCFail | if OS variant is not valid |
Performs sanity checks for storage parameters.
Parameters | |
params:list | list of storage parameters |
num | expected number of parameters |
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 |
Common checks for restricted command file system directories and files.
Parameters | |
path:string | Path to check |
owner | None 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 |
Unpacks data compressed by the RPC client.
Parameters | |
data:list or tuple | Data sent by RPC client |
Returns | |
str | Decompressed data |
This function images a device using a downloaded image file.
Parameters | |
source | URL of image to dump to disk |
target | path of the device to image |
size:int | maximum size in MiB to write (data source might be smaller) |
Returns | |
NoneType | None |
Raises | |
RPCFail | in case of download or write failures |
This function images/wipes the device using a local file.
Parameters | |
source | path of the image or data source (e.g., "/dev/zero") |
target | path of the device to image/wipe |
offset:int | offset in MiB in the output file |
size:int | maximum size in MiB to write (data source might be smaller) |
truncate:bool | whether the file should be truncated |
Returns | |
None | |
Raises | |
RPCFail | in case of failure |
Checks whether the given filename is in the queue directory.
Parameters | |
file | the file name we should check |
Returns | |
None | Undocumented |
Raises | |
RPCFail | if the file is not valid |
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 |
*args | Undocumented |
**kwargs | Undocumented |
Finds attached BlockDev
s for the given disks.
Parameters | |
disks:list of objects.Disk | the disk objects we need to find |
Returns | |
list of BlockDev objects or None if a given disk was not found or was no attached. |
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.Instance | the instance whose disks we should assemble |
Returns | |
list | list of (disk_object, link_name, drive_uri) |
Generates the root SSH key pair on the node.
Parameters | |
node | UUID of the node whose key is removed |
node | name of the node whose key is remove |
ssh | mapping of node names to their SSH port |
sshconstants.SSHK_ALL | the type of SSH key to be generated |
ssh | the length of the key to be generated |
pub | Undocumented |
ssconf | Undocumented |
noded | Undocumented |
run | Undocumented |
suffix | Undocumented |
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. |
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 | |
name | Undocumented |
hvparams:dict of string | the hypervisor's hvparams |
get | Undocumented |
Retrieves node information for all hypervisors.
See _GetHvInfo for information on the output.
Parameters | |
hv | list of pairs of a hypervisor's name and its hvparams |
get | Undocumented |
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 |
Path of the file containing the reason of the instance status change.
Parameters | |
instance | The name of the instance |
Returns | |
string | The path of the file |
Wrapper around _GetVgInfo which checks the storage parameters.
Parameters | |
name:string | name of the volume group |
params:list | list of storage parameters, which in this case should be containing only one for exclusive storage |
Calls fn for all names in names and returns a list of dictionaries.
Returns | |
None or list of dict | Undocumented |
Simple wrapper to return an SshRunner.
Parameters | |
cluster | the cluster name, which is needed by the SshRunner constructor |
Returns | |
ssh.SshRunner | an SshRunner instance |
Retrieves information about spindles in an LVM volume group.
Parameters | |
name:string | VG name |
excl | exclusive storage |
info | Undocumented |
Returns | |
dict | dictionary whose keys are "name", "vg_free", "vg_size" for VG name, free spindles, total spindles respectively |
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 | 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 |
Opens the underlying block device of a disk.
Parameters | |
disk:objects.Disk | the disk object we want to open |
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 | 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 valid versions or an error message |
Performs a number of tests on a restricted command.
Parameters | |
path:string | Directory containing restricted commands |
cmd:string | Command name |
_verify | Undocumented |
_verify | Undocumented |
_verify | Undocumented |
Returns | |
Same as _VerifyRestrictedCmd |
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 | if we should make the block device read/write |
Returns | |
the assembled device or None (in case no device was assembled) | |
Raises | |
errors.BlockDeviceError | in case there is an error during the activation of the children or the device itself |
Note | |
this function is called recursively. |
Check if a device is activated.
If so, return information about the real device.
Parameters | |
disk:objects.Disk | the disk object we need to find |
lvs | Undocumented |
Returns | |
None if the device can't be found, otherwise the device instance |
Execute the master IP address setup script.
Parameters | |
masterobjects.MasterNetworkParameters | network parameters of the master |
action:string | action to pass to the script. Must be one of backend._MASTER_START or backend._MASTER_STOP |
use | whether to use an external master IP address setup script |
Raises | |
backend.RPCFail | if there are errors during the execution of the script |
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 | The name of the instance |
trail:list of reasons | reason trail |
Returns | |
None | Undocumented |
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 | the name of the target instance |
device | path of the physical block device, on the node |
idx | the disk index |
Returns | |
absolute path to the disk's symlink |
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 | the path to check |
Returns | |
the normalized path if valid, None otherwise |
Create an OS instance from disk.
This function will return an OS instance if the given name is a valid OS name.
Parameters | |
name | Undocumented |
base | 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 |
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.
Verifies the hvparams. Appends the results to the 'results' list.
Parameters | |
what:dict | a dictionary of things to check |
vm | whether or not this node is vm capable |
result:dict | dictionary of verification results; results of the verifications in this function will be added here |
get | function to retrieve the hypervisor, to improve testability |
Verifies the hypervisor. Appends the results to the 'results' list.
Parameters | |
what:dict | a dictionary of things to check |
vm | whether or not this node is vm capable |
result:dict | dictionary of verification results; results of the verifications in this function will be added here |
all | dictionary mapping hypervisor names to hvparams |
get | function to retrieve the hypervisor, to improve testability |
Verifies the instance list.
Parameters | |
what:dict | a dictionary of things to check |
vm | whether or not this node is vm capable |
result:dict | dictionary of verification results; results of the verifications in this function will be added here |
all | dictionary mapping hypervisor names to hvparams |
Verifies the node info.
Parameters | |
what:dict | a dictionary of things to check |
vm | whether or not this node is vm capable |
result:dict | dictionary of verification results; results of the verifications in this function will be added here |
all | dictionary mapping hypervisor names to hvparams |
Verifies a whole restricted command and returns its executable filename.
Parameters | |
path:string | Directory containing restricted commands |
cmd:string | Command name |
_owner | Undocumented |
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 |
Verifies restricted command directory.
Parameters | |
path:string | Path to check |
_owner | Undocumented |
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 |
Verifies a restricted command name.
Parameters | |
cmd:string | Command 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 |
Verifies that the 'authorized_keys' files are not cluttered up.
Parameters | |
node | list of nodes of the cluster associated with a couple of flags: (uuid, name, is_master_candidate, is_potential_master_candidate, online) |
my | name of this node |
Verifies the state of the SSH key files.
Parameters | |
node | list of nodes of the cluster associated with a couple of flags: (uuid, name, is_master_candidate, is_potential_master_candidate, online) |
my | name of this node |
sshconstants.SSHK_ALL | type of key used on nodes |
ganeti | filename of the public keys file |
denotes which directories are accepted in the _CleanDirectory
function
Value |
|
denotes which files are accepted in the UploadFile
function
Value |
|
Undocumented
Value |
|
Undocumented
Value |
|
Undocumented
Value |
|