Package utils
source code
Ganeti utility module.
This module holds functions that can be used in both daemons (all) and
the command line scripts.
|
|
|
|
|
|
|
|
dict
|
|
boolean
|
|
|
|
list of int
|
|
list of lists of int
|
|
|
|
int
|
|
int or None
|
|
int or None
|
|
bool
|
|
bool
|
|
|
|
|
|
|
EpochNano()
Return the current timestamp expressed as number of nanoseconds since
the unix epoch |
source code
|
|
tuple; (value in dictionary, matched groups as list)
|
|
list of tuples
|
|
|
|
|
TimeoutExpired(epoch,
timeout,
_time_fn=time.time)
Checks whether a timeout has expired. |
source code
|
|
|
|
bool
|
|
bool
|
|
|
|
|
|
|
_VALID_SERVICE_NAME_RE = re.compile("^[-_.a-zA-Z0-9]{1,128}$")
|
|
UUID_RE = re.compile(constants.UUID_REGEX)
|
Imports:
JoinDisjointDicts,
UniqueSequence,
FindDuplicates,
text,
SequenceToDict,
RunningTimeout,
FlatToDict,
itertools,
NiceSortKey,
GetRepeatedKeys,
InvertDict,
InsertAtPos,
FileLock,
retry,
LockFile,
FingerprintFiles,
Sha1Hmac,
VerifySha1Hmac,
hmac,
NewUUID,
ErrnoOrStr,
WritePidFile,
KP_NEVER,
RemoveDir,
FileStatHelper,
shutil,
VerifyFileID,
BytesToMebibyte,
ListVisibleFiles,
TailFile,
IsNormAbsPath,
grp,
SafeWriteFile,
IsBelowDir,
RemoveFile,
CreateBackup,
GetFileID,
RenameFile,
GetFilesystemStats,
CanRead,
FindFile,
Makedirs,
KP_IF_EXISTS,
stat,
CalculateDirectorySize,
PathJoin,
URL_RE,
ReadFile,
pwd,
ReadOneLineFile,
EnsureDirs,
KEEP_PERMS_VALUES,
ReadPidFile,
ReadWatcherPauseFile,
KP_ALWAYS,
filelock,
MakeDirWithPerm,
IsUserInGroup,
TemporaryFileManager,
WriteFile,
TimestampForFilename,
DaemonPidFileName,
IsUrl,
EnforcePermission,
ReadLockedPidFile,
struct,
NiceSort,
LiveLock,
LiveLockName,
GuessLockfileFor,
SetupToolLogging,
SetupLogging,
CheckVolumeGroupSize,
LvmExclusiveTestBadPvSizes,
LvmExclusiveCheckNodePvs,
ctypes,
Mlockall,
RemoveEtcHostsEntry,
AddHostToEtcHosts,
SetEtcHostsEntry,
RemoveHostFromEtcHosts,
algo,
GetProcCmdline,
WriteErrorToFD,
CloseFDs,
RunCmd,
utils_algo,
SetupDaemonFDs,
DisableFork,
IsDaemonAlive,
StartDaemon,
SetupDaemonEnv,
KillProcess,
RunResult,
utils_wrapper,
RunInSeparateProcess,
IsProcessHandlingSignal,
IsProcessAlive,
utils_retry,
Daemonize,
RunParts,
resource,
subprocess,
StringIO,
signal,
SimpleRetry,
RetryAgain,
RETRY_REMAINING_TIME,
CountRetry,
Retry,
RetryByNumberOfTimes,
RetryTimeout,
VerifyCertificate,
x509,
IsCertificateSelfSigned,
uuid_module,
UuidToInt,
GetCertificateDigest,
io,
GenerateNewClientSslCert,
GenerateNewSslCert,
LookupSpaceInfoByDiskTemplate,
utils_process,
osminor,
IsFileStorageEnabled,
LookupSpaceInfoByStorageType,
GetDiskLabels,
ReleaseBdevPartitionMapping,
CreateBdevPartitionMapping,
IsSharedFileStorageEnabled,
GetDiskTemplatesOfStorageTypes,
DiskTemplateSupportsSpaceReporting,
IsDiskTemplateEnabled,
GetStorageUnits,
IsLvmEnabled,
LvmGetsEnabled,
GenerateSecret,
DnsNameGlobPattern,
EscapeAndJoin,
ShellWriter,
FormatOrdinal,
IsValidShellParam,
compat,
UnescapeAndSplit,
Truncate,
FilterEmptyLinesAndComments,
FormatKeyValue,
MatchNameComponent,
LineSplitter,
collections,
BuildShellCmd,
NormalizeAndValidateThreeOctetMacPrefix,
SafeEncode,
ShellQuoteArgs,
ParseUnit,
FormatUnit,
ShellQuote,
FormatTime,
NormalizeAndValidateMac,
CommaJoin,
ShellCombineCommands,
FormatSeconds,
fcntl,
IsExecutable,
socket,
IgnoreSignals,
tempfile,
ResetTempfileModule,
SetNonblockFlag,
sys,
SetCloseOnExecFlag,
RetryOnSignal,
GetClosedTempfile,
TestDelay,
IgnoreProcessNotFound,
os,
select,
CloseFdNoError,
SplitVersion,
IsCorrectConfigVersion,
ParseVersion,
BuildVersion,
UpgradeRange,
IsEqual,
FIRST_UPGRADE_VERSION,
ShouldCfgdowngrade,
IsBefore,
CURRENT_VERSION,
datetime,
LoadSignedX509Certificate,
calendar,
X509_SIGNATURE,
ExtractX509Certificate,
errno,
X509_CERT_SIGN_DIGEST,
OpenSSL,
re,
SignX509Certificate,
HEX_CHAR_RE,
GenerateSelfSignedX509Cert,
VALID_X509_SIGNATURE_SALT,
GetX509CertValidity,
utils_hash,
X509CertKeyCheck,
time,
GenerateSelfSignedSslCert,
utils_io,
GenerateSignedSslCert,
constants,
GenerateSignedX509Cert,
logging,
utils_text,
VerifyX509Certificate,
pathutils,
CheckNodeCertificate,
bitarray,
GetFreeSlot,
errors
ForceDictType(target,
key_types,
allowed_values=None)
| source code
|
Force the values of a dict to have certain types.
- Parameters:
target (dict) - the dict to update
key_types (dict) - dict mapping target dict keys to types in
constants.ENFORCEABLE_TYPES
allowed_values (list) - list of specially allowed values
|
Validate the given service name.
- Parameters:
name (number or string) - Service name or port specification
|
_ComputeMissingKeys(key_path,
options,
defaults)
| source code
|
Helper functions to compute which keys a invalid.
- Parameters:
key_path - The current key path (if any)
options - The user provided options
defaults - The default dictionary
- Returns:
- A list of invalid keys
|
Verify a dict has only keys set which also are in the defaults
dict.
- Parameters:
options - The user provided options
defaults - The default dictionary
- Raises:
|
List volume groups and their size
- Returns: dict
- Dictionary with keys volume name and values the size of the
volume
|
Check whether the given bridge exists in the system
- Parameters:
bridge (str) - the bridge name to check
- Returns: boolean
- True if it does
|
Try to convert a value ignoring errors.
This function tries to apply function fn to val. If no
ValueError or TypeError exceptions are raised,
it will return the result, else it will return the original value. Any
other exceptions are propagated to the caller.
- Parameters:
fn (callable) - function to apply to the value
val - the value to be converted
- Returns:
- The converted value if the conversion was successful, otherwise
the original value.
|
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"
- Parameters:
cpu_mask (str) - CPU mask definition
- Returns: list of int
- list of CPU IDs
|
Parse a multiple CPU mask definition and return the list of CPU
IDs.
CPU mask format: colon-separated list of comma-separated list of CPU
IDs or dash-separated ID ranges, with optional "all" as CPU
value Example: "0-2,5:all:1,5,6:2" -> [ [ 0,1,2,5 ], [ -1 ],
[ 1, 5, 6 ], [ 2 ] ]
- Parameters:
cpu_mask (str) - multiple CPU mask definition
- Returns: list of lists of int
- list of lists of CPU IDs
|
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 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.
[3, 4, 6] with offset=3 will return 5.
Example: [0, 1, 3] will return 2.
- Parameters:
seq (sequence) - the sequence to be analyzed.
base (int) - use this value as the base index of the sequence
- Returns: int
- the first non-used index in the sequence
|
SingleWaitForFdCondition(fdobj,
event,
timeout)
| source code
|
Waits for a condition to occur on the socket.
Immediately returns at the first interruption.
- Parameters:
fdobj (integer or object supporting a fileno() method) - entity to wait for events on
event (integer) - ORed condition (see select module)
timeout (float or None) - Timeout in seconds
- Returns: int or None
- None for timeout, otherwise occured conditions
|
Waits for a condition to occur on the socket.
Retries until the timeout is expired, even if interrupted.
- Parameters:
fdobj (integer or object supporting a fileno() method) - entity to wait for events on
event (integer) - ORed condition (see select module)
timeout (float or None) - Timeout in seconds
- Returns: int or None
- None for timeout, otherwise occured conditions
|
Check for and start daemon if not alive.
- Parameters:
name (string) - daemon name
- Returns: bool
- 'True' if daemon successfully started, 'False' otherwise
|
Stop daemon
- Parameters:
name (string) - daemon name
- Returns: bool
- 'True' if daemon successfully stopped, 'False' otherwise
|
Splits time as floating point number into a tuple.
- Parameters:
value (int or float) - Time in seconds
- Returns:
- Tuple containing (seconds, microseconds)
|
Merges a tuple into time as a floating point number.
- Parameters:
timetuple (tuple) - Time as tuple, (seconds, microseconds)
- Returns:
- Time as a floating point number expressed in seconds
|
Return the current timestamp expressed as number of nanoseconds since
the unix epoch
- Returns:
- nanoseconds since the Unix epoch
|
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.
- Parameters:
data (dict) - Dictionary containing data
name (string) - Name to look for
- Returns: tuple; (value in dictionary, matched groups as list)
|
Returns the list of mounted filesystems.
This function is Linux-specific.
- Parameters:
filename - path of mounts file (/proc/mounts by default)
- Returns: list of tuples
- list of mount entries (device, mountpoint, fstype, options)
|
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.
- Parameters:
signums (list) - signals to intercept
|
Validate instance device names.
Check that a device container contains only unique and valid
names.
- Parameters:
kind (string) - One-word item description
container (list) - Container containing the devices
|
Checks if the instance has only disks of any of the dev_types.
- Parameters:
disks_info (list of Disk) - all the disks of the instance.
dev_types (list of disk templates) - the disk type required.
- Returns: bool
- True iff the instance only has disks of type dev_type.
|
Checks if the instance has some disks of any types in dev_types.
- Parameters:
disks_info (list of Disk) - all the disks of the instance.
dev_types (list of disk template) - the disk type required.
- Returns: bool
- True if the instance has disks of type dev_types or the instance
has no disks and the dev_types allow DT_DISKLESS.
|
Gives a summary disk template from disk devtypes.
- Parameters:
disk_types (list of string) - all the dev_types of the instance. @rtype disk template @returns
the summarized disk template of the disk types.
|
Gives a summary disk template from disks.
- Parameters:
disks_info (list of Disk) - all the disks of the instance. @rtype disk template @returns the
summarized disk template of the disk types.
|