mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
[CLI_CONF] Refactor nxos module common library to use cliconf plugin (#31524)
* refactor nxos modules Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * get_config update * fix get_config * update nxos module * device_info * fix conflict * add failure message check * pep8 fixes * use get_capabilities to check cliconf * Add logic to detect platform in get_capabilities and cache in module_utils * return msg in edit_config * fix conflicts * make modules compatible * fix nxos cliconf api Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * cache capabilities * Update transport queries to get_capabilities in module level * fix unit tests * load_config error code * remove unnecessary change * Refactor nxos_install_os module
This commit is contained in:
parent
bd399ec674
commit
9f86b923e9
23 changed files with 220 additions and 132 deletions
|
@ -35,21 +35,36 @@ class Cliconf(CliconfBase):
|
|||
device_info['network_os'] = 'nxos'
|
||||
reply = self.get(b'show version | json')
|
||||
data = json.loads(reply)
|
||||
platform_reply = self.get(b'show inventory | json')
|
||||
platform_info = json.loads(platform_reply)
|
||||
|
||||
device_info['network_os_version'] = data['sys_ver_str']
|
||||
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['isan_file_name']
|
||||
device_info['network_os_image'] = data.get('isan_file_name') or data.get('kick_file_name')
|
||||
|
||||
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_config(self, source='running'):
|
||||
def get_config(self, source='running', flags=None):
|
||||
lookup = {'running': 'running-config', 'startup': 'startup-config'}
|
||||
return self.send_command(b'show %s' % lookup[source])
|
||||
|
||||
cmd = b'show {} '.format(lookup[source])
|
||||
cmd += ' '.join(flags)
|
||||
cmd = cmd.strip()
|
||||
|
||||
return self.send_command(cmd)
|
||||
|
||||
def edit_config(self, command):
|
||||
responses = []
|
||||
for cmd in chain([b'configure'], to_list(command), [b'end']):
|
||||
self.send_command(cmd)
|
||||
responses.append(self.send_command(cmd))
|
||||
|
||||
return json.dumps(responses)
|
||||
|
||||
def get(self, command, prompt=None, answer=None, sendonly=False):
|
||||
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue