blob: ce63ec894f22753b8208061164b3e43e2183fbc6 [file] [log] [blame]
Matteo Scandolo53d61192018-06-01 16:11:14 -07001# 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
15import os, sys
16sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
17
18from helpers import Helpers
19
20import requests
21from multistructlog import create_logger
22from requests.auth import HTTPBasicAuth
Scott Baker47b47302019-01-30 16:55:07 -080023from xossynchronizer.modelaccessor import ONUDevice, model_accessor
24from xossynchronizer.steps.syncstep import SyncStep
Matteo Scandolo53d61192018-06-01 16:11:14 -070025from xosconfig import Config
26
27log = create_logger(Config().get("logging"))
28
29class SyncONUDevice(SyncStep):
30 provides = [ONUDevice]
31
32 observes = ONUDevice
33
Matteo Scandoloe3daaa22018-06-19 14:36:31 -070034 def disable_onu(self, o):
35 volt_service = o.pon_port.olt_device.volt_service
36 voltha = Helpers.get_voltha_info(volt_service)
37
38 log.info("Disabling device %s in voltha" % o.device_id)
39 request = requests.post("%s:%d/api/v1/devices/%s/disable" % (voltha['url'], voltha['port'], o.device_id))
40
41 if request.status_code != 200:
42 raise Exception("Failed to disable ONU device %s: %s" % (o.serial_number, request.text))
43
44 def enable_onu(self, o):
45 volt_service = o.pon_port.olt_device.volt_service
46 voltha = Helpers.get_voltha_info(volt_service)
47
48 log.info("Enabling device %s in voltha" % o.device_id)
49 request = requests.post("%s:%d/api/v1/devices/%s/enable" % (voltha['url'], voltha['port'], o.device_id))
50
51 if request.status_code != 200:
52 raise Exception("Failed to enable ONU device %s: %s" % (o.serial_number, request.text))
53
Matteo Scandolo53d61192018-06-01 16:11:14 -070054 def sync_record(self, o):
55
Andy Baviercd940192019-05-15 12:59:35 -070056 if o.admin_state in ["DISABLED", "ADMIN_DISABLED"]:
Matteo Scandoloe3daaa22018-06-19 14:36:31 -070057 self.disable_onu(o)
58 if o.admin_state == "ENABLED":
59 self.enable_onu(o)