Last active
December 24, 2015 11:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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