I am using TitanGraphDB + Cassandra.I am starting Titan as follows
cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
I have a Rexster shell that I can use to communicate to Titan+Cassandra above.
cd rexster-console-2.3.0
bin/rexster-console.sh
I want to program the Titan Graph DB from my python program.I am using bulbs package for that.
I create 3 types of vertices from python using bulbs as given below. The 3 types of vertices are
- 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'})
If I try to print out the variables vswitch,vport and vdevice I get the following results.
vswitch <Vertex: http://localhost:8182/graphs/graph/vertices/4>
vport <Vertex: http://localhost:8182/graphs/graph/vertices/28>
However If I try to retrieve the above vertices using a key as follows.
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'
>>> 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()
...or use index.get_unique() instead of index.lookup() if the vertex is unique (only returns one value)...
>>> switch = self.g.vertices.index.get_unique(dpid=dpid_str)
>>> print switch.dpid, switch.state, switch.type
>>> print switch.data()
See the Bulbs Docs and Quickstart for more: