Skip to content

Commit

Permalink
Add get_capabilities in nxapi module_utils (ansible#42688)
Browse files Browse the repository at this point in the history
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
  • Loading branch information
trishnaguha committed Jul 13, 2018
1 parent dc32842 commit d5e9653
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion lib/ansible/module_utils/network/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,34 @@ def load_config(self, commands, return_error=False, opts=None):
else:
return []

def get_device_info(self):
device_info = {}

device_info['network_os'] = 'nxos'
reply = self.run_commands({'command': 'show version', 'output': 'json'})
data = reply[0]

platform_reply = self.run_commands({'command': 'show inventory', 'output': 'json'})
platform_info = platform_reply[0]

device_info['network_os_version'] = data.get('sys_ver_str') or data.get('kickstart_ver_str')
device_info['network_os_model'] = data['chassis_id']
device_info['network_os_hostname'] = data['host_name']
device_info['network_os_image'] = data.get('isan_file_name') or data.get('kick_file_name')

if platform_info:
inventory_table = platform_info['TABLE_inv']['ROW_inv']
for info in inventory_table:
if 'Chassis' in info['name']:
device_info['network_os_platform'] = info['productid']

return device_info

def get_capabilities(self):
return {}
result = {}
result['device_info'] = self.get_device_info()
result['network_api'] = 'nxapi'
return result


def is_json(cmd):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/nxos/nxos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def main():

try:
info = get_capabilities(module)
api = info.get('network_api', 'nxapi')
api = info.get('network_api')
device_info = info.get('device_info', {})
os_platform = device_info.get('network_os_platform', '')
except ConnectionError:
Expand Down

0 comments on commit d5e9653

Please sign in to comment.