integrate switch ip and mac list into one config file.

Change-Id: I54469719d80f6c9b4f2a882c28e4f1283387ab95
This commit is contained in:
Lei Lei 2014-10-24 15:39:44 -07:00
parent c483fcdf93
commit 8de7a30142
5 changed files with 62 additions and 55 deletions

View File

@ -101,11 +101,12 @@ class HDManager(object):
:return a tuple (vendor, switch_state, error)
"""
switch_lists = util.load_configs(setting.SWITCH_LIST_DIR)
switch_lists = util.load_configs(setting.MACHINE_LIST_DIR)
switch_list = []
for item in switch_lists:
if item and 'SWITCH_LIST' in item and item['SWITCH_LIST']:
switch_list.extend(item['SWITCH_LIST'])
for items in switch_lists:
for item in items['MACHINE_LIST']:
for k, v in item.items():
switch_list.append(k)
if host in switch_list:
return ("appliance", "Found", "")

View File

@ -27,7 +27,9 @@ class Mac(base.BaseSnmpMacPlugin):
"""Processes MAC address."""
def __init__(self, host, credential):
return
self.host = host
#self.credential = credential
#return
def scan(self):
"""Implemnets the scan method in BasePlugin class.
@ -36,8 +38,11 @@ class Mac(base.BaseSnmpMacPlugin):
Dummy scan function for compass appliance.
Returns fixed mac addresses.
"""
mac_lists = util.load_configs(setting.MAC_LIST_DIR)
mac_list = None
for item in mac_lists:
mac_list = item['MAC_LIST']
machine_lists = util.load_configs(setting.MACHINE_LIST_DIR)
for items in machine_lists:
for item in items['MACHINE_LIST']:
for k, v in item.items():
if k == self.host:
mac_list = v
return mac_list

View File

@ -116,11 +116,8 @@ CALLBACK_DIR = lazypy.delay(
TMPL_DIR = lazypy.delay(
lambda: os.path.join(CONFIG_DIR, 'templates')
)
MAC_LIST_DIR = lazypy.delay(
lambda: os.path.join(CONFIG_DIR, 'mac_list')
)
SWITCH_LIST_DIR = lazypy.delay(
lambda: os.path.join(CONFIG_DIR, 'switch_list')
MACHINE_LIST_DIR = lazypy.delay(
lambda: os.path.join(CONFIG_DIR, 'machine_list')
)
PROXY_URL_PREFIX = 'http://10.145.81.205:5000'

View File

@ -1,42 +0,0 @@
MAC_LIST = [
{
'port': '200',
'mac': '80:fb:06:35:8c:85',
'vlan': 0,
},
{
'port': '201',
'mac': '70:7b:e8:75:71:dc',
'vlan': 0,
},
{
'port': '202',
'mac': '80:fb:06:35:8c:a0',
'vlan': 0,
},
{
'port': '203',
'mac': '70:7b:e8:75:71:d3',
'vlan': 0,
},
{
'port': '204',
'mac': '70:7b:e8:75:72:21',
'vlan': 0,
},
{
'port': '205',
'mac': '70:7b:e8:75:71:37',
'vlan': 0,
},
{
'port': '206',
'mac': '70:fb:e8:75:71:d6',
'vlan': 0,
},
{
'port': '207',
'mac': '70:7b:e8:75:71:d9',
'vlan': 0,
}
]

View File

@ -0,0 +1,46 @@
MACHINE_LIST = [
{
'127.0.0.1': [
{
'port': '200',
'mac': '80:fb:06:35:8c:85',
'vlan': 0,
},
{
'port': '201',
'mac': '70:7b:e8:75:71:dc',
'vlan': 0,
},
{
'port': '202',
'mac': '80:fb:06:35:8c:a0',
'vlan': 0,
},
{
'port': '203',
'mac': '70:7b:e8:75:71:d3',
'vlan': 0,
},
{
'port': '204',
'mac': '70:7b:e8:75:72:21',
'vlan': 0,
},
{
'port': '205',
'mac': '70:7b:e8:75:71:37',
'vlan': 0,
},
{
'port': '206',
'mac': '70:fb:e8:75:71:d6',
'vlan': 0,
},
{
'port': '207',
'mac': '70:7b:e8:75:71:d9',
'vlan': 0,
}
]
},
]