blob: 958e0bd96e2379a07e95a7cbb3d3b262f7642512 [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):
Chetan Gaonker5209fe82016-04-19 10:09:53 -070024 if self.on_olt() and self.olt_conf.has_key('port_map'):
Chetan Gaonker7997bb42016-03-28 09:46:15 -070025 port_map = {}
Chetan Gaonker5209fe82016-04-19 10:09:53 -070026 port_map['ports'] = self.olt_conf['port_map']['ports']
27 port_map['start_vlan'] = 0
28 if self.olt_conf['port_map'].has_key('host'):
29 port_map['host'] = self.olt_conf['port_map']['host']
30 else:
31 port_map['host'] = 'ovsbr0'
32 if self.olt_conf['port_map'].has_key('start_vlan'):
33 port_map['start_vlan'] = int(self.olt_conf['port_map']['start_vlan'])
34
Chetan Gaonker7997bb42016-03-28 09:46:15 -070035 ##Build a rx/tx port number to interface map
Chetan Gaonker5209fe82016-04-19 10:09:53 -070036 port_map[1] = self.olt_conf['port_map']['rx']
37 port_map[2] = self.olt_conf['port_map']['tx']
Chetan Gaonker7997bb42016-03-28 09:46:15 -070038 port_map[port_map[1]] = 1
39 port_map[port_map[2]] = 2
40 return port_map
41 else:
42 return None
Chetan Gaonkera2b87df2016-03-31 15:41:31 -070043
44 def olt_device_data(self):
45 if self.on_olt():
46 accessDeviceDict = {}
47 accessDeviceDict['uplink'] = str(self.olt_conf['uplink'])
48 accessDeviceDict['vlan'] = str(self.olt_conf['vlan'])
49 return accessDeviceDict
50 return None