def spec_to_node(self, current, spec): n = None message = "" if spec == "ref": n = reference() elif spec == "current": n = current elif self.is_uuid4(spec): n = Node.findById(spec) if n is None: message += "Node with id: " + spec + " does not exist" else: try: nq = dict([ [nv[0].strip(), nv[1].strip() ] for nv in [nv.split("=") for nv in spec[spec.index("(")+1:spec.index(")")].strip().split(",")]]) except: self.abort(400, "Unable to parse node defn") n = Node.find(auth.get_tenant(), **nq) if len(n) == 1: n = n[0] elif len(n) > 1: n = None message += "Could not find a unique node nodes with props: " + str(nq) else: n = None message += "Could not find a node nodes with props: " + str(nq) return (n, message)
def node_id_to_node(self, node_id): n = None msg = "Node with id: " + node_id + " does not exist" if node_id == "ref": n = reference() elif node_id.startswith("Node"): logging.info("trying spec..............") n,msg = self.spec_to_node(None, node_id) else: n = Node.findById(node_id) if n is None: self.abort(404, msg) return n