- print "%(hostname)-39s | %(checked)11.11s | %(state)10.10s | %(ssh)5.5s | %(pcu)6.6s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
-
-def verify(constraints, data):
- """
- constraints is a list of key, value pairs.
- # [ {... : ...}==AND , ... , ... , ] == OR
- """
- con_or_true = False
- for con in constraints:
- #print "con: %s" % con
- if len(con.keys()) == 0:
- con_and_true = False
- else:
- con_and_true = True
-
- for key in con.keys():
- #print "looking at key: %s" % key
- if key in data:
- value_re = re.compile(con[key])
- con_and_true = con_and_true & (value_re.search(data[key]) is not None)
- elif key not in data:
- print "missing key %s" % key
- con_and_true = False
-
- con_or_true = con_or_true | con_and_true
-
- return con_or_true
-
-def query_to_dict(query):
-
- ad = []
-
- or_queries = query.split('||')
- for or_query in or_queries:
- and_queries = or_query.split('&&')
-
- d = {}
-
- for and_query in and_queries:
- (key, value) = and_query.split('=')
- d[key] = value
-
- ad.append(d)
-
- return ad
-
-def _pcu_in(fbdata):
- if 'plcnode' in fbdata:
- if 'pcu_ids' in fbdata['plcnode']:
- if len(fbdata['plcnode']['pcu_ids']) > 0:
- return True
- return False
-
-def pcu_select(str_query):
- pcunames = []
- if str_query is None: return pcunames
-
- #print str_query
- dict_query = query_to_dict(str_query)
- #print dict_query
-
- for node in fb['nodes'].keys():
-
- fb_nodeinfo = fb['nodes'][node]['values']
- if _pcu_in(fb_nodeinfo):
- pcuinfo = fbpcu['nodes']['id_%s' % fb_nodeinfo['plcnode']['pcu_ids'][0]]['values']
- if verify(dict_query, pcuinfo):
- pcunames.append(node)
-
- return pcunames
-
-def node_select(str_query):
- hostnames = []
- if str_query is None: return hostnames