Murat Parlakisik | b224cc9 | 2017-02-16 16:27:12 -0800 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import requests |
| 4 | import json |
| 5 | from django.db.models import Q, F |
| 6 | from services.progran.models import * |
| 7 | from synchronizers.base.syncstep import SyncStep |
| 8 | from xos.logger import Logger, logging |
| 9 | |
| 10 | # from core.models import Service |
| 11 | from requests.auth import HTTPBasicAuth |
| 12 | |
| 13 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 14 | sys.path.insert(0, parentdir) |
| 15 | |
| 16 | logger = Logger(level=logging.INFO) |
| 17 | |
| 18 | |
| 19 | class SyncVImsiApp(SyncStep): |
| 20 | provides = [VProgranImsi] |
| 21 | |
| 22 | observes = VProgranImsi |
| 23 | |
| 24 | requested_interval = 0 |
| 25 | |
| 26 | def __init__(self, *args, **kwargs): |
| 27 | super(SyncVImsiApp, self).__init__(*args, **kwargs) |
| 28 | |
| 29 | def get_onos_progran_addr(self): |
| 30 | |
| 31 | return "http://%s:%s/onos/" % ("10.6.0.1", "8183") |
| 32 | |
| 33 | def get_onos_progran_auth(self): |
| 34 | |
| 35 | return HTTPBasicAuth("onos", "rocks") |
| 36 | |
| 37 | def sync_record(self, app): |
| 38 | |
| 39 | logger.info("Sync'ing Edited vProgran Imsi") |
| 40 | |
| 41 | onos_addr = self.get_onos_progran_addr() |
| 42 | |
| 43 | data = {} |
| 44 | data["imsi"] = app.imsi |
| 45 | data["profile"] = app.profile |
| 46 | |
| 47 | |
| 48 | url = onos_addr + "progran/mwc/connect" |
| 49 | |
| 50 | print "POST %s for app %s" % (url, "Progran Imsi") |
| 51 | |
| 52 | auth = self.get_onos_progran_auth() |
| 53 | r = requests.post(url, data=json.dumps(data), auth=auth) |
| 54 | if (r.status_code != 200): |
| 55 | print r |
| 56 | raise Exception("Received error from progran app update (%d)" % r.status_code) |
| 57 | |
| 58 | def delete_record(self, app): |
| 59 | logger.info("Deletion is not supported yet") |
| 60 | |