blob: bf5676798ae2c4e843a0c836cee2a5677f8c4e78 [file] [log] [blame]
Murat Parlakisikb224cc92017-02-16 16:27:12 -08001import os
2import sys
3import requests
4import json
5from django.db.models import Q, F
6from services.progran.models import *
7from synchronizers.base.syncstep import SyncStep
8from xos.logger import Logger, logging
9
10# from core.models import Service
11from requests.auth import HTTPBasicAuth
12
13parentdir = os.path.join(os.path.dirname(__file__), "..")
14sys.path.insert(0, parentdir)
15
16logger = Logger(level=logging.INFO)
17
18
19class 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