mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07: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:
parent
5cd7bf39dd
commit
a41028244d
16 changed files with 303 additions and 180 deletions
|
@ -86,10 +86,13 @@ ansible_facts:
|
|||
returned: always
|
||||
type: dict
|
||||
"""
|
||||
|
||||
import platform
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.common.netconf import exec_rpc
|
||||
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_param, tostring
|
||||
from ansible.module_utils.network.junos.junos import get_configuration, get_connection
|
||||
from ansible.module_utils.network.junos.junos import get_configuration, get_capabilities
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
@ -138,19 +141,30 @@ class FactsBase(object):
|
|||
class Default(FactsBase):
|
||||
|
||||
def populate(self):
|
||||
reply = self.rpc('get-software-information')
|
||||
data = reply.find('.//software-information')
|
||||
|
||||
self.facts.update({
|
||||
'hostname': self.get_text(data, 'host-name'),
|
||||
'version': self.get_text(data, 'junos-version'),
|
||||
'model': self.get_text(data, 'product-model')
|
||||
})
|
||||
self.facts.update(self.platform_facts())
|
||||
|
||||
reply = self.rpc('get-chassis-inventory')
|
||||
data = reply.find('.//chassis-inventory/chassis')
|
||||
self.facts['serialnum'] = self.get_text(data, 'serial-number')
|
||||
|
||||
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 Config(FactsBase):
|
||||
|
||||
|
@ -318,7 +332,6 @@ def main():
|
|||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
get_connection(module)
|
||||
warnings = list()
|
||||
gather_subset = module.params['gather_subset']
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue