diff options
author | Daniil Baturin <daniil@baturin.org> | 2016-09-06 10:51:06 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2016-09-06 10:51:06 +0600 |
commit | 55a34298a135b273971c8c99f35b50220574a465 (patch) | |
tree | fd780122c535c90c0a54cedd1fecef4c0eb4a4b6 | |
parent | 97b35d3aad1be5382db7e6e891c64157fc35ed3f (diff) | |
download | python-vyos-mgmt-55a34298a135b273971c8c99f35b50220574a465.tar.gz python-vyos-mgmt-55a34298a135b273971c8c99f35b50220574a465.zip |
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.
-rw-r--r-- | vymgmt/router.py | 26 |
1 files changed, 24 insertions, 2 deletions
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: |