Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 1 | import json |
| 2 | import requests |
| 3 | import os,sys,time |
| 4 | |
| 5 | class OnosCtrl: |
| 6 | |
| 7 | def __init__(self, app, controller = None): |
| 8 | self.app = app |
| 9 | if controller is None: |
| 10 | self.controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost' |
| 11 | else: |
| 12 | self.controller = controller |
| 13 | self.app_url = 'http://%s:8181/onos/v1/applications/%s' %(self.controller, self.app) |
| 14 | self.cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(self.controller) |
| 15 | self.auth = ('karaf', 'karaf') |
| 16 | |
| 17 | def config(self, config): |
| 18 | if config: |
| 19 | json_data = json.dumps(config) |
| 20 | resp = requests.post(self.cfg_url, auth = self.auth, data = json_data) |
| 21 | return resp.ok, resp.status_code |
| 22 | return False, 400 |
| 23 | |
| 24 | def activate(self): |
| 25 | resp = requests.post(self.app_url + '/active', auth = self.auth) |
| 26 | return resp.ok, resp.status_code |
| 27 | |
| 28 | def deactivate(self): |
| 29 | resp = requests.delete(self.app_url + '/active', auth = self.auth) |
| 30 | return resp.ok, resp.status_code |
| 31 | |
| 32 | |