Skip to content

Instantly share code, notes, and snippets.

@Mierdin
Last active December 24, 2015 11:59
Show Gist options
  • Save Mierdin/6794738 to your computer and use it in GitHub Desktop.
Save Mierdin/6794738 to your computer and use it in GitHub Desktop.
Just a small snippet of python that forms a connection, sends some JSON, and outputs the response. Main use case is fast testing of OVSDB using a simple script.
import socket
import json
import time
def pingOVS(HOST, PORT):
#Create socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Establish TCP session via IP address and port specified
s.connect((HOST, PORT))
#Send JSON to socket
print "Sending echo request =====>"
s.send(json.dumps({'method':'echo','id':'echo','params':[]}))
#Wait for response and print to console
result = json.loads(s.recv(1024))
print "<========" + str(result)
time.sleep(2)
while True:
pingOVS("10.12.0.30", 6634)
#Exit
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment