From 7f80a99417bdae2030ad020a14c6ca99573239b4 Mon Sep 17 00:00:00 2001
From: subh <subh.singh007@gmail.com>
Date: Tue, 4 Mar 2014 00:59:16 -0800
Subject: [PATCH] added exception handling for the device curl call.

---
 apps/circuitpusher/circuitpusher.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/apps/circuitpusher/circuitpusher.py b/apps/circuitpusher/circuitpusher.py
index 6c1af0e83..344ecd960 100755
--- a/apps/circuitpusher/circuitpusher.py
+++ b/apps/circuitpusher/circuitpusher.py
@@ -94,14 +94,26 @@ if args.action=='add':
     result = os.popen(command).read()
     parsedResult = json.loads(result)
     print command+"\n"
-    sourceSwitch = parsedResult[0]['attachmentPoint'][0]['switchDPID']
+    
+    try:
+    	sourceSwitch = parsedResult[0]['attachmentPoint'][0]['switchDPID']
+    except IndexError:
+	print "ERROR : the specified end point (%s) must already been known to the controller (i.e., already have sent packets on the network, easy way to assure this is to do a ping (to any target) from the two hosts." % (args.srcAddress)
+	sys.exit()
+
     sourcePort = parsedResult[0]['attachmentPoint'][0]['port']
     
     command = "curl -s http://%s/wm/device/?ipv4=%s" % (args.controllerRestIp, args.dstAddress)
     result = os.popen(command).read()
     parsedResult = json.loads(result)
     print command+"\n"
-    destSwitch = parsedResult[0]['attachmentPoint'][0]['switchDPID']
+
+    try:
+        destSwitch = parsedResult[0]['attachmentPoint'][0]['switchDPID']
+    except IndexError:
+        print "ERROR : the specified end point (%s) must already been known to the controller (i.e., already have sent packets on the network, easy way to assure this is to do a ping (to any target) from the two hosts." % (args.dstAddress) 
+        sys.exit()
+ 
     destPort = parsedResult[0]['attachmentPoint'][0]['port']
     
     print "Creating circuit:"
-- 
GitLab