4 def match_tags(box, all_tags, exact_tags):
5 """ returns True if box has required tags """
7 texact = set(exact_tags)
9 if texact and box.connections == texact:
12 if tall and tall.issubset(box.connections):
17 def find_boxes(box, all_tags = None, exact_tags = None, max_depth = 1):
18 """ Look for the connected boxes with the required tags, doing breath-first
19 search, until max_depth ( max_depth = None will traverse the entire graph ).
21 if not all_tags and not exact_tags:
22 msg = "No matching criteria for resources."
23 raise RuntimeError(msg)
26 # enqueue (depth, box)
37 (depth, a) = queue.pop()
38 if match_tags(a, all_tags, exact_tags):
41 if not max_depth or depth <= max_depth:
43 for b in sorted(a.connections):
44 if b not in traversed:
50 class Resource(object):
51 def __init__(self, box, ec):
52 self._box = weakref.ref(box)
53 self._ec = weakref.ref(ec)
57 self._logger = logging.getLogger("neco.execution.Resource.%s" %
59 self._logger.setLevel(getattr(logging, loglevel.upper()))
69 def find_resources(self, all_tags = None, exact_tags = None,
73 boxes = find_boxes(self.box, all_tags, exact_tags, max_depth)
75 r = self.ec.resource(b.guid)
80 class ResourceResolver(object):