Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 1 | import os |
| 2 | import json |
| 3 | ##load the olt config |
| 4 | |
| 5 | class 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 Gaonker | 4ca5cca | 2016-04-11 13:59:35 -0700 | [diff] [blame] | 14 | self.olt_conf['olt'] = True |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 15 | 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 Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 24 | if self.on_olt() and self.olt_conf.has_key('port_map'): |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 25 | port_map = {} |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 26 | 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 Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 35 | ##Build a rx/tx port number to interface map |
Chetan Gaonker | 5209fe8 | 2016-04-19 10:09:53 -0700 | [diff] [blame] | 36 | port_map[1] = self.olt_conf['port_map']['rx'] |
| 37 | port_map[2] = self.olt_conf['port_map']['tx'] |
Chetan Gaonker | 7997bb4 | 2016-03-28 09:46:15 -0700 | [diff] [blame] | 38 | port_map[port_map[1]] = 1 |
| 39 | port_map[port_map[2]] = 2 |
| 40 | return port_map |
| 41 | else: |
| 42 | return None |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 43 | |
| 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 |