From c5bb8f17f637ddd62b5cf51b5010d38c26914dfb Mon Sep 17 00:00:00 2001 From: Lei Lei Date: Fri, 17 Oct 2014 17:46:31 -0700 Subject: [PATCH] get mac and switch from config file. Change-Id: I048057d7d5804478e331ebf92bbe299bb029d7ed --- compass/hdsdiscovery/hdmanager.py | 8 +++- .../vendors/appliance/plugins/mac.py | 47 ++++--------------- compass/utils/setting_wrapper.py | 6 +++ conf/mac_list/mac_list.conf | 42 +++++++++++++++++ conf/switch_list/switch_list.conf | 3 ++ 5 files changed, 67 insertions(+), 39 deletions(-) create mode 100644 conf/mac_list/mac_list.conf create mode 100644 conf/switch_list/switch_list.conf diff --git a/compass/hdsdiscovery/hdmanager.py b/compass/hdsdiscovery/hdmanager.py index 080caf45..81108141 100644 --- a/compass/hdsdiscovery/hdmanager.py +++ b/compass/hdsdiscovery/hdmanager.py @@ -19,6 +19,8 @@ import re from compass.hdsdiscovery.error import TimeoutError from compass.hdsdiscovery import utils +from compass.utils import setting_wrapper as setting +from compass.utils import util UNREACHABLE = 'unreachable' @@ -99,7 +101,11 @@ class HDManager(object): :return a tuple (vendor, switch_state, error) """ - if host == '127.0.0.1': + switch_lists = util.load_configs(setting.SWITCH_LIST_DIR) + switch_list = None + for item in switch_lists: + switch_list = item['SWITCH_LIST'] + if host in switch_list: return ("appliance", "Found", "") # TODO(grace): Why do we need to have valid IP? diff --git a/compass/hdsdiscovery/vendors/appliance/plugins/mac.py b/compass/hdsdiscovery/vendors/appliance/plugins/mac.py index 1c856403..4244eb13 100644 --- a/compass/hdsdiscovery/vendors/appliance/plugins/mac.py +++ b/compass/hdsdiscovery/vendors/appliance/plugins/mac.py @@ -14,6 +14,11 @@ """Compass Appliance Mac module.""" from compass.hdsdiscovery import base +from compass.utils import setting_wrapper as setting +from compass.utils import util + +import logging + CLASS_NAME = "Mac" @@ -31,42 +36,8 @@ class Mac(base.BaseSnmpMacPlugin): Dummy scan function for compass appliance. Returns fixed mac addresses. """ - 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, - }] + mac_lists = util.load_configs(setting.MAC_LIST_DIR) + mac_list = None + for item in mac_lists: + mac_list = item['MAC_LIST'] return mac_list diff --git a/compass/utils/setting_wrapper.py b/compass/utils/setting_wrapper.py index fbedadf0..b660bf66 100644 --- a/compass/utils/setting_wrapper.py +++ b/compass/utils/setting_wrapper.py @@ -116,6 +116,12 @@ 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') +) PROXY_URL_PREFIX = 'http://10.145.81.205:5000' if ( diff --git a/conf/mac_list/mac_list.conf b/conf/mac_list/mac_list.conf new file mode 100644 index 00000000..6485f6c1 --- /dev/null +++ b/conf/mac_list/mac_list.conf @@ -0,0 +1,42 @@ +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, + } +] diff --git a/conf/switch_list/switch_list.conf b/conf/switch_list/switch_list.conf new file mode 100644 index 00000000..21c46c0a --- /dev/null +++ b/conf/switch_list/switch_list.conf @@ -0,0 +1,3 @@ +SWITCH_LIST = [ + '127.0.0.1' +]