+
+ def _filter_by_fixed_attr(self, filters, nodes_id):
+ """
+ Query PLCAPI for nodes ids matching fixed attributes defined by the
+ user
+ """
+ node_tags = self.plapi.get_node_tags(filters)
+ if node_tags is not None:
+
+ if len(nodes_id) == 0:
+ # first attribute being matched
+ for node_tag in node_tags:
+ nodes_id.append(node_tag['node_id'])
+ else:
+ # remove the nodes ids that don't match the new attribute
+ # that is being match
+
+ nodes_id_tmp = []
+ for node_tag in node_tags:
+ if node_tag['node_id'] in nodes_id:
+ nodes_id_tmp.append(node_tag['node_id'])
+
+ if len(nodes_id_tmp):
+ nodes_id = set(nodes_id) & set(nodes_id_tmp)
+ else:
+ # no node from before match the new constraint
+ self.fail_discovery()
+ else:
+ # no nodes match the filter applied
+ self.fail_discovery()
+
+ return nodes_id
+
+ def _filter_by_range_attr(self, attr_name, attr_value, filters, nodes_id):
+ """
+ Query PLCAPI for nodes ids matching attributes defined in a certain
+ range, by the user
+ """
+ node_tags = self.plapi.get_node_tags(filters)
+ if node_tags is not None:
+
+ if len(nodes_id) == 0:
+ # first attribute being matched
+ for node_tag in node_tags:
+
+ # check that matches the min or max restriction
+ if 'min' in attr_name and node_tag['value'] != 'n/a' and \
+ float(node_tag['value']) > attr_value:
+ nodes_id.append(node_tag['node_id'])
+
+ elif 'max' in attr_name and node_tag['value'] != 'n/a' and \
+ float(node_tag['value']) < attr_value:
+ nodes_id.append(node_tag['node_id'])
+ else:
+
+ # remove the nodes ids that don't match the new attribute
+ # that is being match
+ nodes_id_tmp = []
+ for node_tag in node_tags:
+
+ # check that matches the min or max restriction and was a
+ # matching previous filters
+ if 'min' in attr_name and node_tag['value'] != 'n/a' and \
+ float(node_tag['value']) > attr_value and \
+ node_tag['node_id'] in nodes_id:
+ nodes_id_tmp.append(node_tag['node_id'])
+
+ elif 'max' in attr_name and node_tag['value'] != 'n/a' and \
+ float(node_tag['value']) < attr_value and \
+ node_tag['node_id'] in nodes_id:
+ nodes_id_tmp.append(node_tag['node_id'])
+
+ if len(nodes_id_tmp):
+ nodes_id = set(nodes_id) & set(nodes_id_tmp)
+ else:
+ # no node from before match the new constraint
+ self.fail_discovery()
+
+ else: #TODO CHECK
+ # no nodes match the filter applied
+ self.fail_discovery()
+
+ return nodes_id
+
+ def _query_if_alive(self, nodes_id=None, hostname=None):
+ """
+ Query PLCAPI for nodes that register activity recently, using filters
+ related to the state of the node, e.g. last time it was contacted
+ """