Esempio n. 1
0
 def create(source_id,
            destination_id,
            name,
            panel_type,
            num_of_ports,
            connector,
            height=-1):
     source_rack = Rack.find_one(by_id=source_id)
     destination_rack = Rack.find_one(by_id=destination_id)
     if not source_rack:
         log("Source rack not found")
         return False
     if not destination_rack:
         log("Destination rack not found")
         return False
     json_props = dict(id=uuid.uuid4(),
                       name=name,
                       panel_type=panel_type,
                       num_of_ports=num_of_ports,
                       connector=connector,
                       status="active",
                       height=height)
     source_rack_props = "{ id: \"" + str(source_id) + "\" }"
     destination_rack_props = "{ id: \"" + str(destination_id) + "\" }"
     cypher_query = """
     MATCH (a:Rack {}), (b:Rack {}) CREATE (a)-[c:{} {}]->(b) RETURN c
     """.format(source_rack_props, destination_rack_props,
                panel_type.upper(), json_to_properties(json_props))
     return db.run(cypher_query).evaluate()
Esempio n. 2
0
 def find_all_between_racks(rack1_id, rack2_id):
     if not Rack.find_one(by_id=rack1_id):
         log("Rack 1 not found")
         return False
     if not Rack.find_one(by_id=rack2_id):
         log("Rack 2 not found")
         return False
     cypher_query = """
     MATCH (a)-[r]->(b) WHERE a.id=\"{}\" AND b.id=\"{}\" return r
     """.format(rack1_id, rack2_id)
     r1 = db.run(cypher_query).data()
     cypher_query = """
     MATCH (a)-[r]->(b) WHERE a.id=\"{}\" AND b.id=\"{}\" return r
     """.format(rack2_id, rack1_id)
     r2 = db.run(cypher_query).data()
     if r1 and r2:
         return [i["r"] for i in r1] + [i["r"] for i in r2]
     if r1:
         return [i["r"] for i in r1]
     return [i["r"] for i in r2]