1- # Copyright CEA/DAM/DIF (2010, 2012, 2013, 2014 )
1+ # Copyright CEA/DAM/DIF (2010-2015 )
22# Contributors:
3- # Stephane THIELL <[email protected] > 3+ # Stephane THIELL <[email protected] > 44# Aurelien DEGREMONT <[email protected] > 55#
66# This file is part of the ClusterShell library.
@@ -77,7 +77,7 @@ class GroupResolverConfigError(GroupResolverError):
7777 """Raised when a configuration error is encountered"""
7878
7979
80- _DEFAULT_CACHE_DELAY = 3600
80+ _DEFAULT_CACHE_TIME = 3600
8181
8282
8383class GroupSource (object ):
@@ -153,12 +153,12 @@ class UpcallGroupSource(GroupSource):
153153 GroupSource class managing external calls for nodegroup support.
154154
155155 Upcall results are cached for a customizable amount of time. This is
156- controlled by `cache_delay ` attribute. Default is 3600 seconds.
156+ controlled by `cache_time ` attribute. Default is 3600 seconds.
157157 """
158158
159159 def __init__ (self , name , map_upcall , all_upcall = None ,
160160 list_upcall = None , reverse_upcall = None , cfgdir = None ,
161- cache_delay = None ):
161+ cache_time = None ):
162162 GroupSource .__init__ (self , name )
163163 self .verbosity = 0
164164 self .cfgdir = cfgdir
@@ -175,10 +175,10 @@ def __init__(self, name, map_upcall, all_upcall=None,
175175 self .has_reverse = True
176176
177177 # Cache upcall data
178- if cache_delay is None :
179- self .cache_delay = _DEFAULT_CACHE_DELAY
178+ if cache_time is None :
179+ self .cache_time = _DEFAULT_CACHE_TIME
180180 else :
181- self .cache_delay = cache_delay
181+ self .cache_time = cache_time
182182 self ._cache = {}
183183 self .clear_cache ()
184184
@@ -219,7 +219,7 @@ def _upcall_cache(self, upcall, cache, key, **args):
219219 corresponding `upcall'.
220220
221221 If `key' is missing, it is added to provided `cache'. Each entry in a
222- cache is kept only for a limited time equal to self.cache_delay .
222+ cache is kept only for a limited time equal to self.cache_time .
223223 """
224224 if not self .upcalls .get (upcall ):
225225 raise GroupSourceNoUpcall (upcall , self )
@@ -231,7 +231,7 @@ def _upcall_cache(self, upcall, cache, key, **args):
231231
232232 # Fetch the data if unknown of just purged
233233 if key not in cache :
234- cache_expiry = time .time () + self .cache_delay
234+ cache_expiry = time .time () + self .cache_time
235235 # $CFGDIR and $SOURCE always replaced
236236 args ['CFGDIR' ] = self .cfgdir
237237 args ['SOURCE' ] = self .name
@@ -277,20 +277,20 @@ class YAMLGroupLoader(object):
277277
278278 - create GroupSource objects
279279 - gather groups dict content on load
280- - reload the file once cache_delay has expired
280+ - reload the file once cache_time has expired
281281 """
282282
283- def __init__ (self , filename , cache_delay = None ):
283+ def __init__ (self , filename , cache_time = None ):
284284 """
285285 Initialize YAMLGroupLoader and load file.
286286
287287 :param filename: YAML file path
288- :param cache_delay : cache delay
288+ :param cache_time : cache time (seconds)
289289 """
290- if cache_delay is None :
291- self .cache_delay = _DEFAULT_CACHE_DELAY
290+ if cache_time is None :
291+ self .cache_time = _DEFAULT_CACHE_TIME
292292 else :
293- self .cache_delay = cache_delay
293+ self .cache_time = cache_time
294294 self .cache_expiry = 0
295295 self .filename = filename
296296 self .sources = {}
@@ -335,7 +335,7 @@ def _load(self):
335335 # else: cannot add new source on reload - just ignore it
336336
337337 # groups are loaded, set cache expiry
338- self .cache_expiry = time .time () + self .cache_delay
338+ self .cache_expiry = time .time () + self .cache_time
339339
340340 def __iter__ (self ):
341341 """Iterate over GroupSource objects."""
@@ -347,10 +347,10 @@ def groups(self, sourcename):
347347 Groups dict accessor for sourcename.
348348
349349 This method is called by associated FileGroupSource objects and simply
350- returns dict content, after reloading file if cache_delay has expired.
350+ returns dict content, after reloading file if cache_time has expired.
351351 """
352352 if self .cache_expiry < time .time ():
353- # reload whole file if cache delay expired
353+ # reload whole file if cache time expired
354354 self ._load ()
355355
356356 return self ._groups [sourcename ]
@@ -607,21 +607,21 @@ def _sources_from_cfg(self, cfg, cfgdir):
607607 if srcname != self .SECTION_MAIN :
608608 # only map is a mandatory upcall
609609 map_upcall = cfg .get (section , 'map' , True )
610- all_upcall = list_upcall = reverse_upcall = delay = None
610+ all_upcall = list_upcall = reverse_upcall = ctime = None
611611 if cfg .has_option (section , 'all' ):
612612 all_upcall = cfg .get (section , 'all' , True )
613613 if cfg .has_option (section , 'list' ):
614614 list_upcall = cfg .get (section , 'list' , True )
615615 if cfg .has_option (section , 'reverse' ):
616616 reverse_upcall = cfg .get (section , 'reverse' , True )
617- if cfg .has_option (section , 'cache_delay ' ):
618- delay = float (cfg .get (section , 'cache_delay ' , True ))
617+ if cfg .has_option (section , 'cache_time ' ):
618+ ctime = float (cfg .get (section , 'cache_time ' , True ))
619619 # add new group source
620620 self .add_source (UpcallGroupSource (srcname , map_upcall ,
621621 all_upcall ,
622622 list_upcall ,
623623 reverse_upcall ,
624- cfgdir , delay ))
624+ cfgdir , ctime ))
625625 except (NoSectionError , NoOptionError , ValueError ), exc :
626626 raise GroupResolverConfigError (str (exc ))
627627
0 commit comments