mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Add platform facts in network facts modules (#51434)
* Add platform facts in network facts modules Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Add nxos Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Add vyos Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Add iosxr Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Add junos Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * fix pep8 Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * update unit test Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * fix vyos_facts unittest Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * fix ios_facts unittest Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * fix iosxr unittests Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * fix CI failure Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * fix junos test Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
@@ -103,6 +103,14 @@ ansible_net_stacked_serialnums:
|
||||
description: The serial numbers of each device in the stack
|
||||
returned: when multiple devices are configured in a stack
|
||||
type: list
|
||||
ansible_net_api:
|
||||
description: The name of the transport
|
||||
returned: always
|
||||
type: str
|
||||
ansible_net_python_version:
|
||||
description: The Python version Ansible controller is using
|
||||
returned: always
|
||||
type: str
|
||||
|
||||
# hardware
|
||||
ansible_net_filesystems:
|
||||
@@ -148,9 +156,10 @@ ansible_net_neighbors:
|
||||
returned: when interfaces is configured
|
||||
type: dict
|
||||
"""
|
||||
import platform
|
||||
import re
|
||||
|
||||
from ansible.module_utils.network.ios.ios import run_commands
|
||||
from ansible.module_utils.network.ios.ios import run_commands, get_capabilities
|
||||
from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
|
||||
from ansible.module_utils.network.ios.ios import normalize_interface
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
@@ -180,21 +189,13 @@ class Default(FactsBase):
|
||||
|
||||
def populate(self):
|
||||
super(Default, self).populate()
|
||||
self.facts.update(self.platform_facts())
|
||||
data = self.responses[0]
|
||||
if data:
|
||||
self.facts['version'] = self.parse_version(data)
|
||||
self.facts['iostype'] = self.parse_iostype(data)
|
||||
self.facts['serialnum'] = self.parse_serialnum(data)
|
||||
self.facts['model'] = self.parse_model(data)
|
||||
self.facts['image'] = self.parse_image(data)
|
||||
self.facts['hostname'] = self.parse_hostname(data)
|
||||
self.parse_stacks(data)
|
||||
|
||||
def parse_version(self, data):
|
||||
match = re.search(r'Version (\S+?)(?:,\s|\s)', data)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
def parse_iostype(self, data):
|
||||
match = re.search(r'\S+(X86_64_LINUX_IOSD-UNIVERSALK9-M)(\S+)', data)
|
||||
if match:
|
||||
@@ -202,21 +203,6 @@ class Default(FactsBase):
|
||||
else:
|
||||
return "IOS"
|
||||
|
||||
def parse_hostname(self, data):
|
||||
match = re.search(r'^(.+) uptime', data, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
def parse_model(self, data):
|
||||
match = re.search(r'^[Cc]isco (\S+).+bytes of .*memory', data, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
def parse_image(self, data):
|
||||
match = re.search(r'image file is "(.+)"', data)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
def parse_serialnum(self, data):
|
||||
match = re.search(r'board ID (\S+)', data)
|
||||
if match:
|
||||
@@ -231,6 +217,24 @@ class Default(FactsBase):
|
||||
if match:
|
||||
self.facts['stacked_serialnums'] = match
|
||||
|
||||
def platform_facts(self):
|
||||
platform_facts = {}
|
||||
|
||||
resp = get_capabilities(self.module)
|
||||
device_info = resp['device_info']
|
||||
|
||||
platform_facts['system'] = device_info['network_os']
|
||||
|
||||
for item in ('model', 'image', 'version', 'platform', 'hostname'):
|
||||
val = device_info.get('network_os_%s' % item)
|
||||
if val:
|
||||
platform_facts[item] = val
|
||||
|
||||
platform_facts['api'] = resp['network_api']
|
||||
platform_facts['python_version'] = platform.python_version()
|
||||
|
||||
return platform_facts
|
||||
|
||||
|
||||
class Hardware(FactsBase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user