diff options
author | Nilashish Chakraborty <nilashishchakraborty8@gmail.com> | 2021-02-19 20:18:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 14:48:12 +0000 |
commit | ea481d755414ee3390a2ff5792be9c67896fa567 (patch) | |
tree | fb4d06d62aa6382a43998f63dc0a8fbeb7b643ba /plugins | |
parent | 7a5b1d97c706e695257af464cd7cc207d2d9bd3b (diff) | |
download | vyos-ansible-old-ea481d755414ee3390a2ff5792be9c67896fa567.tar.gz vyos-ansible-old-ea481d755414ee3390a2ff5792be9c67896fa567.zip |
Add support for single_user_mode (#123)
Add support for single_user_mode
Reviewed-by: https://github.com/apps/ansible-zuul
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/cliconf/vyos.py | 49 | ||||
-rw-r--r-- | plugins/terminal/vyos.py | 2 |
2 files changed, 36 insertions, 15 deletions
diff --git a/plugins/cliconf/vyos.py b/plugins/cliconf/vyos.py index de9e93d..c8aaff9 100644 --- a/plugins/cliconf/vyos.py +++ b/plugins/cliconf/vyos.py @@ -28,6 +28,18 @@ description: - This vyos plugin provides low level abstraction apis for sending and receiving CLI commands from VyOS network devices. version_added: 1.0.0 +options: + config_commands: + description: + - Specifies a list of commands that can make configuration changes + to the target device. + - When `ansible_network_single_user_mode` is enabled, if a command sent + to the device is present in this list, the existing cache is invalidated. + version_added: 2.0.0 + type: list + default: [] + vars: + - name: ansible_vyos_config_commands """ import re @@ -46,27 +58,34 @@ from ansible.plugins.cliconf import CliconfBase class Cliconf(CliconfBase): + def __init__(self, *args, **kwargs): + super(Cliconf, self).__init__(*args, **kwargs) + self._device_info = {} + def get_device_info(self): - device_info = {} + if not self._device_info: + device_info = {} + + device_info["network_os"] = "vyos" + reply = self.get("show version") + data = to_text(reply, errors="surrogate_or_strict").strip() - device_info["network_os"] = "vyos" - reply = self.get("show version") - data = to_text(reply, errors="surrogate_or_strict").strip() + match = re.search(r"Version:\s*(.*)", data) + if match: + device_info["network_os_version"] = match.group(1) - match = re.search(r"Version:\s*(.*)", data) - if match: - device_info["network_os_version"] = match.group(1) + match = re.search(r"HW model:\s*(\S+)", data) + if match: + device_info["network_os_model"] = match.group(1) - match = re.search(r"HW model:\s*(\S+)", data) - if match: - device_info["network_os_model"] = match.group(1) + reply = self.get("show host name") + device_info["network_os_hostname"] = to_text( + reply, errors="surrogate_or_strict" + ).strip() - reply = self.get("show host name") - device_info["network_os_hostname"] = to_text( - reply, errors="surrogate_or_strict" - ).strip() + self._device_info = device_info - return device_info + return self._device_info def get_config(self, flags=None, format=None): if format: diff --git a/plugins/terminal/vyos.py b/plugins/terminal/vyos.py index a659002..bf9d87b 100644 --- a/plugins/terminal/vyos.py +++ b/plugins/terminal/vyos.py @@ -53,6 +53,8 @@ class TerminalModule(TerminalBase): re.compile(br"\x1b]0;[^\x07]*\x07"), ] + terminal_config_prompt = re.compile(r"^.+#$") + try: terminal_length = os.getenv("ANSIBLE_VYOS_TERMINAL_LENGTH", 10000) terminal_length = int(terminal_length) |