-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
74 lines (61 loc) · 1.84 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
# -*- coding: utf-8 -*-
from ConfigParser import SafeConfigParser
from sys import exit
import logging
from switch import Switch
# define env variables
logging_file = 'log'
logging_level = logging.DEBUG
conf_files = ['public.conf', 'mac_info.conf']
# read application config
config = SafeConfigParser()
config.read(conf_files)
conf_warn = ""
try:
logging_file = config.get('logging', 'file1')
logging_conf_level = config.get('logging', 'level')
except Exception, e:
conf_warn = "Can't read logging config:" + str(e)
logging_conf_level = None
# init log file
if logging_conf_level:
level = logging_conf_level.lower()
if level == "debug":
logging_level = logging.DEBUG
elif level == "info":
logging_level = logging.INFO
elif level == "warning":
logging_level = logging.WARNING
elif level == "error":
logging_level = logging.ERROR
elif level == "critical":
logging_level = logging.CRITICAL
logging.basicConfig(
filename=logging_file,
level=logging_level,
format='%(asctime)s %(levelname)s %(message)s',
datefmt='%m/%d/%Y %H:%M:%S'
)
if conf_warn != "":
logging.warning(conf_warn)
# exit(1)
def get_switch_config():
for section in config.sections():
if section.find("switch_") != -1:
switch_conf = {}
for item in ["switch_type", "ip", "name", "stack_member", "user", "pass"]:
switch_conf[item] = config.get(section, item)
return switch_conf
if __name__ == "__main__":
print "Test"
dict_sw = get_switch_config()
sw = Switch(
stype=dict_sw['switch_type'],
sm=dict_sw['stack_member'],
ip=dict_sw['ip'],
host=dict_sw['name'],
user=dict_sw['user'],
passwd=dict_sw['pass']
)
sw.info()