-
Notifications
You must be signed in to change notification settings - Fork 9
/
netspark.py
55 lines (45 loc) · 2.12 KB
/
netspark.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
'''
This script is the master controller script. It will make the necessary
commands to run whatever is needed against whatever is needed.
Usage:
netspark.py -h | --help
netspark.py (--info COMMAND | --config CONFIGFILE) (--csv FILENAME | --db QUERYNAME | --ip IPADDR) [-c CREDFILE] [--debug]
Options:
-h, --help Shows this menu.
-d, --debug Print debug information. This is the most verbose
option.
--info COMMAND This will run regular show commands
--config CONFIGFILE This will run configuration commands
--csv FILENAME Input file if using CSV [default: test.csv]
--db QUERYNAME SQL field: 'groupname' [default: test]
--ip IPADDR Single IP address of test switch
-c CREDFILE Crednetials file [default: credentials.csv]
'''
import os.path
import logging
from docopt import docopt
import spark_threaded as st
arguments = docopt(__doc__)
# Set logging level https://www.digitalocean.com/community/tutorials/how-to-use-logging-in-python-3
# This is for debugging.
if arguments['--debug'] == True:
logging.basicConfig(level=logging.DEBUG)
print("Arguments: \n" + str(arguments))
else:
logging.basicConfig(level=logging.WARNING)
# Global variable MODE stores whether we're running config or not. This is here instead of defined
# in the functions below because I'm going to use it for testing.
MODE = st.check_config_mode(arguments['--config'])
logging.debug("Value for MODE evaluated to: " + str(MODE))
if MODE is False:
st.info_command(arguments['--info'], arguments['--csv'], arguments['--db'], arguments['--ip'], arguments['-c'])
elif MODE is True:
COMMANDLIST = []
if os.path.exists(arguments['--config']):
with open(arguments['--config']) as conffile:
for row in conffile:
COMMANDLIST.append(row)
st.COMMANDLIST = COMMANDLIST
st.config_command(arguments['--config'], arguments['--csv'], arguments['--db'], arguments['--ip'], arguments['-c'])
else:
logging.info("You somehow broke the required info/config arguments!")