mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +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:
@@ -96,6 +96,14 @@ ansible_net_fqdn:
|
||||
description: The fully qualified domain name of the device
|
||||
returned: always
|
||||
type: str
|
||||
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:
|
||||
@@ -135,11 +143,13 @@ ansible_net_neighbors:
|
||||
returned: when interfaces is configured
|
||||
type: dict
|
||||
"""
|
||||
|
||||
import platform
|
||||
import re
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.network.eos.eos import run_commands
|
||||
from ansible.module_utils.network.eos.eos import run_commands, get_capabilities
|
||||
from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args
|
||||
|
||||
|
||||
@@ -159,15 +169,12 @@ class FactsBase(object):
|
||||
class Default(FactsBase):
|
||||
|
||||
SYSTEM_MAP = {
|
||||
'version': 'version',
|
||||
'serialNumber': 'serialnum',
|
||||
'modelName': 'model'
|
||||
}
|
||||
|
||||
COMMANDS = [
|
||||
'show version | json',
|
||||
'show hostname | json',
|
||||
'bash timeout 5 cat /mnt/flash/boot-config'
|
||||
]
|
||||
|
||||
def populate(self):
|
||||
@@ -178,18 +185,25 @@ class Default(FactsBase):
|
||||
self.facts[value] = data[key]
|
||||
|
||||
self.facts.update(self.responses[1])
|
||||
self.facts.update(self.parse_image())
|
||||
self.facts.update(self.platform_facts())
|
||||
|
||||
def parse_image(self):
|
||||
data = self.responses[2]
|
||||
if isinstance(data, dict):
|
||||
data = data['messages'][0]
|
||||
match = re.search(r'SWI=(.+)$', data, re.M)
|
||||
if match:
|
||||
value = match.group(1)
|
||||
else:
|
||||
value = None
|
||||
return dict(image=value)
|
||||
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