Trees | Indices | Help |
|
---|
|
Ganeti utility module.
This module holds functions that can be used in both daemons (all) and the command line scripts.
|
|||
RunResult Holds the result of running external programs. |
|||
ShellWriter Helper class to write scripts with indentation. |
|||
FdConditionWaiterHelper Retry helper for WaitForFdCondition. |
|||
LogFileHandler Log handler that doesn't fallback to stderr. |
|||
RetryTimeout Retry loop timed out. |
|||
RetryAgain Retry again. |
|||
_RetryDelayCalculator Calculator for increasing delays. |
|||
FileLock Utility class for file locks. |
|||
LineSplitter Splits data chunks into lines separated by newline. |
|||
SignalWakeupFd | |||
SignalHandler Generic signal handler class. |
|||
FieldSet A simple field set. |
|
|||
|
|||
RunResult |
|
||
|
|||
|
|||
int |
|
||
|
|||
|
|||
tuple |
|
||
int |
|
||
|
|||
|
|||
|
|||
list of tuples |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
str |
|
||
dict |
|
||
|
|||
string |
|
||
boolean |
|
||
set |
|
||
string |
|
||
bool |
|
||
int |
|
||
|
|||
None or str |
|
||
|
|||
dict |
|
||
boolean |
|
||
list |
|
||
|
|||
boolean |
|
||
str |
|
||
str |
|
||
|
|||
list of int |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
str |
|
||
str |
|
||
str |
|
||
list |
|
||
|
|||
str |
|
||
str |
|
||
|
|||
str |
|
||
None or int |
|
||
|
|||
boolean |
|
||
|
|||
|
|||
int |
|
||
int or None |
|
||
int or None |
|
||
list |
|
||
str |
|
||
boolean |
|
||
|
|||
|
|||
|
|||
int |
|
||
str |
|
||
|
|||
|
|||
int |
|
||
|
|||
|
|||
str or None |
|
||
None or str |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
string |
|
||
|
|||
tuple; (OpenSSL.crypto.X509, string) |
|
||
|
|||
bool |
|
||
str |
|
||
string |
|
||
|
|||
tuple; (value in dictionary, matched groups as list) |
|
||
int |
|
||
int |
|
||
list of tuples |
|
||
int |
|
||
bool |
|
||
bool |
|
||
|
|||
|
|||
|
|||
string |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
ctypes = None
|
|||
_locksheld = []
|
|||
_re_shell_unquoted = re.compile('^[-.,=:/_+@A-Za-z0-9]+$')
|
|||
debug_locks = False
|
|||
no_fork = False when set to True, RunCmd is disabled |
|||
_RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
|
|||
HEX_CHAR_RE = r"[a-zA-Z0-9]"
|
|||
VALID_X509_SIGNATURE_SALT = re.compile("^%s+$" % HEX_CHAR_RE,
|
|||
X509_SIGNATURE = re.compile(r"^%s:\s*(?P<salt>%s+)/(?P<sign>%s
|
|||
_VALID_SERVICE_NAME_RE = re.compile("^[-_.a-zA-Z0-9]{1,128}$")
|
|||
UUID_RE = re.compile('^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-' '
|
|||
_MCL_CURRENT = 1
|
|||
_MCL_FUTURE = 2
|
|||
_MAC_CHECK = re.compile("^([0-9a-f]{2}:){5}[0-9a-f]{2}$", re.I) MAC checker regexp |
|||
RETRY_REMAINING_TIME = object() Special delay to specify whole remaining timeout |
Imports: os, sys, time, subprocess, re, socket, tempfile, shutil, errno, pwd, itertools, select, fcntl, resource, logging, signal, OpenSSL, datetime, calendar, hmac, collections, StringIO, errors, constants, compat
|
Execute a (shell) command. The command should not read from its standard input, as it will be closed.
|
Setup a daemon's environment. This should be called between the first and second fork, due to setsid usage.
|
Setups up a daemon's file descriptors.
|
Start a daemon process after forking twice.
|
Possibly write an error message to a fd.
|
Run a command and return its output.
|
Run a command and save its output to a file.
|
Sets or unsets the close-on-exec flag on a file descriptor.
|
Sets or unsets the O_NONBLOCK flag on on a file descriptor.
|
Run Scripts or programs in a directory
|
Remove a file ignoring some errors. Remove a file, ignoring non-existing ones or directories. Other errors are passed.
|
Remove an empty directory. Remove a directory, ignoring non-existing ones. Other errors are passed. This includes the case, where the directory is not empty, so it can't be removed.
|
Renames a file.
|
Super-mkdir; create a leaf directory and all intermediate ones. This is a wrapper around |
Resets the random name generator of the tempfile module. This function should be called after |
Compute the fingerprint of a file. If the file does not exist, a None will be returned instead.
|
Compute fingerprints for a list of files.
|
Force the values of a dict to have certain types.
|
Returns the path for a PID's proc status file.
|
Check if a given pid exists on the system.
Note: zombie status is not handled, so zombie processes will be returned as alive |
Parse a rendered sigset_t value. This is the opposite of the Linux kernel's fs/proc/array.c:render_sigset_t function.
|
Retrieves a field from the contents of a proc status file.
|
Checks whether a process is handling a signal.
|
Read a pid from a file.
|
Reads a locked PID file. This can be used together with StartDaemon.
|
Try to match a name against a list. This function will try to match a name like test1 against a list like
|
Validate the given service name.
|
List volume groups and their size
|
Check whether the given bridge exists in the system
|
Sort a list of strings based on digit and non-digit groupings. Given a list of names The sort algorithm breaks each name in groups of either only-digits or no-digits. Only the first eight such groups are considered, and after that we just use what's left of the string.
|
Try to convert a value ignoring errors. This function tries to apply function fn to val. If no
|
Verifies is the given word is safe from the shell's p.o.v. This means that we can pass this to a command via the shell and be sure that it doesn't alter the command line and is passed as such to the actual command. Note that we are overly restrictive here, in order to be on the safe side.
|
Build a safe shell command line from the given arguments. This function will check all arguments in the args list so that they are valid shell parameters (i.e. they don't contain shell metacharacters). If everything is ok, it will return the result of template % args.
|
Formats an incoming number of MiB with the appropriate unit.
|
Tries to extract number and scale from the given string. Input must be in the format |
Parse a CPU mask definition and return the list of CPU IDs. CPU mask format: comma-separated list of CPU IDs or dash-separated ID ranges Example: "0-2,5" -> "0,1,2,5"
|
Adds an SSH public key to an authorized_keys file.
|
Removes an SSH public key from an authorized_keys file.
|
Sets the name of an IP address and hostname in /etc/hosts.
|
Wrapper around SetEtcHostsEntry.
|
Removes a hostname from /etc/hosts. IP addresses without names are removed from the file.
|
Wrapper around RemoveEtcHostsEntry.
|
Returns the current time formatted for filenames. The format doesn't contain colons as some shells and applications them as separators. |
Creates a backup of a file.
|
Quotes shell argument according to POSIX.
|
Quotes a list of shell arguments.
|
Returns a list of visible files in a directory.
|
Try to get the homedir of the given user. The user can be passed either as a string (denoting the name) or as an integer (denoting the user id). If the user is not found, the 'default' argument is returned, which defaults to None. |
Returns a random UUID.
Note: This is a Linux-specific method as it uses the /proc filesystem. |
Generates a random secret. This will generate a pseudo-random secret returning an hex string (so that it can be used where an ASCII string is needed).
|
Make required directories, if they don't exist.
|
Reads a file.
|
(Over)write a file atomically. The file_name and either fn (a function taking one argument, the file descriptor, and which should write the data to it) or data (the contents of the file) must be passed. The other arguments are optional and allow setting the file mode, owner and group, and the mtime/atime of the file. If the function doesn't raise an exception, it has succeeded and the target file has the new contents. If the function has raised an exception, an existing target file should be unmodified and the temporary file should be removed.
|
Returns the file 'id', i.e. the dev/inode and mtime information. Either the path to the file or the fd must be given.
|
Verifies that two file IDs are matching. Differences in the inode/device are not accepted, but and older timestamp for fi_disk is accepted.
|
Wraper over WriteFile that locks the target file. By keeping the target file locked during WriteFile, we ensure that cooperating writers will safely serialise access to the file.
|
Return the first non-empty line from a file.
|
Returns the first non-existing integer from seq. The seq argument should be a sorted list of positive integers. The first time the index of an element is smaller than the element value, the index will be returned. The base argument is used to start at a different offset, i.e.
Example:
|
Waits for a condition to occur on the socket. Immediately returns at the first interruption.
|
Waits for a condition to occur on the socket. Retries until the timeout is expired, even if interrupted.
|
Returns a list with unique elements. Element order is preserved.
|
Normalizes and check if a MAC address is valid. Checks whether the supplied MAC address is formally correct, only accepts colon separated format. Normalize it to all lower.
|
Sleep for a fixed amount of time.
|
Close a file descriptor ignoring errors.
|
Close file descriptors. This closes all file descriptors above 2 (i.e. except stdin/out/err).
|
Lock current process' virtual address space into RAM. This is equivalent to the C call mlockall(MCL_CURRENT|MCL_FUTURE), see mlock(2) for more details. This function requires ctypes module.
|
Daemonize the current process. This detaches the current process from the controlling terminal and runs it in the background as a daemon.
|
Compute a ganeti pid file absolute path
|
Write the current process pidfile.
|
Remove the current process pidfile. Any errors are ignored.
|
Kill a process given by its pid.
|
Look for a filesystem object in a given path. This is an abstract method to search for filesystem object (files, dirs) under a given search path.
|
Checks if the volume group list is valid. The function will check if a given volume group is in the list of volume groups and has a minimum size.
|
Splits time as floating point number into a tuple.
|
Merges a tuple into time as a floating point number.
|
Configures the logging module.
|
Check whether a path is absolute and also normalized This avoids things like /dir/../../other/path to be valid. |
Safe-join a list of path components. Requirements:
|
Return the last lines from a file.
Note: this function will only read and parse the last 4KB of the file; if the lines are very long, it could be that less than the requested number of lines are returned |
Parses an ASN1 GENERALIZEDTIME timestamp as used by pyOpenSSL.
|
Returns the validity period of the certificate.
|
Verifies certificate validity.
|
Verifies a certificate for LUVerifyCluster.
|
Sign a X509 certificate. An RFC822-like signature header is added in front of the certificate.
|
Verifies a signed X509 certificate.
|
Calculates the HMAC-SHA1 digest of a text. HMAC is defined in RFC2104.
|
Verifies the HMAC-SHA1 digest of a text. HMAC is defined in RFC2104.
|
Return a 'safe' version of a source string. This function mangles the input string and returns a version that should be safe to display/encode as ASCII. To this end, we first convert it to ASCII using the 'backslashreplace' encoding which should get rid of any non-ASCII chars, and then we process it through a loop copied from the string repr sources in the python; we don't use string_escape anymore since that escape single quotes and backslashes too, and that is too much; and that escaping is not stable, i.e. string_escape(string_escape(x)) != string_escape(x).
|
Split and unescape a string based on a given separator. This function splits a string based on a separator where the separator itself can be escape in order to be an element of the elements. The escaping rules are (assuming coma being the separator):
|
Nicely join a set of identifiers.
|
Tries to find an item in a dictionary matching a name. Callers have to ensure the data names aren't contradictory (e.g. a regexp that matches a string). If the name isn't a direct key, all regular expression objects in the dictionary are matched against it.
|
Converts bytes to mebibytes.
|
Calculates the size of a directory recursively.
|
Returns the list of mounted filesystems. This function is Linux-specific.
|
Returns the total and free space on a filesystem.
|
Runs a function in a separate process. Note: Only boolean return values are supported.
|
Ignores ESRCH when calling a process-related function. ESRCH is raised when a process is not found.
|
Locks a file using POSIX locks.
|
Formats a time value.
|
Formats seconds for easier reading.
|
Reads the watcher pause file.
|
Call a function repeatedly until it succeeds. The function
|
Generates a self-signed X509 certificate.
|
Legacy function to generate self-signed X509 certificate.
|
Signal Handled decoration. This special decorator installs a signal handler and then calls the target function. The function must accept a 'signal_handlers' keyword argument, which will contain a dict indexed by signal number, with SignalHandler objects as values. The decorator can be safely stacked with iself, to handle multiple signals with different handlers.
|
|
VALID_X509_SIGNATURE_SALT
|
X509_SIGNATURE
|
UUID_RE
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Dec 20 13:26:37 2010 | http://epydoc.sourceforge.net |