blob: 69aa8d8b620880f26c175ef116efab65727de770 [file] [log] [blame]
Chetan Gaonker7997bb42016-03-28 09:46:15 -07001import os
2import json
3##load the olt config
4
5class OltConfig:
6 def __init__(self, olt_conf_file = ''):
7 if not olt_conf_file:
8 self.olt_conf_file = os.getenv('OLT_CONFIG')
9 else:
10 self.olt_conf_file = olt_conf_file
11 try:
12 self.olt_handle = open(self.olt_conf_file, 'r')
13 self.olt_conf = json.load(self.olt_handle)
Chetan Gaonker4ca5cca2016-04-11 13:59:35 -070014 self.olt_conf['olt'] = True
Chetan Gaonker7997bb42016-03-28 09:46:15 -070015 except:
16 self.olt_handle = None
17 self.olt_conf = {}
18 self.olt_conf['olt'] = False
19
20 def on_olt(self):
21 return self.olt_conf['olt'] is True
22
23 def olt_port_map(self):
24 if self.on_olt() and self.olt_conf.has_key('ports'):
25 port_map = {}
26 ##Build a rx/tx port number to interface map
27 port_map[1] = self.olt_conf['ports']['rx']
28 port_map[2] = self.olt_conf['ports']['tx']
29 port_map[port_map[1]] = 1
30 port_map[port_map[2]] = 2
31 return port_map
32 else:
33 return None
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070034
35 def olt_device_data(self):
36 if self.on_olt():
37 accessDeviceDict = {}
38 accessDeviceDict['uplink'] = str(self.olt_conf['uplink'])
39 accessDeviceDict['vlan'] = str(self.olt_conf['vlan'])
40 return accessDeviceDict
41 return None