glideinwms.lib package¶
Submodules¶
glideinwms.lib.classadSupport module¶
This module describes base classes for classads and advertisers
- class glideinwms.lib.classadSupport.Classad(adType, advertiseCmd, invalidateCmd)[source]¶
Bases:
object
Base class describing a classad.
- adParams¶
- try:
self.adParams
- except Exception:
self.adParams = {}
- update(params_dict, prefix='')[source]¶
Update or Add ClassAd attributes
- Parameters:
params_dict – new attributes
prefix – prefix used for the attribute names (Default: “”)
- writeToFile(filename, append=True)[source]¶
Write a ClassAd to file, adding a blank line if in append mode to separate the ClassAd
There can be no empty line at the beginning of the file: https://htcondor-wiki.cs.wisc.edu/index.cgi/tktview?tn=5147
- Parameters:
filename – file to write to
append – write mode if False, append if True (Default)
- class glideinwms.lib.classadSupport.ClassadAdvertiser(pool=None, multi_support=False, tcp_support=False)[source]¶
Bases:
object
Base Class to handle the advertisement of classads to condor pools. It contains a dictionary of classads keyed by the classad name and functions to do advertisement and invalidation of classads
- addClassad(name, ad_obj)[source]¶
Adds the classad to the classad dictionary
@type name: string @param name: Name of the classad @type ad_obj: ClassAd @param ad_obj: Actual classad object
- advertiseClassad(ad)[source]¶
Advertise the classad to the pool
@type ad: string @param ad: Name of the classad
- advertiseClassads(ads=None)[source]¶
Advertise multiple classads to the pool
@type ads: list @param ads: classad names to advertise
- classadToFile(ad)[source]¶
Write classad to the file and return the filename
@type ad: string @param ad: Name of the classad
@rtype: string @return: Name of the file
- classadsToFile(ads)[source]¶
Write multiple classads to a file and return the filename. Use only when multi advertise is supported by condor.
@type ads: list @param ads: Classad names
@rtype: string @return: Filename containing all the classads to advertise
- doAdvertise(fname)[source]¶
Do the actual advertisement of classad(s) in the file
@type fname: string @param fname: File name containing classad(s)
- getAllClassads()[source]¶
Return all the known classads
@rtype: string @return: All the known classads delimited by empty line
- getUniqClassadFilename()[source]¶
Return a uniq file name for advertising/invalidating classads
@rtype: string @return: Filename
glideinwms.lib.cleanupSupport module¶
- class glideinwms.lib.cleanupSupport.CredCleanup[source]¶
Bases:
Cleanup
Cleans up old credential files.
- class glideinwms.lib.cleanupSupport.DirCleanup(dirname, fname_expression, maxlife, should_log=True, should_log_warnings=True)[source]¶
Bases:
object
- class glideinwms.lib.cleanupSupport.DirCleanupCredentials(dirname, fname_expression, maxlife)[source]¶
Bases:
DirCleanup
Used to cleanup old credential files saved to disk by the factory for glidein submission (based on ctime).
- class glideinwms.lib.cleanupSupport.DirCleanupWSpace(dirname, fname_expression, maxlife, minlife, maxspace, should_log=True, should_log_warnings=True)[source]¶
Bases:
DirCleanup
glideinwms.lib.condorExe module¶
- exception glideinwms.lib.condorExe.CondorExeError(err_str)[source]¶
Bases:
RuntimeError
Base class for condorExe module errors
- exception glideinwms.lib.condorExe.ExeError(err_str)[source]¶
Bases:
CondorExeError
- exception glideinwms.lib.condorExe.UnconfigError(err_str)[source]¶
Bases:
CondorExeError
- glideinwms.lib.condorExe.exe_cmd(condor_exe, args, stdin_data=None, env={})[source]¶
Execute an arbitrary condor command and return its output as a list of lines Fails if stderr is not empty
- Parameters:
condor_exe (str) – condor_exe uses a relative path to $CONDOR_BIN
args (str) – arguments for the command
stdin_data (str) – Data that will be fed to the command via stdin
env (dict) – Environment to be set before execution
- Returns:
Lines of stdout from the command
- Raises:
- glideinwms.lib.condorExe.generate_bash_script(cmd, environment)[source]¶
Print to a string a shell script setting the environment in ‘environment’ and running ‘cmd’ If ‘cmd’ last argument is a file it will be printed as well in the string
- Parameters:
cmd (str) – command string
environment (dict) – environment as a dictionary
- Returns:
multi-line string with environment, command and eventually the input file
- Return type:
str
- glideinwms.lib.condorExe.iexe_cmd(cmd, stdin_data=None, child_env=None, log=None)[source]¶
Fork a process and execute cmd - rewritten to use select to avoid filling up stderr and stdout queues.
- Parameters:
cmd (str) – Sting containing the entire command including all arguments
stdin_data (str) – Data that will be fed to the command via stdin
child_env (dict) – Environment to be set before execution
- Returns:
Lines of stdout from the command
- Return type:
list of str
- Raises:
ExeError –
- glideinwms.lib.condorExe.set_path(new_condor_bin_path, new_condor_sbin_path=None)[source]¶
Set path to condor binaries, if needed
Works changing the global variables condor_bin_path and condor_sbin_path
- Parameters:
new_condor_bin_path (str) – directory where the HTCondor binaries are located
new_condor_sbin_path (str) – directory where the HTCondor system binaries are located
glideinwms.lib.condorLogParser module¶
This module implements classes and functions to parse the condor log files.
NOTE: Inactive files are log files that have only completed or removed entries Such files will not change in the future
- class glideinwms.lib.condorLogParser.cacheDirClass(logClass, dirname, log_prefix, log_suffix='.log', cache_ext='.cifpk', inactive_files=None, inactive_timeout=86400, cache_dir=None, wrapperClass=None, username=None)[source]¶
Bases:
object
This is the base class for all the directory log Parser classes. It parses some/all log files in a directory. It should generally not be called directly. Rather, call one of the inherited classes.
- cdInit(logClass, dirname, log_prefix, log_suffix='.log', cache_ext='.cifpk', inactive_files=None, inactive_timeout=86400, cache_dir=None, wrapperClass=None, username=None)[source]¶
@param logClass: this is an actual class, not an object @param inactive_files: if None, will be reloaded from cache @param inactive_timeout: how much time must elapse before a file can be
- declared inactive
@param cache_dir: If None, use dirname for the cache directory.
- diff(other)[source]¶
Diff self data with other info
This is a virtual function that just calls the class diff() function.
- getFileList(active_only)[source]¶
Lists the directory and returns files that match the prefix/suffix extensions and are active (modified within inactivity_timeout)
@return: a list of log files
- has_changed()[source]¶
Checks all the files in the list to see if any have changed.
@return: True/False
- load(active_only=True)[source]¶
For each file in the filelist, call the appropriate load() function for that file. Merge all the data from all the files into temporary array mydata then set it to self.data. It will save the list of inactive_files it finds in a cache for quick access.
This function should set self.data.
- class glideinwms.lib.condorLogParser.cachedLogClass[source]¶
Bases:
object
This is the base class for most Log Parsers in lib/condorLogParser and factory/glideFactoryLogParser. (I{virtual, do not use})
The Constructor for inherited classes needs to define logname and cachename (possibly by using clInit) as well as the methods
loadFromLog, merge and isActive.
init method to be used by real constructors
- glideinwms.lib.condorLogParser.countAndInterpretRawStatuses(jobs_raw)[source]¶
Given a dictionary of job statuses (like the one got from parseSubmitLogFastRaw) will return a dictionary of status counts
for example: {‘Completed’: 30170, ‘Removed’: 148, ‘Running’: 5013}
@param jobs_raw: Dictionary of job statuses @return: Dictionary of status counts
- glideinwms.lib.condorLogParser.countStatuses(jobs)[source]¶
Given a dictionary of job statuses (like the one got from parseSubmitLogFastRaw) will return a dictionary of sstatus counts
for example: {‘009’: 25170, ‘012’: 418, ‘005’: 1503}
- glideinwms.lib.condorLogParser.diffTimes(start_time, end_time, year)[source]¶
Get two condor time strings and compute the difference The start_time must be before the end_time
- glideinwms.lib.condorLogParser.diffTimeswWrap(start_time, end_time, year, wrap_time)[source]¶
Get two condor time strings and compute the difference The start_time must be before the end_time
- class glideinwms.lib.condorLogParser.dirCompleted(dirname, log_prefix, log_suffix='.log', cache_ext='.cifpk', inactive_files=None, inactive_timeout=86400, cache_dir=None)[source]¶
Bases:
cacheDirClass
- This class will keep track of:
counts of statuses (Wait, Idle, Running, Held, Completed, Removed)
list of completed jobs
This data is available in self.data dictionary for example self.data={‘completed_jobs’:[‘123.002’,’555.001’], ‘counts’:{‘Idle’: 1145, ‘Completed’: 2}}
- class glideinwms.lib.condorLogParser.dirCounts(dirname, log_prefix, log_suffix='.log', cache_ext='.cifpk', inactive_files=None, inactive_timeout=86400, cache_dir=None)[source]¶
Bases:
cacheDirClass
This class will keep track of counts of statuses (Wait, Idle, Running, Held, Completed, Removed) These data is available in self.data dictionary for example self.data={‘Idle’: 1145, ‘Completed’: 2}
- class glideinwms.lib.condorLogParser.dirSummary(dirname, log_prefix, log_suffix='.log', cache_ext='.cifpk', inactive_files=None, inactive_timeout=86400, cache_dir=None)[source]¶
Bases:
cacheDirClass
This class will keep track of: jobs in various of statuses (Wait, Idle, Running, Held, Completed, Removed) This data is available in self.data dictionary For example, self.data={‘Idle’:[‘123.003’,’123.004’],’Running’:[‘123.001’,’123.002’]}
- class glideinwms.lib.condorLogParser.dirSummaryTimings(dirname, log_prefix, log_suffix='.log', cache_ext='.cifpk', inactive_files=None, inactive_timeout=86400, cache_dir=None)[source]¶
Bases:
cacheDirClass
This class will keep track of: jobs in various of statuses (Wait, Idle, Running, Held, Completed, Removed) This data is available in self.data dictionary For example self.data={‘Idle’:[(‘123.003’,’09/28 01:38:53’, ‘09/28 01:42:23’, ‘09/28 08:06:33’),(‘123.004’,’09/28 02:38:53’, ‘09/28 02:42:23’, ‘09/28 09:06:33’)], ‘Running’:[(‘123.001’,’09/28 01:32:53’, ‘09/28 01:43:23’, ‘09/28 08:07:33’),(‘123.002’,’09/28 02:38:53’, ‘09/28 03:42:23’, ‘09/28 06:06:33’)]}
- glideinwms.lib.condorLogParser.get_new_status(old_status, new_status)[source]¶
Given a job with an old and new status, will return the appropriate status to register to the job.
@param old_status: Globus job status @param new_status: Globus job status @return: Appropriate status for the job
- glideinwms.lib.condorLogParser.interpretStatus(status, default_status='Idle')[source]¶
Transform a integer globus status to either Wait, Idle, Running, Held, Completed or Removed
- glideinwms.lib.condorLogParser.listAndInterpretRawStatuses(jobs_raw, invert_function)[source]¶
Given a dictionary of job statuses (whatever the invert_function recognises) will return a dictionary of jobs in each status (syntax depends on the invert_function)
for example with linvert_funtion==istStatuses: {‘Completed’: [“2.003”,”5.001”], ‘Removed’: [“41.001”], ‘Running’: [“408.003”]}
@param jobs_raw: A dictionary of job statuses @param invert_function: function to turn a job status into “Completed”,”Removed”,”Running”, etc @return: Dictionary of jobs in each category.
- glideinwms.lib.condorLogParser.listStatuses(jobs)[source]¶
Given a dictionary of job statuses (like the one got from parseSubmitLogFastRaw) will return a dictionary of jobs in each status
For example: {‘009’: [“1.003”,”2.001”], ‘012’: [“418.001”], ‘005’: [“1503.001”,”1555.002”]}
@param jobs: Dictionary of job statuses @return: Dictionary of jobs in each status category
- glideinwms.lib.condorLogParser.listStatusesTimings(jobs)[source]¶
Given a dictionary of job statuses + timings (like the one got from parseSubmitLogFastRawTimings) will return a dictionary of jobs +timings in each status
For example: {‘009’: [(“1.003”,’09/28 01:38:53’, ‘’, ‘09/28 01:38:53’),(“2.001”,’09/28 03:38:53’, ‘’, ‘09/28 04:38:53’)], ‘005’: [(“1503.001”, ‘09/28 01:48:52’, ‘09/28 16:11:23’, ‘09/28 20:31:53’),(“1555.002”, ‘09/28 02:48:52’, ‘09/28 18:11:23’, ‘09/28 23:31:53’)]}
@param jobs: Dictionary of job statuses and timings @return: Dictionary of jobs+timings in each status category
- glideinwms.lib.condorLogParser.loadCache(fname)[source]¶
Loads a pickle file from a filename and returns the resulting data.
@param fname: Filename to load @return: data retrieved from file
- class glideinwms.lib.condorLogParser.logCompleted(logname, cache_dir)[source]¶
Bases:
cachedLogClass
- This class will keep track of:
counts of statuses (Wait, Idle, Running, Held, Completed, Removed)
list of completed jobs
This data is available in self.data dictionary
For example self.data= {‘completed_jobs’:[‘123.002’,’555.001’], ‘counts’:{‘Idle’: 1145, ‘Completed’: 2}}
- diff(other)[source]¶
Diff self.data with other info. For use in comparing previous iteration with current iteration
Uses symmetric difference of sets.
- class glideinwms.lib.condorLogParser.logCounts(logname, cache_dir)[source]¶
Bases:
cachedLogClass
This class will keep track of counts of statuses (Wait, Idle, Running, Held, Completed, Removed) This data is available in self.data dictionary For example self.data={‘Idle’: 1145, ‘Completed’: 2}
- class glideinwms.lib.condorLogParser.logSummary(logname, cache_dir)[source]¶
Bases:
cachedLogClass
This class will keep track of: jobs in various of statuses (Wait, Idle, Running, Held, Completed, Removed) This data is available in self.data dictionary for example self.data={‘Idle’:[‘123.003’,’123.004’],’Running’:[‘123.001’,’123.002’]}
- diff(other)[source]¶
diff self data with other info. Used to compare previous iteration with current iteration
Performs symmetric difference on the two sets and creates a dictionary for each status.
@return: data[status][‘Entered’|’Exited’] - list of jobs
- class glideinwms.lib.condorLogParser.logSummaryTimings(logname, cache_dir)[source]¶
Bases:
cachedLogClass
This class will keep track of: jobs in various of statuses (Wait, Idle, Running, Held, Completed, Removed) This data is available in self.data dictionary for example self.data={‘Idle’:[‘123.003’,’123.004’],’Running’:[‘123.001’,’123.002’]}
- glideinwms.lib.condorLogParser.parseSubmitLogFast(fname)[source]¶
Reads a Condor submit log, return a dictionary of jobIds each having the last status.
For example {(1583,4)’: 0, (3616,8): 9}
@param fname: filename to parse @return: Dictionary of jobIDs and last status
- glideinwms.lib.condorLogParser.parseSubmitLogFastRaw(fname)[source]¶
Read a condor submit log.
@return: a dictionary of jobStrings each having the last statusString For example {‘1583.004’: ‘000’, ‘3616.008’: ‘009’}
- glideinwms.lib.condorLogParser.parseSubmitLogFastRawCallback(fname, callback)[source]¶
Read a condor submit log for each new event, call a callback
@param fname: Condor submit file to parse @param callname: def callback(new_status_str,timestamp_str,job_str)
- glideinwms.lib.condorLogParser.parseSubmitLogFastRawTimings(fname)[source]¶
Read a condor submit log. Returns a dictionary of jobStrings each having (the last statusString,firstTime,runningTime,lastTime) plus the first and last date in the file
for example {‘9568.001’:(‘000’, ‘09/28 01:38:53’, ‘’, ‘09/28 01:38:53’),’9868.003’:(‘005’, ‘09/28 01:48:52’, ‘09/28 16:11:23’, ‘09/28 20:31:53’)},’09/28 01:38:53’,’09/28 20:31:53’
@return: a dictionary of jobStrings
- glideinwms.lib.condorLogParser.parseSubmitLogFastTimings(fname, year=None)[source]¶
Reads a Condor submit log, return a dictionary of jobIds each having (the last status, seconds in queue, if status==5, seconds running)
For example {(1583,4)’: (0,345,None), (3616,8): (5,7777,4532)}
@param fname: filename to parse @param year: if no year, then use the current one @return: Dictionary of jobIDs
- glideinwms.lib.condorLogParser.rawJobId2Nr(str)[source]¶
Convert the log representation into (ClusterId,ProcessId)
Return (-1,-1) in case of error
- glideinwms.lib.condorLogParser.rawTime2cTime(instr, year)[source]¶
Convert the log representation into ctime
@return: ctime or -1 in case of error
glideinwms.lib.condorManager module¶
This module implements functions that will act on Condor
- glideinwms.lib.condorManager.cached_exe_cmd(cmd, arg_str, schedd_name, pool_name, schedd_lookup_cache)[source]¶
- glideinwms.lib.condorManager.condorAdvertise(classad_fname, command, use_tcp=False, is_multi=False, pool_name=None)[source]¶
- glideinwms.lib.condorManager.condorHold(constraint, schedd_name=None, pool_name=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
- glideinwms.lib.condorManager.condorHoldOne(cluster_or_uname, schedd_name=None, pool_name=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
- glideinwms.lib.condorManager.condorRelease(constraint, schedd_name=None, pool_name=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
- glideinwms.lib.condorManager.condorReleaseOne(cluster_or_uname, schedd_name=None, pool_name=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
- glideinwms.lib.condorManager.condorRemove(constraint, schedd_name=None, pool_name=None, do_forcex=False, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
- glideinwms.lib.condorManager.condorRemoveOne(cluster_or_uname, schedd_name=None, pool_name=None, do_forcex=False, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
- glideinwms.lib.condorManager.condorReschedule(schedd_name=None, pool_name=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
glideinwms.lib.condorMonitor module¶
This module implements classes to query the condor daemons and manipulate the results Please notice that it also converts “ into “
- class glideinwms.lib.condorMonitor.AbstractQuery[source]¶
Bases:
object
Pure virtual class to have a minimum set of methods defined
- fetch(constraint=None, format_list=None)[source]¶
Fetch the classad attributes specified in the format_list matching the constraint
@rtype: dict @return: Dict containing classad attributes and values
- class glideinwms.lib.condorMonitor.BaseSubQuery(query, subquery_func)[source]¶
Bases:
StoredQuery
Virtual class that implements fetch for StoredQuery()
- class glideinwms.lib.condorMonitor.CondorQ(schedd_name=None, pool_name=None, security_obj=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
Bases:
CondorQuery
Class to implement condor_q. Uses htcondor-python bindings if possible.
- fetch(constraint=None, format_list=None)[source]¶
Return the results obtained using HTCondor commands or python bindings
- Parameters:
constraint (str) – query constraint
format_list (list) – Classad attr & type. [(attr1, ‘i’), (‘attr2’, ‘s’)]
Returns (dict): Dict containing the query results
- fetch_using_bindings(constraint=None, format_list=None)[source]¶
Fetch the condor_q results using htcondor-python bindings
- Parameters:
constraint (str) – Constraints to be applied to the query
format_list (list) – Classad attr & type. [(attr1, ‘i’), (‘attr2’, ‘s’)]
Returns (dict): Dict containing the results
- class glideinwms.lib.condorMonitor.CondorQEdit(pool_name=None, schedd_name=None)[source]¶
Bases:
object
Fully implemented class that executes condorq_edit commands. Only provides a method to do bulk updates of jobs using transaction-based API and the condor python bindings. Cannot be used without python bindings
- class glideinwms.lib.condorMonitor.CondorQLite(schedd_name=None, pool_name=None, security_obj=None, schedd_lookup_cache=<glideinwms.lib.condorMonitor.LocalScheddCache object>)[source]¶
Bases:
CondorQuery
- class glideinwms.lib.condorMonitor.CondorQuery(exe_name, resource_str, group_attribute, pool_name=None, security_obj=None, env={})[source]¶
Bases:
StoredQuery
Fully implemented class that executes condor commands
- fetch(constraint=None, format_list=None)[source]¶
Return the results obtained using HTCondor commands or python bindings
- Parameters:
constraint (str) – query constraint
format_list (list) – Classad attr & type. [(attr1, ‘i’), (‘attr2’, ‘s’)]
Returns (dict): Dict containing the query results
- fetch_using_bindings(constraint=None, format_list=None)[source]¶
Fetch the results using htcondor-python bindings
- Parameters:
constraint (str) – Constraints to be applied to the query
format_list (list) – Classad attr & type. [(attr1, ‘i’), (‘attr2’, ‘s’)]
Returns (dict): Dict containing the results
- Raises:
NotImplementedError – the operation is not implemented using bindings
- fetch_using_exe(constraint=None, format_list=None)[source]¶
Return the results obtained from executing the HTCondor query command
- Parameters:
constraint (str) – Constraints to be applied to the query
format_list (list) – Classad attr & type. [(attr1, ‘i’), (‘attr2’, ‘s’)]
Returns (dict): Dict containing the results
- get_requested_encryption()[source]¶
Get the current encryption settings
Returns: None->None; REQUIRED->True; OPTIONAL->False
- get_requested_integrity()[source]¶
Get the current integrity settings
Returns: None->None; REQUIRED->True; OPTIONAL->False
- class glideinwms.lib.condorMonitor.CondorStatus(subsystem_name=None, pool_name=None, security_obj=None)[source]¶
Bases:
CondorQuery
Class to implement condor_status. Uses htcondor-python bindings if possible.
- class glideinwms.lib.condorMonitor.Group(query, group_key_func, group_data_func)[source]¶
Bases:
BaseSubQuery
Sub Query class with grouping functionality Each element has a value that is the summary of the values in a group
- class glideinwms.lib.condorMonitor.LocalScheddCache[source]¶
Bases:
NoneScheddCache
Schedd caching class The schedd can be found either through -name attr or through the local disk lookup. Remember which one to use.
- class glideinwms.lib.condorMonitor.NestedGroup(query, group_key_func, group_element_func=None)[source]¶
Bases:
BaseSubQuery
Sub Query class with grouping functionality to create nested results Each element is a dictionary with elements reduced from the original elements in the group
- class glideinwms.lib.condorMonitor.NoneDiskCache[source]¶
Bases:
object
Dummy class used if a regular DiskCache is not specified
- class glideinwms.lib.condorMonitor.NoneScheddCache[source]¶
Bases:
object
Dummy caching class, when you don’t want caching. Used as base class below, too
- exception glideinwms.lib.condorMonitor.PBError(err_str)[source]¶
Bases:
RuntimeError
Thrown when there are exceptions using htcondor python bindings
- exception glideinwms.lib.condorMonitor.QueryError(err_str)[source]¶
Bases:
RuntimeError
Thrown when there are exceptions using htcondor python bindings or commands
- class glideinwms.lib.condorMonitor.StoredQuery[source]¶
Bases:
AbstractQuery
Virtual class that implements fetchStored
- fetchStored(constraint_func=None)[source]¶
- @param constraint_func: A boolean function, with only one argument
(data el). If None, return all the data.
@type constraint_func: Boolean function
@rtype: dict @return: Same as fetch(), but limited to constraint_func(el)==True
- stored_data = {}¶
- class glideinwms.lib.condorMonitor.SubQuery(query, constraint_func=None)[source]¶
Bases:
BaseSubQuery
Fully usable subquery class, typically used on CondorQ() or CondorStatus()
- class glideinwms.lib.condorMonitor.Summarize(query, hash_func=<function Summarize.<lambda>>)[source]¶
Bases:
object
Summarizing classes
- class glideinwms.lib.condorMonitor.SummarizeMulti(queries, hash_func=<function SummarizeMulti.<lambda>>)[source]¶
Bases:
object
- glideinwms.lib.condorMonitor.addDict(base_dict, new_dict)[source]¶
Recursively add two dictionaries Do it in place, using the first one
- Parameters:
base_dict – first dictionary
new_dict – dictionary to be added
- glideinwms.lib.condorMonitor.applyConstraint(data, constraint_func)[source]¶
Return a subset of data that satisfies constraint_function If constraint_func is None, return back entire data
- Parameters:
data
constraint_func
Returns:
- glideinwms.lib.condorMonitor.bindings_friendly_attrs(format_list)[source]¶
Convert the format_list into attrs that can be used with python bindings Python bindings should take care of the typing
- glideinwms.lib.condorMonitor.bindings_friendly_constraint(constraint)[source]¶
Convert the constraint to format that can be used with python bindings
- glideinwms.lib.condorMonitor.condorq_attrs(q_constraint, attribute_list)[source]¶
Retrieves a list of a single item from the all the factory queues.
- glideinwms.lib.condorMonitor.doGroup(indata, group_key_func, group_data_func)[source]¶
Group the indata based on the keys that satisfy group_key_func (applied to the value) Return a dict of groups summarized by group_data_func Each group returned by group_data_func must be a dictionary, possibly similar to the original value of the indata elements
- Parameters:
indata
group_key_func
group_data_func
- Returns:
dict of groups summarized by group_data_func
- glideinwms.lib.condorMonitor.doNestedGroup(indata, group_key_func, group_element_func=None)[source]¶
Group the indata based on the keys that satisfy group_key_func (applied to the value) Return a dict of dictionaries created by group_element_func Each each value of the dictionaries returned by group_element_func must be a dictionary, possibly similar to the original value of the indata elements
If group_element_func is None (not provided), then the dictionaries in the groups are a copy of the original dictionaries in indata
- Parameters:
indata – data to group
group_key_func – group_by function
group_element_func – how to handle the data in each group (by default is a copy of the original one)
- Returns:
dictionary of dictionaries with grouped indata
- Return type:
dict
- glideinwms.lib.condorMonitor.fetch2count(data, hash_func)[source]¶
Nested count of the hash values returned from all the elements in data
- Parameters:
data – data from a fetch()
hash_func –
Hashing function One argument: classad dictionary Returns: hash value
if None, will not be counted if a list, all elements will be used
- Returns:
- dictionary of hash values
Elements are counts (or more dictionaries if hash returns lists)
- Return type:
dict
- glideinwms.lib.condorMonitor.fetch2count_flat(data, hash_func)[source]¶
Count the hash values returned from all the elements in data
- Parameters:
data – data from a fetch()
hash_func –
Hashing function One argument: classad dictionary Returns: flat hash value (for hashing functions returning also lists, use fetch2count
if None, will not be counted
- Returns:
a dictionary with a count of the hash values returned
- glideinwms.lib.condorMonitor.list2dict(list_data, attr_name)[source]¶
Convert a list to a dictionary where the keys are tuples with the values of the attributes listed in attr_name
Original description: Convert a list to a dictionary and group the results based on attributes specified by attr_name
This function has a couple of quirks, but is OK because the ways it is used (MM) The way it is used, attr_name is the job cluster, process, which are both present in all jobs from condor_q and unique, or the Name that is always present and unique in condor_status, so the quirks should not cause problems 1. Type checking (of attr_name) probably should use isistance() 2. dict_name is a tuple including elements of attr_name translated to value in list_el
if them or the lowercase is a key in list_el BUT from the value ( dict_data[dict_name] ) only exact match is excluded, not the lowercase version
keys (dict_name) may have different cardinality if one or some of the elements is not matching list_el keys
if 2 or more list_el have the same dict_name (same valies in attr_list attributes), the newest ones overwrite the older ones without any warning AND the original description mentions … “and group the results” … there is no grouping
‘Undefined’ attributes are not added to the dict_el (dict elements may have different keys)
using ‘%s’%a_value != ‘Undefined’ and str(list_el[a]) != ‘Undefined’ for the same. Use twice the better one
- Parameters:
list_data – list of dictionaries to convert
attr_name – string (1 attribute) or list or tuple (one or more attributes) with the attributes to use as key
- Returns:
dictionary of dictionaries
- Return type:
dict
glideinwms.lib.condorSecurity module¶
This module implements classes that will setup the Condor security as needed
- class glideinwms.lib.condorSecurity.EnvProtoState(filter=None)[source]¶
Bases:
SecEnvState
- class glideinwms.lib.condorSecurity.GSIRequest(x509_proxy=None, allow_fs=True, allow_idtokens=True, proto_requests=None)[source]¶
Bases:
ProtoRequest
- class glideinwms.lib.condorSecurity.ProtoRequest(requests=None)[source]¶
Bases:
SecEnvRequest
glideinwms.lib.config_util module¶
This module contains a list of shared utility function used by the both OSG collector and CRIC configuration generation helper tools
- exception glideinwms.lib.config_util.ProgramError(code)[source]¶
Bases:
Exception
Simple collection of program error codes and related short messages
- codes_map = {1: 'File not found', 2: 'Site not found', 3: 'CE not found', 4: 'Do not use BEST_FIT', 5: 'Collector error'}¶
- glideinwms.lib.config_util.get_attr_str(attrs)[source]¶
Convert attributes from a dictionary form to the corresponding configuration string
- Parameters:
attrs (dict) – the dictionary containing the attributes
- Returns:
the string representing the xml attributes section for a single entry
- Return type:
string
- glideinwms.lib.config_util.get_limits_str(limits)[source]¶
Convert pilots limits from a dictionary form to the corresponding configuration string
- Parameters:
limits (dict) – the dictionary containing the pilots limits
- Returns:
the string representing the xml pilots limits section for a single entry
- Return type:
string
- glideinwms.lib.config_util.get_submission_speed(submission_speed)[source]¶
Convert submission speed from a name to the corresponding configuration string
- Parameters:
submission_speed (string) – the string containing the submission speed name
- Returns:
the string representing the xml submission speed section for a single entry
- Return type:
string
- glideinwms.lib.config_util.get_submit_attr_str(submit_attrs)[source]¶
Convert submit attributes from a dictionary form to the corresponding configuration string
- Parameters:
submit_attrs (dict) – the dictionary containing the submit attributes
- Returns:
the string representing the xml submit attributes section for a single entry
- Return type:
string
- glideinwms.lib.config_util.get_yaml_file_info(file_name)[source]¶
Loads a yaml file into a dictionary
- Parameters:
file_name (str) – The file to load
Returns:
- Raises:
- glideinwms.lib.config_util.update(data, update_data, overwrite=True)[source]¶
Recursively update the information contained in a dictionary
- Parameters:
data (dict) – The starting dictionary
update_data (dict) – The dictionary that contains the new data
overwrite (bool) – wether existing keys are going to be overwritten
- glideinwms.lib.config_util.write_to_file(file_name, information)[source]¶
Take a dictionary and writes it out to disk as a yaml file
- Parameters:
file_name (str) – the filename to write to disk
information (dict) – the dictionary to write out as yaml file
glideinwms.lib.defaults module¶
Collections of constants that are used throughout the GlideinWMS project
- glideinwms.lib.defaults.force_bytes(instr, encoding='utf_8')[source]¶
Forces the output to be bytes, encoding the input if it is a unicode string (str)
AnyStr is str or bytes types
- Parameters:
instr (AnyStr) – string to be converted
encoding (str) – a valid encoding, utf_8, ascii, latin-1 (iso-8859-1’)
- Returns:
instr as bytes string
- Return type:
bytes
- Raises:
ValueError – if it detects an improper str conversion (b’’ around the string)
- glideinwms.lib.defaults.force_str(inbytes, encoding='utf_8')[source]¶
Forces the output to be str, decoding the input if it is a bytestring (bytes)
AnyStr is str or bytes types
- Parameters:
inbytes (AnyStr) – string to be converted
encoding (str) – a valid encoding, utf8, ascii, latin-1
- Returns:
instr as unicode string
- Return type:
str
- Raises:
ValueError – if it detects an improper str conversion (b’’ around the string) or the input is neither string or bytes
glideinwms.lib.disk_cache module¶
This module helps managing objects that needs to be cached. Objects are cached both in memory and on disk so that the cache can be leveraged by multiple processes.
Each object you want to save needs to have a string id that identifies it. The id is used to locate the object in the memory (a key in a dictionary), and on the disk (the filename).
- class glideinwms.lib.disk_cache.DiskCache(cache_dir, cache_duration=3600)[source]¶
Bases:
object
The class that manages the cache. Objects expires after a cache_duration time (defaults to one hour). Objects are pickled into a file. The directory to save those files has to be specified. Methods to save and load an object by its id are provided.
- get(objid)[source]¶
Returns the cached object given its object id
objid
. Returns None if the object is not in the cache, or if it has expired.First we check if the object is in the memory dictionary, otherwise we look for its corresponding cache file, and we loads it from there.
- Parameters:
objid (str) – the string representing the object id you want to get
- Returns:
The cached object, or None if the object does not exist or the cache is expired
- get_fname(objid)[source]¶
Simple auxiliary function that returns the cache filename given a cache object id
- save(objid, obj)[source]¶
Save an object into the cache.
Objects are saved both in memory and into the corresponding cache file (one file for each object id). Objects are saved paired with the timestamp representing the time when it has been saved.
- Parameters:
objid (str) – The id of the object you are saving
obj – the python object that you want to save
- glideinwms.lib.disk_cache.get_lock(name)[source]¶
Create a “name”.lock file and, using fcnt, lock it (or wait for the lock to be released) before proceeding
N.B. The “name”.lock file is not removed after the lock is released, it is kept to be reused: we only care about the lock status.
- Params:
name (str): the name of the file you want to lock. A lockfile name.lock will be created
glideinwms.lib.exprParser module¶
Description: general purpose python expression parser and unparser
- glideinwms.lib.exprParser.exp_compare(node1, node2)[source]¶
Compare 2 AST trees to verify if they are the same
- Parameters:
node1 (ast.AST) – AST tree
node2 (ast.AST) – AST tree
- Returns:
True if node1 and node2 are the same expression
- Return type:
bool
- glideinwms.lib.exprParser.exp_compile(obj)[source]¶
Convert an ast object into a code object
- Parameters:
obj (ast.AST) – AST object to compile
- Returns:
code object
glideinwms.lib.fork module¶
This module implements functions and classes to handle forking of processes and the collection of results
- exception glideinwms.lib.fork.ForkError(msg)[source]¶
Bases:
RuntimeError
Base class for this module’s errors
- exception glideinwms.lib.fork.ForkResultError(nr_errors, good_results, failed=[])[source]¶
Bases:
ForkError
- glideinwms.lib.fork.fetch_fork_result(r, pid)[source]¶
Used with fork clients to retrieve results Can raise: OSError if Bad file descriptor or file already closed or if waitpid syscall returns -1 FetchError if a os.read error was encountered Possible errors from os.read and pickle.load (catched here): - EOFError if the forked process failed an nothing was written to the pipe, if cPickle finds an empty string - IOError failure for an I/O-related reason, e.g., “pipe file not found” or “disk full” - OSError other system-related error (includes both former OSError and IOError since Py3.4) - pickle.UnpicklingError incomplete pickled data
- Parameters:
r (pipe) – Input pipe
pid (int) – pid of the child
- Returns:
Unpickled object
- Return type:
Object
- glideinwms.lib.fork.fetch_fork_result_list(pipe_ids)[source]¶
Read the output pipe of the children, used after forking to perform work and after forking to entry.writeStats()
- Parameters:
pipe_ids (dict) – Dictionary of pipe and pid
- Returns:
Dictionary of fork_results
- Return type:
dict
- glideinwms.lib.fork.fetch_ready_fork_result_list(pipe_ids)[source]¶
Read the output pipe of the children, used after forking. If there is data on the pipes to consume, read the data and close the pipe. and after forking to entry.writeStats()
- Parameters:
pipe_ids (dict) – Dictionary of pipe and pid
- Returns:
Dictionary of work_done
- Return type:
dict
- glideinwms.lib.fork.fork_in_bg(function_torun, *args)[source]¶
Fork and call a function with args
This function returns right away, returning the pid and a pipe to the stdout of the function process where the output of the function will be pickled
Example
def add(i, j): return i+j d = fork_in_bg(add, i, j)
- Parameters:
function_torun (function) – function to call after forking the process
*args – arguments list to pass to the function
- Returns:
dict with {‘r’: fd, ‘pid’: pid} where fd is the stdout from a pipe.
- Return type:
dict
- glideinwms.lib.fork.print_child_processes(root_pid='10442', this_pid='52119')[source]¶
Print the process tree of the root PID
- Parameters:
root_pid (str) – String containing the process ID to use as root of the process tree
this_pid (str|None) – If String containing the process ID of the current process (will get a star in the line)
- Returns:
list of str containing all the lines of the process tree
- Return type:
list
glideinwms.lib.glideinWMSVersion module¶
Execute a ls command on a condor job working directory
- Usage:
glideinWMSVersion.py <Path to glideinWMS distribution> [<Checksum file>]
- class glideinwms.lib.glideinWMSVersion.GlideinWMSDistro(chksumFile='checksum')[source]¶
Bases:
object
- class __impl(chksumFile='checksum')¶
Bases:
object
Implementation of the singleton interface
- createVersionString()¶
- version()¶
- __instance = <glideinwms.lib.glideinWMSVersion.GlideinWMSDistro.__impl object>¶
glideinwms.lib.hashCrypto module¶
hashCrypto - This module defines classes to perform hash based cryptography
It uses M2Crypto: https://github.com/mcepl/M2Crypto a wrapper around OpenSSL: https://www.openssl.org/docs/man1.1.1/man3/
- NOTE get_hash() and extract_hash() both return Unicode utf-8 (defaults.BINARY_ENCODING_CRYPTO) strings and
get_hash() accepts byte-like objects or utf-8 encoded Unicode strings. Same for all the get_XXX or extract_XXX that use those functions. Other class methods and functions use bytes for input and output
- class glideinwms.lib.hashCrypto.Hash(hash_algo)[source]¶
Bases:
object
Generic hash class
- Available hash algorithms:
‘sha1’ ‘sha224’ ‘sha256’, ‘ripemd160’ ‘md5’
- compute(data)[source]¶
Compute hash inline
len(data) must be less than len(key)
- Parameters:
data (bytes) – data to calculate the hash of
- Returns:
digest value as bytes string (OpenSSL final and digest together)
- Return type:
bytes
- glideinwms.lib.hashCrypto.extract_hash(hash_algo, fname, block_size=1048576)[source]¶
Compute hash from file
- Parameters:
hash_algo (str) – hash algorithm to use
fname (str) – file path (file will be open in binary mode)
block_size (int) – block size
- Returns:
utf-8 encoded hash
- Return type:
str
glideinwms.lib.logSupport module¶
- class glideinwms.lib.logSupport.GlideinHandler(filename, maxDays=1.0, minDays=0.0, maxMBytes=10.0, backupCount=5, compression=None)[source]¶
Bases:
BaseRotatingHandler
Custom logging handler class for GlideinWMS. It combines the decision tree for log rotation from the TimedRotatingFileHandler with the decision tree from the RotatingFileHandler. This allows us to specify a lifetime AND file size to determine when to rotate the file. Files are rotated if the days since the last rotation (or the beginning) are more than the time limit (maxDays) or if the size of the file grew above the size limit (maxMBytes) and at least the min time interval (minDays) went by.
This class assumes that the lifetime (interval, min_lifetime) specified is in seconds but the value in the constructor (maxDays, minDays) are in days (24 hour periods) and can be fractions (float).
And the size is measured in Bytes (MBytes in the constructor parameter can be fractional)
@type filename: string @ivar filename: Full path to the log file. Includes file name. @type interval: int @ivar interval: Number of seconds to keep log file before rotating @type maxBytes: int @param maxBytes: Maximum size of the logfile in Bytes before file rotation (used with min days) @type min_lifetime: int @param min_lifetime: Minimum number of seconds (used with max bytes) @type backupCount: int @ivar backupCount: How many backups to keep
- doRollover()[source]¶
Do a rollover
In this case, a date/time stamp is appended to the filename when the rollover happens. If there is a backup count, then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix.
- getFilesToDelete()[source]¶
Determine the files to delete when rolling over.
More specific than the earlier method, which just used glob.glob().
- shouldRollover(record, empty_record=False)[source]¶
Determine if rollover should occur.
Basically, we are combining the checks for size and time interval
- Parameters:
record (str) – The message that will be logged.
empty_record (bool) – If False (default) count also record length to evaluate if a rollover is needed
- Returns:
True if rollover should be performed, False otherwise
- Return type:
bool
@attention: Due to the architecture decision to fork “workers” we run into an issue where the child that was forked could cause a log rotation. However, the parent will never know and the parent’s file descriptor will still be pointing at the old log file (now renamed by the child). This will in turn cause the parent to immediately request a log rotate, which results in what appears to be truncated logs. To handle this we add a flag to disable log rotation. By default, this is set to False, but anywhere we want to fork a child (or in any object that will be forked) we set the flag to True. Then in the parent, we initiate a log function that will log and rotate if necessary.
- class glideinwms.lib.logSupport.MsgFilter(msg_type_list)[source]¶
Bases:
Filter
Filter used in handling records for the info logs.
Default to logging.INFO
- filter(rec)[source]¶
Determine if the specified record is to be logged.
Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.
- msg_type_list = [20]¶
- glideinwms.lib.logSupport.alternate_log(msg)[source]¶
When an exceptions happen within the logging system (e.g. when the disk is full while rotating a log file) an alternate logging is necessary, e.g. writing to stderr
- glideinwms.lib.logSupport.format_dict(unformated_dict, log_format=' %-25s : %s\n')[source]¶
Convenience function used to format a dictionary for the logs to make it human-readable.
- Parameters:
unformated_dict (dict) – The dictionary to be formatted for logging
log_format (str) – format string for logging
- Returns:
Formatted string
- Return type:
str
- glideinwms.lib.logSupport.get_logger_with_handlers(name, directory, config_data, level=10)[source]¶
Create/retrieve a logger, set the handlers, set the starting logging level, and return the logger
The file name is {name}.{plog[“extension”].lower()}.log
- Parameters:
name (str) – logger name (and file base name)
directory (str|Path) – log directory
config_data (dict) – logging configuration (the “ProcessLogs” value evaluates to list of dictionary with process_logs section values)
level – logger’s logging level (default: logging.DEBUG)
- Returns:
configured logger
- Return type:
logging.Logger
- glideinwms.lib.logSupport.get_processlog_handler(log_file_name, log_dir, msg_types, extension, maxDays, minDays, maxMBytes, backupCount=5, compression=None)[source]¶
Return a configured handler for the GlideinLogger logger
The file name is “{log_dir}/{log_file_name}.{extension.lower()}.log” and can include env variables
- Parameters:
log_file_name (str) – log file name (same as the logger name)
log_dir (str|Path) – log directory
msg_types (str) – log levels to include (comma separated list). Keywords are: DEBUG,INFO,WARN,ERR, ADMIN or ALL (ADMIN and ALL both mean all the previous) ADMIN adds also the “admin” prefix to the log_file_name
extension (str) – file name extension
maxDays (float) – Max number of days before file rotation (fraction of day accepted, used in unit test)
minDays (float) – Minimum number of days before file rotation (used with max MBytes)
maxMBytes (float) – Maximum size of the logfile in MB before file rotation (used with min days)
backupCount (int) – Number of backups to keep
compression (str) – Compression to use (gz, zip, depending on available compression modules)
- Returns:
configured handler
- Return type:
glideinwms.lib.pidSupport module¶
- class glideinwms.lib.pidSupport.PidWParentSupport(pid_fname)[source]¶
Bases:
PidSupport
glideinwms.lib.pubCrypto module¶
pubCrypto - This module defines classes to perform public key cryptography
It uses M2Crypto: https://github.com/mcepl/M2Crypto a wrapper around OpenSSL: https://www.openssl.org/docs/man1.1.1/man3/
- NOTE For convenience and consistency w/ previous versions of this module, Encryption/Signing functions
(b64, hex and .encrypt() ) accept bytes-like objects (bytes, bytearray) and also Unicode strings utf-8 encoded (defaults.BINARY_ENCODING_CRYPTO). B64 and hex Decryption functions, consistent w/ Python’s binascii.a2b_* functions, accept bytes and Unicode strings containing only ASCII characters, .decrypt() only accepts bytes-like objects (such as bytes, bytearray and other objects that support the buffer protocol). All these functions return bytes.
Keys can be loaded from AnyStr (str, bytes, bytearray). Keys are returned as bytes string. Key files are binary.
- exception glideinwms.lib.pubCrypto.PubCryptoError(msg)[source]¶
Bases:
Exception
Exception masking M2Crypto exceptions, to ease error handling in modules importing pubCrypto
- class glideinwms.lib.pubCrypto.PubRSAKey(key_str=None, key_fname=None, encryption_padding=4, sign_algo='sha256')[source]¶
Bases:
object
Public part of the RSA key
- _load_from_bio(bio)[source]¶
Load the key into the object
Protected, overridden by child classes. Used by load
- Parameters:
bio (M2Crypto.BIO.BIO) – BIO to retrieve the key from (file or memory buffer)
- _save_to_bio(bio)[source]¶
Save the key from the object
Protected, overridden by child classes. Used by save and get
- Parameters:
bio (M2Crypto.BIO.BIO) – BIO object to save the key to (file or memory buffer)
- Returns:
status returned by M2Crypto.m2.rsa_write_pub_key
- Return type:
int
- Raises:
KeyError – if the key is not defined
- encrypt(data)[source]¶
Encrypt the data
- Parameters:
data (AnyStr) – string to encrypt. bytes-like or str. If unicode, it is encoded using utf-8 before being encrypted. len(data) must be less than len(key)
- Returns:
encrypted data
- Return type:
bytes
- load(key_str=None, key_fname=None)[source]¶
Load key from a string or a file
Only one of the two can be defined (not None) Load the key into self.rsa_key
- Parameters:
key_str (str/bytes) – string w/ base64 encoded key Must be bytes-like object or ASCII string, like base64 inputs
key_fname (str) – file name
- Raises:
ValueError – if both key_str and key_fname are defined
- save(key_fname)[source]¶
Save the key to a file
The file is binary and is written using M2Crypto.BIO
- Parameters:
key_fname (str) – file name
Returns:
- verify(data, signature)[source]¶
Verify that the signature gets you the data
- Parameters:
data (AnyStr) – string to verify. bytes-like or str. If unicode, it is encoded using utf-8 before being encrypted. :
signature (bytes) – signature to use in the verification
- Returns:
True if the signature gets you the data
- Return type:
bool
- Raises:
KeyError – if the key is not defined
- class glideinwms.lib.pubCrypto.RSAKey(key_str=None, key_fname=None, private_cipher='aes_256_cbc', private_callback=<function _default_callback>, encryption_padding=4, sign_algo='sha256')[source]¶
Bases:
PubRSAKey
Public and private part of the RSA key
- PubRSAKey()[source]¶
Return the public part only. Downgrade to PubRSAKey
- Returns:
an object w/ only the public part of the key
- Return type:
- _load_from_bio(bio)[source]¶
Load the key into the object
Internal, overrides the parent _load_from_bio. Used by load
- Parameters:
bio (M2Crypto.BIO.BIO)
- _save_to_bio(bio)[source]¶
Save the key from the object
Protected, overridden by child classes. Used by save and get
- Parameters:
bio (M2Crypto.BIO.BIO) – BIO to save the key into (file or memory buffer)
Returns:
- Raises:
KeyError – if the key is not defined
- decrypt(data)[source]¶
Decrypt data inline
- Parameters:
data (bytes) – data to decrypt
- Returns:
decrypted string
- Return type:
bytes
- Raises:
KeyError – if the key is not defined
- new(key_length=None, exponent=65537)[source]¶
Refresh/Generate a new key and store it in the object
- Parameters:
key_length (int/None) – if no key_length provided, use the length of the existing one
exponent (int) – exponent
- glideinwms.lib.pubCrypto._default_callback(*args)[source]¶
Return a dummy passphrase
Good for service key processing where human not present. Used as a callback in the :mod:M2Crypto module:
A Python callable object that is invoked to acquire a passphrase with which to unlock the key. The default is :func:M2Crypto.util.passphrase_callback
def passphrase_callback(v: bool, prompt1: str = 'Enter passphrase:', prompt2: str = 'Verify passphrase:' ): -> Optional[str]
- Parameters:
*args
- Returns:
str or None
- Return type:
Optional[str]
glideinwms.lib.rrdSupport module¶
This module implements the basic functions needed to interface to rrdtool
- class glideinwms.lib.rrdSupport.BaseRRDSupport(rrd_obj)[source]¶
Bases:
object
- create_rrd(rrdfname, rrd_step, rrd_archives, rrd_ds)[source]¶
Create a new RRD archive
- Parameters:
archive (rrdfname - File path name of the RRD)
seconds (rrd_step - base interval in)
tuples (rrd_archives - list of) – CF - consolidation function (usually AVERAGE) xff - xfiles factor (fraction that can be unknown) steps - how many of these primary data points are used to build a consolidated data point rows - how many generations of data values are kept
fileds (each containing the following) – CF - consolidation function (usually AVERAGE) xff - xfiles factor (fraction that can be unknown) steps - how many of these primary data points are used to build a consolidated data point rows - how many generations of data values are kept
fields (rrd_ds - a tuple containing the following) – ds-name - attribute name DST - Data Source Type (usually GAUGE) heartbeat - the maximum number of seconds that may pass between two updates before it becomes unknown min - min value max - max value
- For more details see
- create_rrd_multi(rrdfname, rrd_step, rrd_archives, rrd_ds_arr)[source]¶
Create a new RRD archive
- Parameters:
archive (rrdfname - File path name of the RRD)
seconds (rrd_step - base interval in)
tuples (rrd_ds_arr - list of) – CF - consolidation function (usually AVERAGE) xff - xfiles factor (fraction that can be unknown) steps - how many of these primary data points are used to build a consolidated data point rows - how many generations of data values are kept
fileds (each containing the following) – CF - consolidation function (usually AVERAGE) xff - xfiles factor (fraction that can be unknown) steps - how many of these primary data points are used to build a consolidated data point rows - how many generations of data values are kept
tuples – ds-name - attribute name DST - Data Source Type (usually GAUGE) heartbeat - the maximum number of seconds that may pass between two updates before it becomes unknown min - min value max - max value
fields (each containing the following) – ds-name - attribute name DST - Data Source Type (usually GAUGE) heartbeat - the maximum number of seconds that may pass between two updates before it becomes unknown min - min value max - max value
- For more details see
- fetch_rrd(filename, CF, resolution=None, start=None, end=None, daemon=None)[source]¶
Fetch will analyze the RRD and try to retrieve the data in the resolution requested.
- Parameters:
from (filename -the name of the RRD you want to fetch data)
data (CF -the consolidation function that is applied to the) – you want to fetch (AVERAGE, MIN, MAX, LAST)
have (resolution -the interval you want your values to) – (default 300 sec)
series (end -end of the time)
series
specified (daemon -Address of the rrdcached daemon. If) – command is sent to the server before reading the RRD files. This allows rrdtool to return fresh data even if the daemon is configured to cache values for a long time.
flush (a) – command is sent to the server before reading the RRD files. This allows rrdtool to return fresh data even if the daemon is configured to cache values for a long time.
- For more details see
- rrd2graph(fname, rrd_step, ds_name, ds_type, start, end, width, height, title, rrd_files, cdef_arr=None, trend=None, img_format='PNG')[source]¶
Create a graph file out of a set of RRD files
- Parameters:
file (fname - File path name of the graph)
files (rrd_files - list of RRD)
files
files
start
format (end - Time points in utime)
width
graph (title - Title to put in the)
graph
files – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
of (each being a tuple) – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
values (cdef_arr - list of derived RRD) –
- if present, only the cdefs will be plotted
each elsement is a tuple of (in order)
rrd_id - logical name of the RRD file (will be the graph label) cdef_formula - Derived formula in rrdtool format graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
seconds (trend - Trend value in)
- For more details see
- rrd2graph_multi(fname, rrd_step, start, end, width, height, title, rrd_files, cdef_arr=None, trend=None, img_format='PNG')[source]¶
Create a graph file out of a set of RRD files
- Parameters:
file (img_format - format of the graph)
files (rrd_files - list of RRD)
start
format (end - Time points in utime)
width
graph (title - Title to put in the)
graph
files – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file ds_name - Which attribute should I use in the RRD files ds_type - Which type should I use in the RRD files graph_type - Graph type (LINE, STACK, AREA) graph_color - Graph color in rrdtool format
of (each being a tuple) – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file ds_name - Which attribute should I use in the RRD files ds_type - Which type should I use in the RRD files graph_type - Graph type (LINE, STACK, AREA) graph_color - Graph color in rrdtool format
values (cdef_arr - list of derived RRD) –
- if present, only the cdefs will be plotted
each elsement is a tuple of (in order)
rrd_id - logical name of the RRD file (will be the graph label) cdef_formula - Derived formula in rrdtool format graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
seconds (trend - Trend value in)
file
- For more details see
- rrd2graph_multi_now(fname, rrd_step, period, width, height, title, rrd_files, cdef_arr=None, trend=None, img_format='PNG')[source]¶
Create a graph file out of a set of RRD files
- Parameters:
file (img_format - format of the graph)
files (rrd_files - list of RRD)
start=now-period (period -)
end=now
width
graph (title - Title to put in the)
graph
files – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file ds_name - Which attribute should I use in the RRD files ds_type - Which type should I use in the RRD files graph_type - Graph type (LINE, STACK, AREA) graph_color - Graph color in rrdtool format
of (each being a tuple) – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file ds_name - Which attribute should I use in the RRD files ds_type - Which type should I use in the RRD files graph_type - Graph type (LINE, STACK, AREA) graph_color - Graph color in rrdtool format
values (cdef_arr - list of derived RRD) –
- if present, only the cdefs will be plotted
each elsement is a tuple of (in order)
rrd_id - logical name of the RRD file (will be the graph label) cdef_formula - Derived formula in rrdtool format graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
seconds (trend - Trend value in)
file
- For more details see
- rrd2graph_now(fname, rrd_step, ds_name, ds_type, period, width, height, title, rrd_files, cdef_arr=None, trend=None, img_format='PNG')[source]¶
Create a graph file out of a set of RRD files
- Parameters:
file (fname - File path name of the graph)
files (rrd_files - list of RRD)
files
files
start=now-period (period -)
end=now
width
graph (title - Title to put in the)
graph
files – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
of (each being a tuple) – rrd_id - logical name of the RRD file (will be the graph label) rrd_fname - name of the RRD file graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
values (cdef_arr - list of derived RRD) –
- if present, only the cdefs will be plotted
each elsement is a tuple of (in order)
rrd_id - logical name of the RRD file (will be the graph label) cdef_formula - Derived formula in rrdtool format graph_type - Graph type (LINE, STACK, AREA) grpah_color - Graph color in rrdtool format
seconds (trend - Trend value in)
- For more details see
- update_rrd(rrdfname, time, val)[source]¶
Create an RRD archive with a new value
- Parameters:
archive (rrdfname - File path name of the RRD)
taken (time - When was the value)
value (val - What vas the)
- update_rrd_multi(rrdfname, time, val_dict)[source]¶
Create an RRD archive with a set of values (possibly all of the supported)
- Parameters:
archive (rrdfname - File path name of the RRD)
taken (time - When was the value)
value (val_dict - What was the)
- verify_rrd(filename, expected_dict)[source]¶
Verifies that an rrd matches a dictionary of datastores. This will return a tuple of arrays ([missing],[extra]) attributes
@param filename: filename of the rrd to verify @param expected_dict: dictionary of expected values @return: A two-tuple of arrays ([missing attrs],[extra attrs])
- class glideinwms.lib.rrdSupport.DummyDiskLock[source]¶
Bases:
object
Dummy, do nothing. Used just to get a object
- class glideinwms.lib.rrdSupport.ExeRRDSupport[source]¶
Bases:
BaseRRDSupport
- class glideinwms.lib.rrdSupport.ModuleRRDSupport[source]¶
Bases:
BaseRRDSupport
- glideinwms.lib.rrdSupport.addDataStore(filenamein, filenameout, attrlist)[source]¶
Add a list of data stores to a rrd export file This will essentially add attributes to the end of a rrd row
@param filenamein: filename path of a rrd exported with rrdtool dump @param filenameout: filename path of output xml with datastores added @param attrlist: array of datastores to add
- class glideinwms.lib.rrdSupport.rrdSupport[source]¶
Bases:
BaseRRDSupport
- class glideinwms.lib.rrdSupport.rrdtool_exe[source]¶
Bases:
object
This class is a wrapper around the rrdtool client (binary) and is used in place of the rrdtool python module, if that one is not available
It provides also extra functions: dump: returns an array of lines with the content instead of saving the RRD in an XML file restore: allows the restore of a DB
- dump(*args)[source]¶
Run rrd_tool dump
Input is usually just the file name. Output is a list of lines, as returned from rrdtool dump. This is different from the dump method provided by the rrdtool package (Python binding) which outputs to a file or stdout
- Parameters:
*args – rrdtool dump arguments, joined in single string for the command line
- Returns:
multi-line string, output of rrd dump
- Return type:
str
- glideinwms.lib.rrdSupport.verifyHelper(filename, data_dict, fix_rrd=False, backup=True)[source]¶
Helper function for verifyRRD. Checks one file, prints out errors. if fix_rrd, will attempt to dump out rrd to xml, add the missing attributes, then restore. Original file is backed up with time stamp if backup is True, obliterated otherwise.
- Parameters:
filename (str) – filename of rrd to check
data_dict (dict) – expected dictionary
fix_rrd (bool) – if True, will attempt to add missing attrs
backup (bool) – if not True skip the backup of original rrd
- Returns:
True if there were some problem with the RRD file, False if all OK
- Return type:
bool
glideinwms.lib.servicePerformance module¶
- class glideinwms.lib.servicePerformance.PerfMetric(name)[source]¶
Bases:
object
Class to store performance metrics for different events in a service
glideinwms.lib.subprocessSupport module¶
Fork a process and run a command
- glideinwms.lib.subprocessSupport.iexe_cmd(cmd, useShell=False, stdin_data=None, child_env=None, text=True, encoding=None, timeout=None, log=None)[source]¶
Fork a process and execute cmd
Using process.communicate() automatically handling buffers to avoid deadlocks. Before it had been rewritten to use select to avoid filling up stderr and stdout queues.
The useShell value of True should be used sparingly. It allows for executing commands that need access to shell features such as pipes, filename wildcards. Refer to the python manual for more information on this. When used, the ‘cmd’ string is not tokenized.
One possible improvement would be to add a function to accept an array instead of a command string.
- Parameters:
cmd (str) – String containing the entire command including all arguments
useShell (bool) – if True run the command in a shell (passed to Popen as shell)
stdin_data (str/bytes) – Data that will be fed to the command via stdin. It should be bytes if text is False and encoding is None, str otherwise
child_env (dict) – Environment to be set before execution
text (bool) – if False, then stdin_data and the return value are bytes instead of str (default: True)
encoding (str|None) – encoding to use for the streams. If None (default) and text is True, then the defaults.BINARY_ENCODING_DEFAULT (utf-8) encoding is used
timeout (None|int) – timeout in seconds. No timeout by default
log (logger) – optional logger for debug and error messages
- Returns:
- output of the command. It will be bytes if text is False,
str otherwise
- Return type:
str/bytes
- Raises:
subprocess.CalledProcessError – if the subprocess fails (exit status not 0)
RuntimeError – if it fails to invoke the subprocess or the subprocess times out
glideinwms.lib.symCrypto module¶
symCrypto - This module defines classes to perform symmetric key cryptography (shared or hidden key)
It uses M2Crypto: https://github.com/mcepl/M2Crypto a wrapper around OpenSSL: https://www.openssl.org/docs/man1.1.1/man3/
- NOTE For convenience and consistency w/ previous versions of this module, Encryption/Signing functions
(b64, hex and .encrypt() ) accept bytes-like objects (bytes, bytearray) and also Unicode strings utf-8 encoded (defaults.BINARY_ENCODING_CRYPTO). B64 and hex Decryption functions, consistent w/ Python’s binascii.a2b_* functions, accept bytes and Unicode strings containing only ASCII characters, .decrypt() only accepts bytes-like objects (such as bytes, bytearray and other objects that support the buffer protocol). All these functions return bytes.
Key definitions accept AnyStr (str, bytes, bytearray), key_str are iv_str bytes, key_iv_code is a str, so is the key
- class glideinwms.lib.symCrypto.AutoSymKey(key_iv_code=None)[source]¶
Bases:
MutableSymKey
Symmetric Keys from code strings. Get cypher name from key_iv_code
- class glideinwms.lib.symCrypto.MutableSymKey(cypher_name=None, key_len=None, iv_len=None, key_str=None, iv_str=None, key_iv_code=None)[source]¶
Bases:
SymKey
SymKey class, allows to change the crypto after instantiation
- get_wcrypto()[source]¶
Get the stored key and the crypto name
- Returns:
cypher name bytes: key string bytes: iv string
- Return type:
str
- class glideinwms.lib.symCrypto.ParametrizedSymKey(cypher_name, key_str=None, iv_str=None, key_iv_code=None)[source]¶
Bases:
SymKey
Helper class to build different types of Symmetric Keys from a parameter dictionary (cypher_dict).
- class glideinwms.lib.symCrypto.Sym3DESKey(key_str=None, iv_str=None, key_iv_code=None)[source]¶
Bases:
ParametrizedSymKey
- class glideinwms.lib.symCrypto.SymAES128Key(key_str=None, iv_str=None, key_iv_code=None)[source]¶
Bases:
ParametrizedSymKey
- class glideinwms.lib.symCrypto.SymAES256Key(key_str=None, iv_str=None, key_iv_code=None)[source]¶
Bases:
ParametrizedSymKey
- class glideinwms.lib.symCrypto.SymKey(cypher_name, key_len, iv_len, key_str=None, iv_str=None, key_iv_code=None)[source]¶
Bases:
object
Symmetric keys cryptography
You probably don’t want to use this, use the child classes instead
self.key_str and self.iv_str are bytes (strings) with HEX encoded data
- Available ciphers, too many to list them all, try man enc, a few of them are:
‘aes_128_cbc’ ‘aes_128_ofb ‘aes_256_cbc’ ‘aes_256_cfb’ ‘bf_cbc’ ‘des3’
- decrypt(data)[source]¶
Decrypt data inline
- Parameters:
data (bytes) – data to decrypt
- Returns:
decrypted data
- Return type:
bytes
- Raises:
KeyError – if there is no valid crypto key
- decrypt_base64(data)[source]¶
like decrypt, but the input is base64 encoded
- Parameters:
data (AnyStrASCII) – Base64 input data. bytes or ASCII encoded Unicode str
- Returns:
decrypted data
- Return type:
bytes
- decrypt_hex(data)[source]¶
like decrypt, but the input is hex encoded
- Parameters:
data (AnyStrASCII) – HEX input data. bytes or ASCII encoded Unicode str
- Returns:
decrypted data
- Return type:
bytes
- encrypt(data)[source]¶
Encrypt data inline
- Parameters:
data (AnyStr) – data to encrypt
- Returns:
encrypted data
- Return type:
bytes
- Raises:
KeyError – if there is no valid crypto key
- get()[source]¶
Get the key and initialization vector
- Returns:
(key, iv) tuple wehere both key and iv are bytes
- Return type:
tuple
- get_code()[source]¶
Return the key code: cypher, key, iv, as a comma separated string
- Returns:
key description in the string
- Return type:
str
- is_valid()[source]¶
Return true if the key is valid
- Returns:
True if the key string is not None
- Return type:
bool
- load(key_str=None, iv_str=None, key_iv_code=None)[source]¶
Load a new key from text (str/bytes)
- Parameters:
key_str (str/bytes) – string w/ base64 encoded key Must be bytes-like object or ASCII string, like base64 inputs
iv_str (str/bytes) – initialization vector
key_iv_code (str/bytes) – comma separated text with cypher, key, iv
Returns:
glideinwms.lib.tarSupport module¶
- exception glideinwms.lib.tarSupport.FileDoesNotExist(full_path)[source]¶
Bases:
Exception
File does not exist exception
@note: Include the file name in the full_path @ivar full_path: The full path to the missing file. Includes the file name
- class glideinwms.lib.tarSupport.GlideinTar[source]¶
Bases:
object
This class provides a container for creating tarballs. The class provides methods to add files and string data (ends up as a file in the tarball). The tarball can be written to a file on disk or written to memory.
- add_file(filename, arc_dirname)[source]¶
Add a filepath to the files list
@type filename: string @param filename: The file path to the file that will eventually be written to the tarball. @type arc_dirname: string @param arc_dirname: This is the directory that the file will show up under in the tarball
- add_string(name, string_data)[source]¶
Add a string to the string dictionary.
@type name: string @param name: A string specifying the “filename” within the tarball that the string_data will be written to. @type string_data: string @param string_data: The contents that will be written to a “file” within the tarball.
- create_tar(tf)[source]¶
Takes the provided tar file object and adds all the specified data to it. The strings dictionary is parsed such that the key name is the file name and the value is the file data in the tar file.
@type tf: Tar File @param tf: The Tar File Object that will be written to
- create_tar_blob(compression='gz')[source]¶
Creates a tarball and writes it out to memory
- @Note: we don’t have to worry about ReadError, since we don’t allow
appending. We only write to a tarball on create.
@param fd: The file that the tarball will be written to @param compression: The type of compression that should be used
- @raise glideinwms_tarfile.CompressionError: This exception can be raised is an
invalid compression type has been passed in
- create_tar_file(archive_full_path, compression='gz')[source]¶
Creates a tarball and writes it out to the file specified in fd
- @Note: we don’t have to worry about ReadError, since we don’t allow
appending. We only write to a tarball on create.
@param fd: The file that the tarball will be written to @param compression: The type of compression that should be used
- @raise glideinwms_tarfile.CompressionError: This exception can be raised is an
invalid compression type has been passed in
- is_tarfile(full_path)[source]¶
Checks to see if the tar file specified is valid and can be read. Returns True if the file is a valid tar file and it can be read. Returns False if not valid or it cannot be read.
@param full_path: The full path to the tar file. Includes the file name
@return: True/False
glideinwms.lib.timeConversion module¶
glideinwms.lib.token_util module¶
Collection of utility functions for HTCondor IDTOKEN generation and verification
- glideinwms.lib.token_util.create_and_sign_token(pwd_file, issuer=None, identity=None, kid=None, duration=None, scope=None)[source]¶
Create an HTCSS IDTOKEN
This should be compatible with the HTCSS code to create tokens.
- Parameters:
pwd_file – (str) file containing an HTCondor password
issuer – (str, optional) default is HTCondor TRUST_DOMAIN
identity – (str, optional) identity claim, default is $USERNAME@$HOSTNAME
kid – (str, optional) Key id, hint of signature used. Default is file name of password
duration – (int, optional) number of seconds IDTOKEN is valid. Default is infinity
scope –
- (str, optional) permissions IDTOKEN will have.
Default is everything,
example: condor:/READ condor:/WRITE condor:/ADVERTISE_STARTD
- Returns:
a signed HTCondor IDTOKEN
- Return type:
str
- glideinwms.lib.token_util.derive_master_key(password)[source]¶
Derive an encryption/decryption key
Source: https://github.com/CoffeaTeam/coffea-casa/blob/master/charts/coffea-casa/files/hub-extra/auth.py
- Parameters:
password (bytes) – an unscrambled HTCondor password (bytes-like: bytes, bytearray, memoryview)
- Returns:
an HTCondor encryption/decryption key
- Return type:
bytes
- glideinwms.lib.token_util.sign_token(identity, issuer, kid, master_key, duration=None, scope=None)[source]¶
Assemble and sign an idtoken
- Parameters:
identity (str) – who the token was generated for
issuer (str) – idtoken issuer, typically HTCondor Collector
kid (str) – Key ID
master_key (bytes) – encryption key
duration (int, optional) – number of seconds IDTOKEN is valid. Default: infinity
scope (str, optional) – permissions IDTOKEN has. Default: everything
- Returns:
a signed IDTOKEN (jwt token)
- Return type:
str
- glideinwms.lib.token_util.simple_scramble(in_buf)[source]¶
Undo the simple scramble of HTCondor
simply XOR with 0xdeadbeef Source: https://github.com/CoffeaTeam/coffea-casa/blob/master/charts/coffea-casa/files/hub-extra/auth.py
- Parameters:
data (bytearray) – binary string to be unscrambled
- Returns:
an HTCondor scrambled binary string
- Return type:
bytearray
- glideinwms.lib.token_util.token_file_expired(token_file)[source]¶
Check validity of token exp and nbf claim. Do not check signature, audience, or other claims
- Parameters:
token_file (Path or str) – a filename containing a jwt (a text file w/ default encoding is expected)
- Returns:
- True if exp in future or absent and nbf in past or absent,
False otherwise
- Return type:
bool
- glideinwms.lib.token_util.token_str_expired(token_str)[source]¶
Check validity of token exp and nbf claim. Do not check signature, audience, or other claims
- Parameters:
token_str (str) – string containing a jwt
- Returns:
- True if exp in future or absent and nbf in past or absent,
False otherwise
- Return type:
bool
glideinwms.lib.unparser module¶
Usage (for testing, will do roundtrips on the files): unparse.py <path to source files> unparse.py –testdir <path to source files directories>
- class glideinwms.lib.unparser.Unparser(tree, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Bases:
object
Methods in this class recursively traverse an AST and output source code for the abstract syntax; original formatting is disregarded.
- __For_helper(fill, t)¶
- __FunctionDef_helper(t, fill_suffix)¶
- binop = {'Add': '+', 'BitAnd': '&', 'BitOr': '|', 'BitXor': '^', 'Div': '/', 'FloorDiv': '//', 'LShift': '<<', 'MatMult': '@', 'Mod': '%', 'Mult': '*', 'Pow': '**', 'RShift': '>>', 'Sub': '-'}¶
- boolops = {<class 'ast.And'>: 'and', <class 'ast.Or'>: 'or'}¶
- cmpops = {'Eq': '==', 'Gt': '>', 'GtE': '>=', 'In': 'in', 'Is': 'is', 'IsNot': 'is not', 'Lt': '<', 'LtE': '<=', 'NotEq': '!=', 'NotIn': 'not in'}¶
- unop = {'Invert': '~', 'Not': 'not', 'UAdd': '+', 'USub': '-'}¶
- glideinwms.lib.unparser.interleave(inter, f, seq)[source]¶
Call f on each item in seq, calling inter() in between.
glideinwms.lib.util module¶
This is a collection of utilities functions for file handling and other
- exception glideinwms.lib.util.ExpiredFileException[source]¶
Bases:
Exception
The file is too old to be used
- glideinwms.lib.util.chmod(*args, **kwargs)[source]¶
Wrapper for os.chmod that supresses PermissionError exceptions
- Parameters:
*args – Positional arguments to pass to os.chmod
**kwargs – Keyword arguments to pass to os.chmod
- Returns:
None
- glideinwms.lib.util.conditional_raise(mask_exceptions)[source]¶
Auxiliary function to handle conditional raising
- Parameters:
mask_exceptions – callback function and arguments to use if an exception happens (Default: None) The callback function can access the exception via sys.exc_info() If a function is not provided, the exception is re-risen if provided it is called using mask_exceptions[0](*mask_exceptions[1:])
- Returns:
None
- glideinwms.lib.util.dict_normalize(in_dict, keys=None, prefix='', suffix='', default=None)[source]¶
Change the keys of a dictionary
- Parameters:
in_dict – input dictionary
keys – key list, if None it is using in_dict.keys() (Default: None)
prefix – prefix for the keys (Default “”)
suffix – suffix for the keys (Default “”)
default – default value passed to get (Default: None)
- Returns:
normalized dictionary
- glideinwms.lib.util.dict_to_flat(in_dict, prefix='', suffix='', sep='')[source]¶
Flatten a multi-level dictionary to one level The resulting keys are the string concatenation of the original ones A separator can be added between keys
NOTE: Value could be clobbered if there are duplicates in the strings resulting from concatenating keys, e.g. {‘a’:{‘b’:1}, ‘ab’:2} A separator will not solve the problem if it is a valid character for the keys
- Parameters:
in_dict – input dictionary
prefix – prefix for the keys (Default “”)
suffix – suffix for the keys (Default “”)
sep – separator between keys (Default: “”)
- Returns:
flattened dictionary
- glideinwms.lib.util.dict_to_flat_slow(in_dict, prefix='', suffix='')[source]¶
Flatten a multi-level dictionary to one level The resulting keys are the string concatenation of the original ones
- Parameters:
in_dict – input dictionary
prefix – prefix for the keys (Default “”)
suffix – suffix for the keys (Default “”)
- Returns:
flattened dictionary
- glideinwms.lib.util.file_get_tmp(fname=None, tmp_type=None)[source]¶
Get the name of a temporary file Depending on the option chosen this may be unsafe: .tmp suffix is OK only if no one else will use this file .$PID.tmp is OK if no multithreading is used and there are no safety concerns (name easy to guess, attacks prone) tempfile from tempfile.mkstemp() that guarantees uniqueness and safety
@param fname: original file name @param tmp_type: type of temporary file name (Default: None):
None (or anything False) - ‘.tmp’ suffix added to the file name (unsafe, may be conflicts if )
PID - ‘.$PID.tmp’ suffix added to the file name
REAL (or anything else) - real tempfile (unique and safe, using tempfile.mkstemp())
@return: tamporary file name
- glideinwms.lib.util.file_pickle_dump(fname, content, tmp_type='PID', mask_exceptions=None, protocol=5)[source]¶
Serialize and save content
To avoid inconsistent content :param fname: file storing the serialized content :param content: content to serialize :param tmp_type: tmp file type as defined in file_get_tmp (Default: PID, .$PID.tmp suffix) :param mask_exceptions: callback function and arguments to use if an exception happens (Default: None)
The callback function can access the exception via sys.exc_info() If a function is not provided, the exception is re-risen if provided it is called using mask_exceptions[0](*mask_exceptions[1:])
- Parameters:
protocol – Pickle protocol to be used (Default: pickle.HIGHEST_PROTOCOL, 5 as of py3.8)
- Returns:
True if the saving was successful, False or an exception otherwis
- Return type:
bool
- glideinwms.lib.util.file_pickle_load(fname, mask_exceptions=None, default=None, expiration=-1, remove_expired=False, last_time={})[source]¶
Load a serialized dictionary
This implementation does not use file locking, it relies on the atomicity of file movement/replacement and deletion
- Parameters:
fname – name of the file with the serialized data
mask_exceptions – callback function and arguments to use if an exception happens (Default: None) The callback function can access the exception via sys.exc_info() If a function is not provided, the exception is re-risen if provided it is called using mask_exceptions[0](*mask_exceptions[1:])
default – value returned if the unpickling fails (Default: None)
expiration (int) – input file expiration in seconds (Default: -1) -1 file never expires 0 file always expires after reading
remove_expired (bool) – remove expired file (Default: False) NOTE: if you remove the obsolete file from the reader you may run into a race condition with undesired effects: 1. the reader detects the obsolete file, 2. the writer writes a new version, 3. the reader deletes the new version This can happen only in cycles where there is an obsolete data file to start with, so the number of data files lost because of this is smaller than the occurrences of obsoleted files. When the expiration time is much bigger than the loop time of the writer this is generally acceptable.
last_time (dict) – last time a file has been used, persistent to keep history (Default: {}, first time called) Dictionary file_name->time
- Returns:
python objects (e.g. data dictionary)
- Return type:
Object
- glideinwms.lib.util.file_tmp2final(fname, tmp_fname=None, bck_fname=None, do_backup=True, mask_exceptions=None, log=None, do_print=False)[source]¶
Complete an atomic write by moving a file new version to its destination.
If do_backup is True it removes the previous backup and copies the file to bak_fname. Moves tmp_fname to fname.
- Parameters:
fname (str) – name of the file
tmp_fname (str|None) – name of the temporary file with the new version of the content (Default: <fname>.tmp)
bck_fname (str|None) – name of a backup of the old version (Default: <fname>~)
do_backup (bool) – do a backup of the old version only if True (Default: True)
mask_exceptions – callback function and arguments to use if an exception happens (Default: None) The callback function can access the exception via sys.exc_info() If a function is not provided, the exception is re-risen if provided it is called using mask_exceptions[0](*mask_exceptions[1:])
log
do_print
- Returns:
False if the move caused an exception. True otherwise
- Return type:
bool
- glideinwms.lib.util.flattenDict(d, join=<built-in function add>, lift=<function <lambda>>)[source]¶
Flexible flattening of a dictionary
- Parameters:
d – dictionary to flatten
join – join function for the keys (allows to concatenate strings)
lift – lift function for the keys (allows to create tuples)
- Returns:
list with flattened dictionary
>>> testData = { 'a':1, 'b':2, 'c':{ 'aa':11, 'bb':22, 'cc':{ 'aaa':111 } } } >>> from pprint import pprint as pp
>>> pp(dict( flattenDict(testData, lift=lambda x:(x,)) )) {('a',): 1, ('b',): 2, ('c', 'aa'): 11, ('c', 'bb'): 22, ('c', 'cc', 'aaa'): 111}
>>> pp(dict( flattenDict(testData, join=lambda a,b:a+'_'+b) )) {'a': 1, 'b': 2, 'c_aa': 11, 'c_bb': 22, 'c_cc_aaa': 111}
>>> pp(dict( (v,k) for k,v in flattenDict(testData, lift=hash, join=lambda a,b:hash((a,b))) )) {1: 12416037344, 2: 12544037731, 11: 5470935132935744593, 22: 4885734186131977315, 111: 3461911260025554326}
- glideinwms.lib.util.handle_hooks(basedir, script_dir)[source]¶
The function itaretes over the script_dir directory and executes any script found there
- glideinwms.lib.util.hash_nc(data, len=None)[source]¶
Returns a non-cryptographic MD5 hash encoded in base32
- Parameters:
data (AnyStr) – Data to hash
len (int, optional) – Hash length. Defaults to None.
- Returns:
Hash
- Return type:
str
- glideinwms.lib.util.import_module(module, search_path=None)[source]¶
Import a module by name or path
- Parameters:
module (str) – Module name, module path, file name, or file path.
search_path (str or list of str, optional) – Search path for the module. Defaults to None.
- Raises:
ValueError – Invalid search_path
ImportError – Failed to import the module
- Returns:
Imported module
- Return type:
module
- glideinwms.lib.util.is_true(value)[source]¶
Case-insensitive “True” string parsing helper. Return True for true (case-insensitive string representation matching), False otherwise.
- Parameters:
value – argument to evaluate as True or False. Can be any type.
- Returns:
True if the string representation of value is “true”
- Return type:
bool
- glideinwms.lib.util.print_funct(*args, **kwargs)[source]¶
Print function that can be used as mask exception (the print statement cannot be passed as parameter)
- Parameters:
args – list of what to print, converted into string and separated by ‘sep’
kwargs – keywords, valid keywords: ‘sep’ separator, default is space
- Returns:
None
- glideinwms.lib.util.safe_boolcomp(value, expected)[source]¶
Safely do a boolean comparison.
This works even if the value you wantto compare is a string.
- Parameters:
value – what you want to safely compare
expected (bool) – What you want to compare value with
- Returns:
True if str(value).lower() is True
- Return type:
bool
glideinwms.lib.x509Support module¶
- glideinwms.lib.x509Support.extract_DN(fname)[source]¶
Extract a Distinguished Name from an X.509 proxy.
Get the proxy subject: the subject of the first certificate starting form the bottom of the chain (PEM format) that is not a CA. This is necessary to skip the proxies at the beginning and get the subject of the user/server certificate.
- Parameters:
fname (str) – Filename containing the X.509 proxy
- Returns:
- Proxy subject in oneline format
”” if invalid proxy file
- Return type:
bytes
glideinwms.lib.xmlFormat module¶
General purpose XML formatter
# This module is a generic purpose XML formatter # # Six functions are defined: # class2string - converts a class or a dictionary into an XML string # class fields or dictionary keys are used as XML tags # dict2string - converts a dictionary or a list (or tuple) into an XML string # keys or indexes are used as parameters, not tags # list2string - converts a list or a dictionary into an XML string # no indexes here, only the values are used # in case of a dictionary, keys are used and the values are ignored # # class2file - write a class or a dictionary into an open file as an XML string # class fields or dictionary keys are used as XML tags # dict2file - write a dictionary or a list (or tuple) into an open file as an XML string # keys or indexes are used as parameters, not tags # list2file - write a list or a dictionary into an open file as an XML string # no indexes here, only the values are used # in case of a dictionary, keys are used and the values are ignored # #########################################################################################
- glideinwms.lib.xmlFormat.class2file(fd, inst, inst_name, params={}, subclass_params={}, dicts_params=None, lists_params=None, tree_params=None, text_params=None, indent_tab=' ', leading_tab='', debug_str='')[source]¶
- glideinwms.lib.xmlFormat.class2head(inst, inst_name, params, dicts_params, lists_params, tree_params, text_params, leading_tab, debug_str)[source]¶
- glideinwms.lib.xmlFormat.class2string(inst, inst_name, params={}, subclass_params={}, dicts_params=None, lists_params=None, tree_params=None, text_params=None, indent_tab=' ', leading_tab='', debug_str='', override_dictionary_type=None)[source]¶
- glideinwms.lib.xmlFormat.dict2file(fd, dict_data, dict_name, el_name, dict_attr_name='name', el_attr_name=None, params={}, subtypes_params={}, indent_tab=' ', leading_tab='', debug_str='')[source]¶
- glideinwms.lib.xmlFormat.dict2string(dict_data, dict_name, el_name, dict_attr_name='name', el_attr_name=None, params={}, subtypes_params={}, indent_tab=' ', leading_tab='', debug_str='')[source]¶
- glideinwms.lib.xmlFormat.list2file(fd, list_data, list_name, el_name, el_attr_name=None, params={}, subtypes_params={}, indent_tab=' ', leading_tab='', debug_str='')[source]¶
- glideinwms.lib.xmlFormat.list2string(list_data, list_name, el_name, el_attr_name=None, params={}, subtypes_params={}, indent_tab=' ', leading_tab='', debug_str='')[source]¶
- glideinwms.lib.xmlFormat.tree2file(fd, tree, tree_name, child_element, indent_tab=' ', leading_tab='', debug_str='')[source]¶
glideinwms.lib.xmlParse module¶
- class glideinwms.lib.xmlParse.OrderedDict2(dict=None)[source]¶
Bases:
UserDict
- _abc_impl = <_abc._abc_data object>¶
- popitem() (k, v), remove and return some (key, value) pair [source]¶
as a 2-tuple; but raise KeyError if D is empty.
- glideinwms.lib.xmlParse.domel2dict(doc, use_ord_dict=False, always_singular_list=[])[source]¶
Recursive function transforming XML elements in a dictionary or list. If the node is unique (or it has attributes and the kids have no ‘name’ attribute), then a dictionary with all the attributes is returned If the element is singular of the parent (english word is analyzed):
if it has a ‘name’ attribute or the parent has attributes, a dictionary is added to the parent (name is the key) if if has no name and the parent is empty or a list, then is added to the parent (list)
- Parameters:
doc – document or ELEMENT_NODE
use_ord_dict – use ordinate dictionary if True
always_singular_list – these are considered unique singular even if the word is singular form of a plural
- Returns:
dictionary or list with the content