Matteo Scandolo | c3ca49b | 2017-08-08 13:05:26 -0700 | [diff] [blame^] | 1 | |
| 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 Parlakisik | b224cc9 | 2017-02-16 16:27:12 -0800 | [diff] [blame] | 17 | import os |
| 18 | import sys |
| 19 | import requests |
| 20 | import json |
| 21 | from django.db.models import Q, F |
| 22 | from services.progran.models import * |
| 23 | from synchronizers.base.syncstep import SyncStep |
| 24 | from xos.logger import Logger, logging |
| 25 | |
| 26 | # from core.models import Service |
| 27 | from requests.auth import HTTPBasicAuth |
| 28 | |
| 29 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 30 | sys.path.insert(0, parentdir) |
| 31 | |
| 32 | logger = Logger(level=logging.INFO) |
| 33 | |
| 34 | |
| 35 | class 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 | |