mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Persistence connection for cnos_vlan (#42500)
* Changing Lenovo Inc to Lenovo and update License file to be consistent. * Changing cnos_vlan from paramiko to persistence connection of Ansible. Also talking care of CLI changes in CNOS commands with backward compatibility. * Fixing Validation issues * Trailing lines removal * Review comments of Gundalow are getting addressed. He mentioned only at one place for cnos.py. But I have covered the entire file. * Changes to incorporate Review comments from Qalthos * Removing configure terminal command from module code * Aligning with change in run_cnos_commands method changes * Editing cliconf for latest CNOS CLIs
This commit is contained in:
parent
1a0330488f
commit
0897e79bd1
6 changed files with 204 additions and 151 deletions
|
@ -32,39 +32,52 @@ class Cliconf(CliconfBase):
|
|||
device_info = {}
|
||||
|
||||
device_info['network_os'] = 'cnos'
|
||||
reply = self.get(b'display version')
|
||||
reply = self.get(b'show sys-info')
|
||||
data = to_text(reply, errors='surrogate_or_strict').strip()
|
||||
|
||||
match = re.search(r'^System version: (.*?) ', data, re.M | re.I)
|
||||
if match:
|
||||
device_info['network_os_version'] = match.group(1)
|
||||
|
||||
match = re.search(r'^Lenovo RackSwitch (\S+)', data, re.M | re.I)
|
||||
if match:
|
||||
device_info['network_os_model'] = match.group(1)
|
||||
|
||||
match = re.search(r'^Device name: (.*?) ', data, re.M | re.I)
|
||||
if match:
|
||||
device_info['network_os_hostname'] = match.group(1)
|
||||
else:
|
||||
device_info['network_os_hostname'] = "NA"
|
||||
host = self.get(b'show hostname')
|
||||
hostname = to_text(host, errors='surrogate_or_strict').strip()
|
||||
if data:
|
||||
device_info['network_os_version'] = self.parse_version(data)
|
||||
device_info['network_os_model'] = self.parse_model(data)
|
||||
device_info['network_os_hostname'] = hostname
|
||||
|
||||
return device_info
|
||||
|
||||
def parse_version(self, data):
|
||||
for line in data.split('\n'):
|
||||
line = line.strip()
|
||||
match = re.match(r'System Software Revision (.*?)',
|
||||
line, re.M | re.I)
|
||||
if match:
|
||||
vers = line.split(':')
|
||||
ver = vers[1].strip()
|
||||
return ver
|
||||
return "NA"
|
||||
|
||||
def parse_model(self, data):
|
||||
for line in data.split('\n'):
|
||||
line = line.strip()
|
||||
match = re.match(r'System Model (.*?)', line, re.M | re.I)
|
||||
if match:
|
||||
mdls = line.split(':')
|
||||
mdl = mdls[1].strip()
|
||||
return mdl
|
||||
return "NA"
|
||||
|
||||
@enable_mode
|
||||
def get_config(self, source='running', format='text'):
|
||||
if source not in ('running', 'startup'):
|
||||
msg = "fetching configuration from %s is not supported"
|
||||
return self.invalid_params(msg % source)
|
||||
if source == 'running':
|
||||
cmd = b'display running-config'
|
||||
cmd = b'show running-config'
|
||||
else:
|
||||
cmd = b'display startup-config'
|
||||
cmd = b'show startup-config'
|
||||
return self.send_command(cmd)
|
||||
|
||||
@enable_mode
|
||||
def edit_config(self, command):
|
||||
for cmd in chain([b'configure device'], to_list(command), [b'end']):
|
||||
for cmd in chain([b'configure terminal'], to_list(command), [b'end']):
|
||||
self.send_command(cmd)
|
||||
|
||||
def get(self, command, prompt=None, answer=None, sendonly=False):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue