Ayaka Koshibe
Committed by Ray Milkey

REST authentication in opticalUtil

Environment variables are checked before falling back on and exporting
tentatively chosen defaults.

Change-Id: If378127a2cc757b55024aeb89cb1964f8641d5a6
...@@ -70,9 +70,6 @@ from mininet.cli import CLI ...@@ -70,9 +70,6 @@ from mininet.cli import CLI
70 SLEEP_TIME = 2 70 SLEEP_TIME = 2
71 TIMEOUT = 60 71 TIMEOUT = 60
72 72
73 -REST_USER = 'onos'
74 -REST_PW = 'rocks'
75 -
76 class OpticalSwitch(Switch): 73 class OpticalSwitch(Switch):
77 """ 74 """
78 For now, same as Switch class. 75 For now, same as Switch class.
...@@ -152,6 +149,17 @@ class LINCSwitch(OpticalSwitch): ...@@ -152,6 +149,17 @@ class LINCSwitch(OpticalSwitch):
152 error('Please set ONOS_ROOT environment variable!\n') 149 error('Please set ONOS_ROOT environment variable!\n')
153 else: 150 else:
154 os.environ[ 'ONOS_ROOT' ] = onosDir 151 os.environ[ 'ONOS_ROOT' ] = onosDir
152 + ### REST USER/PASS ###
153 + try:
154 + restUser = os.environ[ 'ONOS_WEB_USER' ]
155 + restPass = os.environ[ 'ONOS_WEB_PASS' ]
156 + except:
157 + error('***WARNING: $ONOS_WEB_USER and $ONOS_WEB_PASS aren\'t set!\n')
158 + error('***WARNING: Setting (probably) sane WEB user/pass values\n')
159 + restUser = 'onos'
160 + restPass = 'rocks'
161 + os.environ[ 'ONOS_WEB_USER' ] = restUser
162 + os.environ[ 'ONOS_WEB_PASS' ] = restPass
155 ### LINC-directory 163 ### LINC-directory
156 lincDir = findDir.__func__('linc-oe', user) 164 lincDir = findDir.__func__('linc-oe', user)
157 if not lincDir: 165 if not lincDir:
...@@ -433,7 +441,7 @@ class LINCSwitch(OpticalSwitch): ...@@ -433,7 +441,7 @@ class LINCSwitch(OpticalSwitch):
433 time = 0 441 time = 0
434 # Set up password authentication 442 # Set up password authentication
435 pw_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() 443 pw_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
436 - pw_mgr.add_password(None, url, REST_USER, REST_PW) 444 + pw_mgr.add_password(None, url, LINCSwitch.restUser, LINCSwitch.restPass)
437 handler = urllib2.HTTPBasicAuthHandler(pw_mgr) 445 handler = urllib2.HTTPBasicAuthHandler(pw_mgr)
438 opener = urllib2.build_opener(handler) 446 opener = urllib2.build_opener(handler)
439 opener.open(url) 447 opener.open(url)
......