Matteo Scandolo | 4a8b4d6 | 2018-03-06 17:18:46 -0800 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import json |
| 16 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncStep |
| 17 | from synchronizers.new_base.modelaccessor import VOLTService |
| 18 | |
| 19 | from xosconfig import Config |
| 20 | from multistructlog import create_logger |
| 21 | from time import sleep |
| 22 | import requests |
| 23 | from requests.auth import HTTPBasicAuth |
| 24 | |
| 25 | log = create_logger(Config().get('logging')) |
| 26 | |
| 27 | class SyncOLTService(SyncStep): |
| 28 | provides = [VOLTService] |
| 29 | |
| 30 | observes = VOLTService |
| 31 | |
| 32 | @staticmethod |
| 33 | def format_url(url): |
| 34 | if 'http' in url: |
| 35 | return url |
| 36 | else: |
| 37 | return 'http://%s' % url |
| 38 | |
| 39 | @staticmethod |
| 40 | def get_p_onos_info(o): |
| 41 | return { |
| 42 | 'url': SyncOLTDevice.format_url(o.volt_service.p_onos_url), |
| 43 | 'user': o.volt_service.p_onos_user, |
| 44 | 'pass': o.volt_service.p_onos_pass |
| 45 | } |
| 46 | |
| 47 | def sync_record(self, o): |
| 48 | log.info("sync'ing olt service", object=str(o), **o.tologdict()) |
| 49 | |
| 50 | if o.onu_provisioning == "allow_all": |
| 51 | # tell ONOS to create the ONU device (POST xosapi/v1/volt/onudevices) |
| 52 | pass |
| 53 | if o.onu_provisioning == "pre_provisioned" or o.onu_provisioning == "oss": |
| 54 | # tell ONOS to update the ONU device (POST xosapi/v1/volt/onudevices/<id>) |
| 55 | # NOTE ONOS will need to find the <id> |
| 56 | # NOTE if onu_provisioning == oss then XOS will need to make a call to the oss server to validate the onu |
| 57 | pass |
| 58 | |
| 59 | |
| 60 | def delete_record(self, o): |
| 61 | pass |