blob: 579c13ebead9e7c348d10d7d8dda3e67507c44b8 [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
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)