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 创建一个顶点。

 fe1 = self.g.vertices.get_or_create('switch_dpid',switch_dpid,
          {'actionOutputPort':actionOutputPort,
           'switch_state':'FE_SWITCH_UPDATED',
           'matchInPort': MatchInPort,
           'type': 'flow_entry',
           'user_state':'FE_USER_ADD',
'actions': ['type':'ACTION_OUTPUT', 'action':[port=actionOutputPort maxLen=0];]})

这给了我一个错误

  'actions': ['type':'ACTION_OUTPUT', 'action':[port=actionOutputPort maxLen=0];]}) 
  SyntaxError: invalid syntax

我期望 Rexster 控制台的输出如下。

switch_dpid=00:00:00:00:00:00:02:05,
actionOutputPort=1,
switch_state=FE_SWITCH_UPDATED,
matchInPort=2,
flow_entry_id=0x4ee30a9400000012,
type=flow_entry,
actions=[[type=ACTION_OUTPUT action=[port=1 maxLen=0]];],
user_state=FE_USER_ADD

我如何编程actions使其如上。

4

1 回答 1

2

您正在将 Groovy 语法与 Python 混为一谈。

actions是字典,action是字典,所以在 Python 中它应该是:

'actions': {'type': 'ACTION_OUTPUT', 
            'action': {port: actionOutputPort,
                       maxLen: 0}}

dict请注意,使用以下函数创建 Python 字典通常更方便(引号更少) :

'actions' = dict(type = 'ACTION_OUTPUT',
                 action = dict(port = actionOutputPort, 
                               maxLen = 0))
于 2014-07-02T22:04:25.123 回答