blob: 611496ba6cc578ce24e3d1a5575c2cdd334ef521 [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
23from synchronizers.new_base.modelaccessor import ONUDevice, model_accessor
24from synchronizers.new_base.syncstep import SyncStep
25from 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
56 if o.admin_state == "DISABLED":
Matteo Scandoloe3daaa22018-06-19 14:36:31 -070057 self.disable_onu(o)
58 if o.admin_state == "ENABLED":
59 self.enable_onu(o)