blob: 68c144d602ecc99f762513bf0ed5fed6e47bf69d [file] [log] [blame]
Matteo Scandoloc3ca49b2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Murat Parlakisikb224cc92017-02-16 16:27:12 -080017import os
18import sys
19import requests
20import json
21from django.db.models import Q, F
22from services.progran.models import *
23from synchronizers.base.syncstep import SyncStep
24from xos.logger import Logger, logging
25
26# from core.models import Service
27from requests.auth import HTTPBasicAuth
28
29parentdir = os.path.join(os.path.dirname(__file__), "..")
30sys.path.insert(0, parentdir)
31
32logger = Logger(level=logging.INFO)
33
34
35class SyncVProfileApp(SyncStep):
36 provides = [VProgranProfile]
37
38 observes = VProgranProfile
39
40 requested_interval = 0
41
42 def __init__(self, *args, **kwargs):
43 super(SyncVProfileApp, self).__init__(*args, **kwargs)
44
45 def get_onos_progran_addr(self):
46
47 return "http://%s:%s/onos/" % ("10.6.0.1", "8183")
48
49 def get_onos_progran_auth(self):
50
51 return HTTPBasicAuth("onos", "rocks")
52
53 def sync_record(self, app):
54
55 logger.info("Sync'ing Edited vProgran Profile ")
56
57 onos_addr = self.get_onos_progran_addr()
58
59 data = {}
60 data["profile"] = app.profile
61 data["dlrate"] = app.dlrate
62 data["ulrate"] = app.ulrate
63
64
65 url = onos_addr + "progran/mwc/profile"
66
67 print "POST %s for app %s" % (url, "Progran Imsi")
68
69 auth = self.get_onos_progran_auth()
70 r = requests.post(url, data=json.dumps(data), auth=auth)
71 if (r.status_code != 200):
72 print r
73 raise Exception("Received error from progran app update (%d)" % r.status_code)
74
75 def delete_record(self, app):
76 logger.info("Deletion is not supported yet")
77