From 55a34298a135b273971c8c99f35b50220574a465 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 6 Sep 2016 10:51:06 +0600 Subject: Add generic run_op_mode_command and run_conf_mode_command so that people can use functions outside of set/delete/commit that we don't support yet, like show, rename or whatever else. --- vymgmt/router.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'vymgmt') diff --git a/vymgmt/router.py b/vymgmt/router.py index c638e31..74b8709 100644 --- a/vymgmt/router.py +++ b/vymgmt/router.py @@ -96,10 +96,32 @@ class Router(object): self.__conn.close() self.__logged_in = False - def configure(self): - """Enter the VyOS configure mode + def run_op_mode_command(self, command): + """ Execute a VyOS operational command + + :param command: VyOS operational command + :return: Command output + """ + + prefix = "" + # In cond mode, op mode commands require the "run" prefix + if self.__conf_mode: + prefix = "run" + + return self.__execute_command("{0} {1}".format(prefix, command)) + def run_conf_mode_command(self, command): + """ Execute a VyOS configuration command + + :param command: VyOS configuration command + :return: Command output """ + if not self.__conf_mode: + raise VyOSError("Cannot execute configuration mode commands outside of configuration mode") + else: + return self.__execute_command(command) + + def configure(self): if not self.__logged_in: raise VyOSError("Cannot enter configuration mode when not logged in") else: -- cgit v1.2.3