diff options
author | Hochikong <michellehzg@gmail.com> | 2016-05-23 19:38:16 +0800 |
---|---|---|
committer | Hochikong <michellehzg@gmail.com> | 2016-05-23 19:38:16 +0800 |
commit | 8e2f9aa509a5d90897844c196675836a10068237 (patch) | |
tree | c5aaf9af194d730ecd1ce486e64b07cd2f39b96c /vyroute/basic_function/RIPRoute.py | |
parent | 71db4ed81a299a8f4b1947272bccb7966360f98f (diff) | |
download | python-vyos-mgmt-8e2f9aa509a5d90897844c196675836a10068237.tar.gz python-vyos-mgmt-8e2f9aa509a5d90897844c196675836a10068237.zip |
add new file and modify some wrong
Diffstat (limited to 'vyroute/basic_function/RIPRoute.py')
-rw-r--r-- | vyroute/basic_function/RIPRoute.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vyroute/basic_function/RIPRoute.py b/vyroute/basic_function/RIPRoute.py new file mode 100644 index 0000000..f559a17 --- /dev/null +++ b/vyroute/basic_function/RIPRoute.py @@ -0,0 +1,55 @@ +# author=hochikong +from Exscript.protocols import SSH2 +from Exscript import Account + + +def riproute(data): + """This method provide a RIP protocols router configuration function + + Parameter data example: + {'router':'vyos@172.16.77.188','passwd':'vyos', + 'config':['192.168.10.0/24','10.20.10.0/24'], + } + + :param data: a python dictionary + :return: a python dictionary + """ + rip_basic_configuration = "set protocols rip network %s" + redistribute_configuration = "set protocols rip redistribute connected" + try: + stringlist = list(data['router']) + divi = stringlist.index('@') + user = ''.join(stringlist[:divi]) + passwd = data['passwd'] + address = ''.join(stringlist[divi + 1:]) + account = Account(user, passwd) + conn = SSH2() + conn.connect(address) + conn.login(account) + + # configure mode + conn.execute("configure") + + # configure RIP router + for i in data['config']: + conn.execute(rip_basic_configuration % i) + + conn.execute(redistribute_configuration) + + # commit configuration + conn.execute("commit") + + # save configuration + conn.execute("save") + + # exit configure mode + conn.execute("exit") + + # close connection + conn.close(force=True) + + return {"Result": "Configured successfully"} + + except Exception, e: + return {"Error": e} + |