def add_pop_edge(pop_url, src_uuid, trg_uuid, timestamp, label, properties=None): """ Add new link between two PoPs :param pop_url: Url of PoP DB :param src_uuid: Source uuid :param trg_uuid: Target uuid :param timestamp: timestamp of the update :param label: Label of the link :param properties: optionally dict containing key values representing PoP link Properties """ if not properties: properties = dict() graph_db = neo4j.Graph(pop_url) src_index = ('pop', 'uuid', src_uuid) trg_index = ('pop', 'uuid', trg_uuid) db_src = neo_resource.get_node(graph_db, src_index) db_trg = neo_resource.get_node(graph_db, trg_index) properties['timestamp'] = timestamp edge = Relationship.cast(db_src, label, db_trg, properties) graph_db.create(edge)
def get_resource(self, graph_db): """ Retrieve the resource from the DB :param graph_db: Graph DB instance :return Node: Resource node """ node = neo_resource.get_node(graph_db, self.index) return node
def get_pop(pop_url, uuid): """ Retrieve PoP given the uuid :param pop_url: Url of PoP DB :param uuid: PoP uuid :return dict: Dictionary containing PoP properties """ graph_db = neo4j.Graph(pop_url) index = ('pop', 'uuid', uuid) pop = neo_resource.get_node(graph_db, index) if pop: results = dict(pop.properties) return results raise HTTPError(404, 'Resource not found: /pop/' + uuid)
def _get_graph_url(pop_url, pop_id): """ Retrieve EPA db url and PoP name for a given pop_id :param pop_url: Url of the PoP DB :param pop_id: PoP ID :return tuple: (EPA url, PoP name) """ try: graph_db = neo4j.Graph(pop_url) index = ('pop', 'uuid', pop_id) pop = neo_resource.get_node(graph_db, index) if pop: properties = dict(pop.properties) if 'occi.epa.pop.graph_db_url' in properties and 'occi.epa.pop.name' in properties: return properties['occi.epa.pop.graph_db_url'], properties['occi.epa.pop.name'] except Exception: raise HTTPError(404, 'Error connecting to graph_url: ' + str(pop_url)) raise HTTPError(404, 'Resource not found: Epa-Pop-Id: ' + str(pop_id))
def _get_graph_url(pop_url, pop_id): """ Retrieve EPA db url and PoP name for a given pop_id :param pop_url: Url of the PoP DB :param pop_id: PoP ID :return tuple: (EPA url, PoP name) """ try: graph_db = neo4j.Graph(pop_url) index = ('pop', 'uuid', pop_id) pop = neo_resource.get_node(graph_db, index) if pop: properties = dict(pop.properties) if 'occi.epa.pop.graph_db_url' in properties and 'occi.epa.pop.name' in properties: return properties['occi.epa.pop.graph_db_url'], properties[ 'occi.epa.pop.name'] except Exception: raise HTTPError(404, 'Error connecting to graph_url: ' + str(pop_url)) raise HTTPError(404, 'Resource not found: Epa-Pop-Id: ' + str(pop_id))
def _get_odl_info(pop_url, pop_id): """ Retrieve OpenDaylight Url, username and password from the PoP DB :param pop_url: Url of Neo4j PoP DB :param pop_id: PoP ID :return tuple: (ODL url, ODL username, ODL password """ try: graph_db = neo4j.Graph(pop_url) index = ('pop', 'uuid', pop_id) pop = neo_resource.get_node(graph_db, index) if pop: properties = dict(pop.properties) if 'occi.epa.pop.odl_url' in properties and 'occi.epa.pop.odl_name' in properties \ and 'occi.epa.pop.odl_password' in properties: return properties['occi.epa.pop.odl_url'], properties['occi.epa.pop.odl_name'],\ properties['occi.epa.pop.odl_password'] except Exception: raise HTTPError(404, 'Error connecting to graph_url: ' + str(pop_url)) raise HTTPError(404, 'Resource not found: Epa-Pop-Id: ' + str(pop_id))