enable auth in rest calls, and fix one error message 04/37304/4
authorJamo Luhrsen <jluhrsen@redhat.com>
Fri, 8 Apr 2016 04:29:14 +0000 (21:29 -0700)
committerLuis Gomez <ecelgp@gmail.com>
Sat, 9 Apr 2016 03:30:54 +0000 (03:30 +0000)
Change-Id: Iddd0dfb7ec44a89c00f3f481a5576459b113077e
Signed-off-by: Jamo Luhrsen <jluhrsen@redhat.com>
tools/clustering/cluster-monitor/monitor.py

index c9fb3ee5d7dd59198f4ff27637d5fd0c826c76e9..d708ea7252f054b288dfd357c0d4f3fbacb0738e 100644 (file)
@@ -37,7 +37,7 @@ import pycurl
 import string
 
 
-def rest_get(restURL):
+def rest_get(restURL, username, password):
     rest_buffer = BytesIO()
     c = pycurl.Curl()
     c.setopt(c.TIMEOUT, 2)
@@ -46,6 +46,7 @@ def rest_get(restURL):
     c.setopt(c.URL, str(restURL))
     c.setopt(c.HTTPGET, 0)
     c.setopt(c.WRITEFUNCTION, rest_buffer.write)
+    c.setopt(pycurl.USERPWD, "%s:%s" % (str(username), str(password)))
     c.perform()
     c.close()
     return json.loads(rest_buffer.getvalue())
@@ -61,7 +62,7 @@ def getClusterRolesWithCurl(shardName, *args):
         url += 'Category=Shards,name=' + names[i]
         url += '-shard-' + shardName + '-config,type=DistributedConfigDatastore'
         try:
-            resp = rest_get(url)
+            resp = rest_get(url, username, password)
             if resp['status'] != 200:
                 controller_state[controller["ip"]] = 'HTTP ' + str(resp['status'])
             if 'value' in resp:
@@ -103,6 +104,8 @@ except:
 try:
     controllers = data["cluster"]["controllers"]
     shards_to_exclude = data["cluster"]["shards_to_exclude"]
+    username = data["cluster"]["user"]
+    password = data["cluster"]["pass"]
 except:
     print str(sys.exc_info())
     print 'Error reading the file cluster.json'
@@ -114,10 +117,11 @@ Shards = set()
 for controller in controllers:
     url = "http://" + controller["ip"] + ":" + controller["port"] + "/jolokia/read/org.opendaylight.controller:"
     url += "Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore"
+    rest_get(url, username, password)
     try:
-        data = rest_get(url)
+        data = rest_get(url, username, password)
     except:
-        print 'Unable to retrieve shard names from ' + controller
+        print 'Unable to retrieve shard names from ' + str(controller)
         print 'Are all controllers up?'
         print str(sys.exc_info()[1])
         exit(1)