mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +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:
@@ -185,6 +185,20 @@ class Cli:
|
||||
self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||
return diff
|
||||
|
||||
def get_capabilities(self):
|
||||
"""Returns platform info of the remove device
|
||||
"""
|
||||
if hasattr(self._module, '_capabilities'):
|
||||
return self._module._capabilities
|
||||
|
||||
connection = self._get_connection()
|
||||
try:
|
||||
capabilities = connection.get_capabilities()
|
||||
except ConnectionError as exc:
|
||||
self._module.fail_json(msg=to_text(exc, errors='surrogate_then_replace'))
|
||||
self._module._capabilities = json.loads(capabilities)
|
||||
return self._module._capabilities
|
||||
|
||||
|
||||
class LocalEapi:
|
||||
|
||||
@@ -617,3 +631,8 @@ def load_config(module, config, commit=False, replace=False):
|
||||
def get_diff(self, candidate=None, running=None, diff_match='line', diff_ignore_lines=None, path=None, diff_replace='line'):
|
||||
conn = self.get_connection()
|
||||
return conn.get_diff(candidate=candidate, running=running, diff_match=diff_match, diff_ignore_lines=diff_ignore_lines, path=path, diff_replace=diff_replace)
|
||||
|
||||
|
||||
def get_capabilities(module):
|
||||
conn = get_connection(module)
|
||||
return conn.get_capabilities()
|
||||
|
||||
@@ -145,7 +145,7 @@ def get_connection(module):
|
||||
if hasattr(module, 'connection'):
|
||||
return module.connection
|
||||
|
||||
capabilities = get_device_capabilities(module)
|
||||
capabilities = get_capabilities(module)
|
||||
network_api = capabilities.get('network_api')
|
||||
if network_api == 'cliconf':
|
||||
module.connection = Connection(module._socket_path)
|
||||
@@ -157,7 +157,7 @@ def get_connection(module):
|
||||
return module.connection
|
||||
|
||||
|
||||
def get_device_capabilities(module):
|
||||
def get_capabilities(module):
|
||||
if hasattr(module, 'capabilities'):
|
||||
return module.capabilities
|
||||
try:
|
||||
@@ -317,12 +317,12 @@ def etree_findall(root, node):
|
||||
|
||||
|
||||
def is_cliconf(module):
|
||||
capabilities = get_device_capabilities(module)
|
||||
capabilities = get_capabilities(module)
|
||||
return (capabilities.get('network_api') == 'cliconf')
|
||||
|
||||
|
||||
def is_netconf(module):
|
||||
capabilities = get_device_capabilities(module)
|
||||
capabilities = get_capabilities(module)
|
||||
network_api = capabilities.get('network_api')
|
||||
if network_api == 'netconf':
|
||||
if not HAS_NCCLIENT:
|
||||
|
||||
Reference in New Issue
Block a user