1

我正在使用 TitanGraphDB + Cassandra。我按如下方式启动 Titan

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties

我有一个 Rexster shell,可以用来与上面的 Titan+Cassandra 通信。

cd rexster-console-2.3.0
bin/rexster-console.sh

我想从我的 python 程序中对 Titan Graph DB 进行编程。我为此使用了灯泡包。

我使用如下所示的灯泡从 python 创建了 3 种类型的顶点。3种类型的顶点是

- switch
- port
- device

 from bulbs.titan import Graph
 vswitch = self.g.vertices.get_or_create('dpid',dpid_str,{'state':'active','dpid':dpid_str,'type':'switch'})
 vport   = self.g.vertices.get_or_create('port_id',port_id,{'desc':desc,'port_id':port_id,'state':state,'port_state':port_state,'number':number,'type':'port'})

如果我尝试打印变量 vswitch、vport 和 vdevice,我会得到以下结果。

vswitch     <Vertex: http://localhost:8182/graphs/graph/vertices/4>
vport       <Vertex: http://localhost:8182/graphs/graph/vertices/28>

但是,如果我尝试使用如下键检索上述顶点。

vswitch = self.g.vertices.index.lookup(dpid=dpid_str)
vport   = self.g.vertices.index.lookup(port_id=port_id_str)

for s in vswitch
     print s

Here 's' prints the the node `<Vertex: http://localhost:8182/graphs/graph/vertices/4>`
which is expected.How do I extract the key-value pairs from this node?

'dpid'  : dpid_str,
'state' :'active',
'type'  :'switch'
4

1 回答 1

1
>>> switches = self.g.vertices.index.lookup(dpid=dpid_str)
>>> ports    = self.g.vertices.index.lookup(port_id=port_id_str)

for s in switches
     print s.dpid, s.state, s.type
     print s.data()

...或者如果顶点是唯一的(仅返回一个值),则使用 index.get_unique() 而不是 index.lookup() ...

 >>> switch = self.g.vertices.index.get_unique(dpid=dpid_str)
 >>> print switch.dpid, switch.state, switch.type
 >>> print switch.data()

有关更多信息,请参阅灯泡文档和快速入门:

于 2014-07-20T05:37:27.137 回答