support networkx 2.1
add_node() and add_edge() parameter variable names changed. Depends-On: Id583a698bffdd7d7f77ba0da40f7b11e4735940f Change-Id: Id5dbd165a1e0220e4e24207e8d237f94415fc490
This commit is contained in:
parent
12b9fa0b49
commit
83a370f70b
@ -23,9 +23,19 @@ class RootRestController(rest.RestController):
|
||||
|
||||
@staticmethod
|
||||
def as_tree(graph, root=OPENSTACK_CLUSTER, reverse=False):
|
||||
if nx.__version__ >= '2.0':
|
||||
linked_graph = json_graph.node_link_graph(
|
||||
graph, attrs={'name': 'graph_index'})
|
||||
else:
|
||||
linked_graph = json_graph.node_link_graph(graph)
|
||||
if 0 == nx.number_of_nodes(linked_graph):
|
||||
return {}
|
||||
if reverse:
|
||||
linked_graph = linked_graph.reverse()
|
||||
if nx.__version__ >= '2.0':
|
||||
return json_graph.tree_data(
|
||||
linked_graph,
|
||||
root=root,
|
||||
attrs={'id': 'graph_index', 'children': 'children'})
|
||||
else:
|
||||
return json_graph.tree_data(linked_graph, root=root)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
|
||||
import json
|
||||
import networkx as nx
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_utils.strutils import bool_from_string
|
||||
@ -81,6 +82,14 @@ class TopologyController(RootRestController):
|
||||
if graph_type == 'graph':
|
||||
return graph
|
||||
if graph_type == 'tree':
|
||||
if nx.__version__ >= '2.0':
|
||||
node_id = ''
|
||||
for node in graph['nodes']:
|
||||
if (root and node[VProps.VITRAGE_ID] == root) or \
|
||||
(not root and node[VProps.ID] == CLUSTER_ID):
|
||||
node_id = node[VProps.GRAPH_INDEX]
|
||||
break
|
||||
else:
|
||||
node_id = CLUSTER_ID
|
||||
if root:
|
||||
for node in graph['nodes']:
|
||||
|
@ -84,9 +84,9 @@ class NXGraph(Graph):
|
||||
def _add_vertex(self, v):
|
||||
properties_copy = copy.copy(v.properties)
|
||||
if properties_copy:
|
||||
self._g.add_node(n=v.vertex_id, **properties_copy)
|
||||
self._g.add_node(v.vertex_id, **properties_copy)
|
||||
else:
|
||||
self._g.add_node(n=v.vertex_id)
|
||||
self._g.add_node(v.vertex_id)
|
||||
|
||||
@Notifier.update_notify
|
||||
def add_edge(self, e):
|
||||
@ -100,11 +100,10 @@ class NXGraph(Graph):
|
||||
def _add_edge(self, e):
|
||||
properties_copy = copy.copy(e.properties)
|
||||
if properties_copy:
|
||||
self._g.add_edge(u=e.source_id, v=e.target_id,
|
||||
key=e.label, **properties_copy)
|
||||
self._g.add_edge(e.source_id, e.target_id,
|
||||
e.label, **properties_copy)
|
||||
else:
|
||||
self._g.add_edge(u=e.source_id, v=e.target_id,
|
||||
key=e.label)
|
||||
self._g.add_edge(e.source_id, e.target_id, e.label)
|
||||
|
||||
def get_vertex(self, v_id):
|
||||
"""Fetch a vertex from the graph
|
||||
|
Loading…
Reference in New Issue
Block a user