Debian Codegraph @

ansible_collections/community/routeros/plugins/cliconf/routeros.py

raw
1 # Copyright (c) 2017 Red Hat Inc.
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import (absolute_import, division, print_function)
6 __metaclass__ = type
7
8 DOCUMENTATION = r"""
9 author: "Egor Zaitsev (@heuels)"
10 name: routeros
11 short_description: Use routeros cliconf to run command on MikroTik RouterOS platform
12 description:
13 - This routeros plugin provides low level abstraction APIs for sending and receiving CLI commands from MikroTik RouterOS
14 network devices.
15 """
16
17 import re
18 import json
19
20 from ansible.module_utils.common.text.converters import to_text
21 from ansible.plugins.cliconf import CliconfBase
22
23
24 class Cliconf(CliconfBase):
25
26 def get_device_info(self):
27 device_info = {}
28 device_info['network_os'] = 'RouterOS'
29
30 resource = self.get('/system resource print')
31 data = to_text(resource, errors='surrogate_or_strict').strip()
32 match = re.search(r'version: (\S+)', data)
33 if match:
34 device_info['network_os_version'] = match.group(1)
35
36 routerboard = self.get('/system routerboard print')
37 data = to_text(routerboard, errors='surrogate_or_strict').strip()
38 match = re.search(r'model: (.+)$', data, re.M)
39 if match:
40 device_info['network_os_model'] = match.group(1)
41
42 identity = self.get('/system identity print')
43 data = to_text(identity, errors='surrogate_or_strict').strip()
44 match = re.search(r'name: (.+)$', data, re.M)
45 if match:
46 device_info['network_os_hostname'] = match.group(1)
47
48 return device_info
49
50 def get_config(self, source='running', flags=None, format=None):
51 return
52
53 def edit_config(self, command):
54 return
55
56 def get(self, command, prompt=None, answer=None, sendonly=False, newline=True, check_all=False):
57 return self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline, check_all=check_all)
58
59 def get_capabilities(self):
60 result = super(Cliconf, self).get_capabilities()
61 return json.dumps(result)