blob: 014970289bb5c356cbf24187fe8dc4ff07fe91f1 [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 SyncVImsiApp(SyncStep):
36 provides = [VProgranImsi]
37
38 observes = VProgranImsi
39
40 requested_interval = 0
41
42 def __init__(self, *args, **kwargs):
43 super(SyncVImsiApp, 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 Imsi")
56
57 onos_addr = self.get_onos_progran_addr()
58
59 data = {}
60 data["imsi"] = app.imsi
61 data["profile"] = app.profile
62
63
64 url = onos_addr + "progran/mwc/connect"
65
66 print "POST %s for app %s" % (url, "Progran Imsi")
67
68 auth = self.get_onos_progran_auth()
69 r = requests.post(url, data=json.dumps(data), auth=auth)
70 if (r.status_code != 200):
71 print r
72 raise Exception("Received error from progran app update (%d)" % r.status_code)
73
74 def delete_record(self, app):
75 logger.info("Deletion is not supported yet")
76