-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --nodown Option to Exclude Nodes That Are Down #449
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ | |
map: nodeattr -n $GROUP | ||
all: nodeattr -n ALL | ||
list: nodeattr -l | ||
down: whatsup -n -d || /bin/true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,8 +160,8 @@ class UpcallGroupSource(GroupSource): | |
""" | ||
|
||
def __init__(self, name, map_upcall, all_upcall=None, | ||
list_upcall=None, reverse_upcall=None, cfgdir=None, | ||
cache_time=None): | ||
list_upcall=None, down_upcall=None, reverse_upcall=None, | ||
cfgdir=None, cache_time=None): | ||
GroupSource.__init__(self, name) | ||
self.verbosity = 0 # deprecated | ||
self.cfgdir = cfgdir | ||
|
@@ -174,6 +174,8 @@ def __init__(self, name, map_upcall, all_upcall=None, | |
self.upcalls['all'] = all_upcall | ||
if list_upcall: | ||
self.upcalls['list'] = list_upcall | ||
if down_upcall: | ||
self.upcalls['down'] = down_upcall | ||
if reverse_upcall: | ||
self.upcalls['reverse'] = reverse_upcall | ||
self.has_reverse = True | ||
|
@@ -192,6 +194,7 @@ def clear_cache(self): | |
""" | ||
self._cache = { | ||
'map': {}, | ||
'down': {}, | ||
'reverse': {} | ||
} | ||
|
||
|
@@ -224,12 +227,12 @@ def _upcall_cache(self, upcall, cache, key, **args): | |
raise GroupSourceNoUpcall(upcall, self) | ||
|
||
# Purge expired data from cache | ||
if key in cache and cache[key][1] < time.time(): | ||
if key in cache and cache[key]: | ||
self.logger.debug("PURGE EXPIRED (%d)'%s'", cache[key][1], key) | ||
del cache[key] | ||
|
||
# Fetch the data if unknown of just purged | ||
if key not in cache: | ||
if key not in cache or not cache[key]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That one could make sense but could use its own commit at least, possibly its own PR. |
||
cache_expiry = time.time() + self.cache_time | ||
# $CFGDIR and $SOURCE always replaced | ||
args['CFGDIR'] = self.cfgdir | ||
|
@@ -252,6 +255,12 @@ def resolv_list(self): | |
""" | ||
return self._upcall_cache('list', self._cache, 'list') | ||
|
||
def resolv_down(self): | ||
""" | ||
Return a list of all nodes that are down in this group. | ||
""" | ||
return self._upcall_cache('down', self._cache, 'down') | ||
|
||
def resolv_all(self): | ||
""" | ||
Return the content of special group ALL, using the cached value | ||
|
@@ -496,6 +505,13 @@ def all_nodes(self, namespace=None): | |
source = self._source(namespace) | ||
return self._list_nodes(source, 'all') | ||
|
||
def down_nodes(self, namespace=None): | ||
""" | ||
Find all nodes. You may specify an optional namespace. | ||
""" | ||
source = self._source(namespace) | ||
return self._list_nodes(source, 'down') | ||
|
||
def grouplist(self, namespace=None): | ||
""" | ||
Get full group list. You may specify an optional | ||
|
@@ -653,23 +669,28 @@ def _sources_from_cfg(self, cfg, cfgdir): | |
if srcname != self.SECTION_MAIN: | ||
# only map is a mandatory upcall | ||
map_upcall = cfg.get(section, 'map', raw=True) | ||
all_upcall = list_upcall = reverse_upcall = ctime = None | ||
all_upcall = list_upcall = down_upcall = reverse_upcall = ctime = None | ||
if cfg.has_option(section, 'all'): | ||
all_upcall = cfg.get(section, 'all', raw=True) | ||
if cfg.has_option(section, 'list'): | ||
list_upcall = cfg.get(section, 'list', raw=True) | ||
if cfg.has_option(section, 'down'): | ||
down_upcall = cfg.get(section, 'down', raw=True) | ||
if cfg.has_option(section, 'reverse'): | ||
reverse_upcall = cfg.get(section, 'reverse', | ||
raw=True) | ||
if cfg.has_option(section, 'cache_time'): | ||
ctime = float(cfg.get(section, 'cache_time', | ||
raw=True)) | ||
# add new group source | ||
self.add_source(UpcallGroupSource(srcname, map_upcall, | ||
all_upcall, | ||
list_upcall, | ||
reverse_upcall, | ||
cfgdir, ctime)) | ||
self.add_source(UpcallGroupSource(srcname, | ||
map_upcall, | ||
all_upcall=all_upcall, | ||
list_upcall=list_upcall, | ||
down_upcall=down_upcall, | ||
reverse_upcall=reverse_upcall, | ||
cfgdir=cfgdir, | ||
cache_time=ctime)) | ||
except (NoSectionError, NoOptionError, ValueError) as exc: | ||
raise GroupResolverConfigError(str(exc)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't look right, you're purging the whole cache instead of a time-based expiration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Needs to be fixed. Was seeing a problem where
cache[key][1]
was not defined and was blowing up. Did this temporarily and forgot to go back and fix. Thanks!