October 2, 2013 in Systems1 minute
I don’t mind coding in Java (i.e. OpenDaylight) but I wanted something quick and easy, so I’m writing a utility-esque script that sacrifices extensibility for speed. And since Python is something I’ve been meaning to stretch my muscles in, I decided to throw this together.
Keep in mind that this can all be done by ovsdb-client natively via Linux command line, but I wanted to write it in Python to learn it, as well as provide it for a cool (technically) cross-platform language.
Simple idea, send an OVS echo function through JSON-RPC to the address and port of your choice. Assumes you’ve already set up OVS to listen passively on an interface for manager OVSDB requests:
ovs-vsctl set-manager ptcp:6634:10.12.0.30
Suggestions welcome.
1import socket
2import json
3import time
4
5def pingOVS(HOST, PORT):
6
7 #Create socket
8 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9
10 #Establish TCP session via IP address and port specified
11 s.connect((HOST, PORT))
12
13 #Send JSON to socket
14 print "Sending echo request =====>"
15 s.send(json.dumps({'method':'echo','id':'echo','params':[]}))
16
17 #Wait for response and print to console
18 result = json.loads(s.recv(1024))
19 print "<========" + str(result)
20 time.sleep(2)
21
22while True:
23 pingOVS("10.12.0.30", 6634)
24
25#Exit
26s.close()