-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendconfig
executable file
·46 lines (38 loc) · 1.46 KB
/
sendconfig
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##########################################################################
# ./sendconfig - Sends a configuration file to a netgear switch
# Copyright © 2014 Ghislain Loaec <gloaec@cadoles.com>
#
# License GPLv3: http://sourceforge.net/directory/license:gplv3/
##########################################################################
import sys
import os
import argparse
from netgear import Api
config = {}
def main(argv):
version = ' '.join([sys.argv[0], config['VERSION']])
parser = argparse.ArgumentParser()
parser.add_argument("configfile",
help = "Switch configuration file")
parser.add_argument("-D", "--debug",
action = "store_true",
help = "Debug mode")
parser.add_argument("-v", "--version",
action = 'version',
version = version,
help = "Display version")
args = parser.parse_args()
api = Api(app_host = config['APP_HOST'],
app_password = config['APP_PASSWORD'],
debug = args.debug)
#try:
if api.uploadConfig(args.configfile):
print 'Configuration successfully transferred'
else: raise Exception('Cannot upload configuration')
#except Exception, e:
# print "Error:", e
if __name__ == "__main__":
execfile(os.path.join(os.path.dirname(os.path.realpath(__file__)), "netgear.conf"), config)
main(sys.argv[1:])