Committed by
Gerrit Code Review
opticalUtil:
Authenticate against REST API. Caveat: assume sane default user/pw. Change-Id: Id4197ce648dbc8de9b56f180beefcbf9b7d6c529
Showing
1 changed file
with
10 additions
and
0 deletions
| ... | @@ -70,6 +70,9 @@ from mininet.cli import CLI | ... | @@ -70,6 +70,9 @@ 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 | + | ||
| 73 | class OpticalSwitch(Switch): | 76 | class OpticalSwitch(Switch): |
| 74 | """ | 77 | """ |
| 75 | For now, same as Switch class. | 78 | For now, same as Switch class. |
| ... | @@ -428,6 +431,13 @@ class LINCSwitch(OpticalSwitch): | ... | @@ -428,6 +431,13 @@ class LINCSwitch(OpticalSwitch): |
| 428 | info('*** Waiting for all devices to be available in ONOS...\n') | 431 | info('*** Waiting for all devices to be available in ONOS...\n') |
| 429 | url = 'http://%s:8181/onos/v1/devices' % LINCSwitch.controllers[0].ip | 432 | url = 'http://%s:8181/onos/v1/devices' % LINCSwitch.controllers[0].ip |
| 430 | time = 0 | 433 | time = 0 |
| 434 | + # Set up password authentication | ||
| 435 | + pw_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | ||
| 436 | + pw_mgr.add_password(None, url, REST_USER, REST_PW) | ||
| 437 | + handler = urllib2.HTTPBasicAuthHandler(pw_mgr) | ||
| 438 | + opener = urllib2.build_opener(handler) | ||
| 439 | + opener.open(url) | ||
| 440 | + urllib2.install_opener(opener) | ||
| 431 | while True: | 441 | while True: |
| 432 | response = json.load(urllib2.urlopen(url)) | 442 | response = json.load(urllib2.urlopen(url)) |
| 433 | devs = response.get('devices') | 443 | devs = response.get('devices') | ... | ... |
-
Please register or login to post a comment