blob: e9e53efa804776f7e85346df475a12b06b698fbd [file] [log] [blame]
Chetan Gaonkercb122cc2016-05-10 10:58:34 -07001#!/usr/bin/env python
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002#
3# Copyright 2016-present Ciena Corporation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Chetan Gaonker7997bb42016-03-28 09:46:15 -070017import os
18import json
19##load the olt config
20
21class OltConfig:
22 def __init__(self, olt_conf_file = ''):
23 if not olt_conf_file:
24 self.olt_conf_file = os.getenv('OLT_CONFIG')
25 else:
26 self.olt_conf_file = olt_conf_file
27 try:
28 self.olt_handle = open(self.olt_conf_file, 'r')
29 self.olt_conf = json.load(self.olt_handle)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070030 self.olt_conf['olt'] = True
Chetan Gaonker7997bb42016-03-28 09:46:15 -070031 except:
32 self.olt_handle = None
33 self.olt_conf = {}
34 self.olt_conf['olt'] = False
35
36 def on_olt(self):
37 return self.olt_conf['olt'] is True
38
39 def olt_port_map(self):
Chetan Gaonker5209fe82016-04-19 10:09:53 -070040 if self.on_olt() and self.olt_conf.has_key('port_map'):
Chetan Gaonker7997bb42016-03-28 09:46:15 -070041 port_map = {}
Chetan Gaonker5209fe82016-04-19 10:09:53 -070042 port_map['ports'] = self.olt_conf['port_map']['ports']
43 port_map['start_vlan'] = 0
44 if self.olt_conf['port_map'].has_key('host'):
45 port_map['host'] = self.olt_conf['port_map']['host']
46 else:
47 port_map['host'] = 'ovsbr0'
48 if self.olt_conf['port_map'].has_key('start_vlan'):
49 port_map['start_vlan'] = int(self.olt_conf['port_map']['start_vlan'])
50
Chetan Gaonker7997bb42016-03-28 09:46:15 -070051 ##Build a rx/tx port number to interface map
Chetan Gaonker5209fe82016-04-19 10:09:53 -070052 port_map[1] = self.olt_conf['port_map']['rx']
53 port_map[2] = self.olt_conf['port_map']['tx']
Chetan Gaonker7997bb42016-03-28 09:46:15 -070054 port_map[port_map[1]] = 1
55 port_map[port_map[2]] = 2
56 return port_map
57 else:
58 return None
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070059
60 def olt_device_data(self):
61 if self.on_olt():
62 accessDeviceDict = {}
63 accessDeviceDict['uplink'] = str(self.olt_conf['uplink'])
64 accessDeviceDict['vlan'] = str(self.olt_conf['vlan'])
65 return accessDeviceDict
66 return None