cisco nexus

This commit is contained in:
ROTTLER Tamas 2025-07-19 13:23:51 +02:00
parent c99e790fc8
commit 08a0666929
3 changed files with 47 additions and 5 deletions

View File

@ -5,6 +5,7 @@
{% if 'routeros' in group_names %}routeros
{% elif 'ciscoasa' in group_names %}asa
{% elif 'ciscoios' in group_names %}ios
{% elif 'cisconexus' in group_names %}nexus
{% elif 'hpcomware' in group_names %}comware
{% else %}undefined
{% endif %}

View File

@ -13,12 +13,12 @@ import difflib
def get_args():
parser = argparse.ArgumentParser(
description='routerbackup - save routeros/ios/asa router configuration')
description='routerbackup - save routeros/ios/nexus/asa router configuration')
parser.add_argument('-t', '--type',
required=True,
action='store',
help='device type {routeros,ios,asa}')
help='device type {routeros,ios,nexus,asa}')
parser.add_argument('-H', '--host',
required=True,
action='store',
@ -349,6 +349,45 @@ class IosConfig(Config):
return prepared
class NexusConfig(Config):
def __init__(self, workdir):
super().__init__(workdir)
self.extra['iproute'] = {
'type': 'text',
'content': None
}
def get_config(self):
shrun = []
stdin, stdout, stderr = self.ssh.exec_command('sh run')
for line in stdout:
line = line.rstrip()
shrun.append(line)
iproute = []
for cmd in ('sh ip interface brief', 'sh ip route'):
stdin, stdout, stderr = self.ssh.exec_command(cmd)
iproute.append('# '+ cmd.center(76, '='))
for line in stdout:
line = line.rstrip()
iproute.append(line)
self.config = '\n'.join(shrun)
self.extra['iproute']['content'] = '\n'.join(iproute)
def _prepare_config_for_diff(self, configlines):
prepared = []
for line in configlines:
if not re.search('\S', line):
continue
if re.match('!Running configuration last done at', line):
continue
if re.match('!Time', line):
continue
prepared.append(line)
return prepared
class ConfigWithShell(Config):
def _shell_command(self, channel, cmd,
waitfor=None,
@ -461,13 +500,15 @@ def main():
args = get_args()
setup_logging(args.host, args.logfile, args.loglevel)
try:
if args.type not in ('routeros', 'ios', 'asa', 'comware'):
if args.type not in ('routeros', 'ios', 'nexus', 'asa', 'comware'):
raise ValueError(f'Invalid devtype: {args.type}')
if args.type == 'routeros':
cf = RouterosConfig(workdir=args.backupdir)
elif args.type == 'ios':
cf = IosConfig(workdir=args.backupdir)
elif args.type == 'nexus':
cf = NexusConfig(workdir=args.backupdir)
elif args.type == 'asa':
cf = AsaConfig(workdir=args.backupdir)
elif args.type == 'comware':

View File

@ -1,6 +1,6 @@
---
- name: set router configuration backup directory
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,hpcomware
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,cisconexus,hpcomware
gather_facts: no
tags: always
tasks:
@ -11,7 +11,7 @@
routerbackup_maxage: 24
- name: use router backup role
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,hpcomware
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,cisconexus,hpcomware
gather_facts: no
roles:
- routerbackup