2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-26 03:19:48 +00:00

Implement reverse noderange

This is the library feature.  A remote API call will be addded
so that the likes of collate can use it.
This commit is contained in:
Jarrod Johnson 2017-08-10 16:45:38 -04:00
parent a571faa215
commit 1e54abd29b
2 changed files with 36 additions and 3 deletions

View File

@ -813,12 +813,16 @@ class ConfigManager(object):
def is_nodegroup(self, nodegroup):
return nodegroup in self._cfgstore['nodegroups']
def get_groups(self):
return self._cfgstore['nodegroups'].iterkeys()
def get_groups(self, sizesort=False):
if sizesort:
return reversed(
sorted(self._cfgstore['nodegroups'], key=lambda x: len(
self._cfgstore['nodegroups'][x]['nodes'])))
return iter(self._cfgstore['nodegroups'])
def list_nodes(self):
try:
return self._cfgstore['nodes'].iterkeys()
return iter(self._cfgstore['nodes'])
except KeyError:
return []

View File

@ -48,6 +48,35 @@ def humanify_nodename(nodename):
for text in re.split(numregex, nodename)]
class ReverseNodeRange(object):
"""Abbreviate a set of nodes to a shorter noderange representation
:param nodes: List of nodes as a list, tuple, etc.
:param config: Config manager
"""
def __init__(self, nodes, config):
self.cfm = config
self.nodes = set(nodes)
@property
def noderange(self):
subsetgroups = []
for group in self.cfm.get_groups(sizesort=True):
nl = set(
self.cfm.get_nodegroup_attributes(group).get('nodes', []))
if len(nl) > len(self.nodes) or not nl:
continue
if not nl - self.nodes:
subsetgroups.append(group)
self.nodes -= nl
if not self.nodes:
break
return ','.join(sorted(subsetgroups) + sorted(self.nodes))
# TODO: pagination operators <pp.nums and >pp.nums for begin and end respective
class NodeRange(object):
"""Iterate over a noderange