Matteo Scandolo | 53d6119 | 2018-06-01 16:11:14 -0700 | [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 os, sys |
| 16 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 17 | |
| 18 | from helpers import Helpers |
| 19 | |
| 20 | import requests |
| 21 | from multistructlog import create_logger |
| 22 | from requests.auth import HTTPBasicAuth |
| 23 | from synchronizers.new_base.modelaccessor import ONUDevice, model_accessor |
| 24 | from synchronizers.new_base.syncstep import SyncStep |
| 25 | from xosconfig import Config |
| 26 | |
| 27 | log = create_logger(Config().get("logging")) |
| 28 | |
| 29 | class SyncONUDevice(SyncStep): |
| 30 | provides = [ONUDevice] |
| 31 | |
| 32 | observes = ONUDevice |
| 33 | |
| 34 | def sync_record(self, o): |
| 35 | |
| 36 | if o.admin_state == "DISABLED": |
| 37 | volt_service = o.pon_port.olt_device.volt_service |
| 38 | voltha = Helpers.get_voltha_info(volt_service) |
| 39 | |
| 40 | log.info("Disabling device %s in voltha" % o.device_id) |
| 41 | request = requests.post("%s:%d/api/v1/devices/%s/disable" % (voltha['url'], voltha['port'], o.device_id)) |
| 42 | |
| 43 | if request.status_code != 200: |
| 44 | raise Exception("Failed to disable ONU device: %s" % request.text) |