diff options
author | Hochikong <michellehzg@gmail.com> | 2016-05-24 22:27:58 +0800 |
---|---|---|
committer | Hochikong <michellehzg@gmail.com> | 2016-05-24 22:27:58 +0800 |
commit | d474dd0f20db9b9bc66908e54b47bcceb71fd490 (patch) | |
tree | bc215d3092ef25c5288ebfbeb98e901c597671e8 | |
parent | 21f0b5ec2197df59f31384ef2c9a541518669f9f (diff) | |
download | python-vyos-mgmt-d474dd0f20db9b9bc66908e54b47bcceb71fd490.tar.gz python-vyos-mgmt-d474dd0f20db9b9bc66908e54b47bcceb71fd490.zip |
fix first bug
-rw-r--r-- | dist/vyroute-0.1-py2.7.egg | bin | 14646 -> 14430 bytes | |||
-rw-r--r-- | vyroute/Router.py | 5 | ||||
-rw-r--r-- | vyroute/basic_function/DeleteRoute.py | 51 |
3 files changed, 22 insertions, 34 deletions
diff --git a/dist/vyroute-0.1-py2.7.egg b/dist/vyroute-0.1-py2.7.egg Binary files differindex 7c08760..68cc6b7 100644 --- a/dist/vyroute-0.1-py2.7.egg +++ b/dist/vyroute-0.1-py2.7.egg diff --git a/vyroute/Router.py b/vyroute/Router.py index eae8843..fe95289 100644 --- a/vyroute/Router.py +++ b/vyroute/Router.py @@ -39,6 +39,9 @@ class Router(object): def lo(self, data): pass + def delete_route(self, data): + pass + # Basic VyOS configuration func def configure(self): pass @@ -82,7 +85,7 @@ class BasicRouter(Router): :return: a python dictionary """ try: - if self.conn.connect(self.address) == "True": + if self.conn.connect(self.address) is True: self.conn.login(self.account) self.status["object"] = "login" return {"Result": "Login successfully."} diff --git a/vyroute/basic_function/DeleteRoute.py b/vyroute/basic_function/DeleteRoute.py index 87af263..17c8531 100644 --- a/vyroute/basic_function/DeleteRoute.py +++ b/vyroute/basic_function/DeleteRoute.py @@ -3,12 +3,11 @@ from Exscript.protocols import SSH2 from Exscript import Account -def deleteroute(data): +def deleteroute(obj, data): """This method provide a router configuration delete function Parameter data example: - {'router':'vyos@172.16.77.188','passwd':'vyos', - 'config':'rip' + {'config':'rip'/'static'/'ospf'/'all' } WARNING! @@ -17,41 +16,27 @@ def deleteroute(data): If you do not want your setting disappear,you can delete router configuration manually or rewrite this func. + :param obj: a connection object :param data: a python dictionary :return: a python dictionary """ delete_basic_configuration = "delete protocols %s" + delete_all_protocols = "delete protocols" 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") - - # delete specific configuration - conn.execute(delete_basic_configuration % data['config']) - - # commit configuration - conn.execute("commit") - - # save configuration - conn.execute("save") - - # exit configure mode - conn.execute("exit") - - # close connection - conn.close(force=True) - - return {"Result": "Delete successfully"} - + if data['config'] == "all": + obj.execute(delete_all_protocols) + return {"Result": "Delete successfully."} + elif data['config'] == 'rip': + obj.execute(delete_basic_configuration % 'rip') + return {"Result": "Delete successfully."} + elif data['config'] == 'static': + obj.execute(delete_basic_configuration % 'static') + return {"Result": "Delete successfully."} + elif data['config'] == 'ospf': + obj.execute(delete_basic_configuration % 'ospf') + return {"Result": "Delete successfully."} + else: + return {"Error": "Nonsupport protocols type."} except Exception, e: return {"Error": e}
\ No newline at end of file |