blob: 0570d94a4a466275f17eae79e0093267ee2a8008 [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 SyncVProfileApp(SyncStep):
20 provides = [VProgranProfile]
21
22 observes = VProgranProfile
23
24 requested_interval = 0
25
26 def __init__(self, *args, **kwargs):
27 super(SyncVProfileApp, 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 Profile ")
40
41 onos_addr = self.get_onos_progran_addr()
42
43 data = {}
44 data["profile"] = app.profile
45 data["dlrate"] = app.dlrate
46 data["ulrate"] = app.ulrate
47
48
49 url = onos_addr + "progran/mwc/profile"
50
51 print "POST %s for app %s" % (url, "Progran Imsi")
52
53 auth = self.get_onos_progran_auth()
54 r = requests.post(url, data=json.dumps(data), auth=auth)
55 if (r.status_code != 200):
56 print r
57 raise Exception("Received error from progran app update (%d)" % r.status_code)
58
59 def delete_record(self, app):
60 logger.info("Deletion is not supported yet")
61