cisco nexus
This commit is contained in:
parent
c99e790fc8
commit
08a0666929
@ -5,6 +5,7 @@
|
|||||||
{% if 'routeros' in group_names %}routeros
|
{% if 'routeros' in group_names %}routeros
|
||||||
{% elif 'ciscoasa' in group_names %}asa
|
{% elif 'ciscoasa' in group_names %}asa
|
||||||
{% elif 'ciscoios' in group_names %}ios
|
{% elif 'ciscoios' in group_names %}ios
|
||||||
|
{% elif 'cisconexus' in group_names %}nexus
|
||||||
{% elif 'hpcomware' in group_names %}comware
|
{% elif 'hpcomware' in group_names %}comware
|
||||||
{% else %}undefined
|
{% else %}undefined
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
47
routerbackup
47
routerbackup
@ -13,12 +13,12 @@ import difflib
|
|||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
parser = argparse.ArgumentParser(
|
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',
|
parser.add_argument('-t', '--type',
|
||||||
required=True,
|
required=True,
|
||||||
action='store',
|
action='store',
|
||||||
help='device type {routeros,ios,asa}')
|
help='device type {routeros,ios,nexus,asa}')
|
||||||
parser.add_argument('-H', '--host',
|
parser.add_argument('-H', '--host',
|
||||||
required=True,
|
required=True,
|
||||||
action='store',
|
action='store',
|
||||||
@ -349,6 +349,45 @@ class IosConfig(Config):
|
|||||||
return prepared
|
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):
|
class ConfigWithShell(Config):
|
||||||
def _shell_command(self, channel, cmd,
|
def _shell_command(self, channel, cmd,
|
||||||
waitfor=None,
|
waitfor=None,
|
||||||
@ -461,13 +500,15 @@ def main():
|
|||||||
args = get_args()
|
args = get_args()
|
||||||
setup_logging(args.host, args.logfile, args.loglevel)
|
setup_logging(args.host, args.logfile, args.loglevel)
|
||||||
try:
|
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}')
|
raise ValueError(f'Invalid devtype: {args.type}')
|
||||||
|
|
||||||
if args.type == 'routeros':
|
if args.type == 'routeros':
|
||||||
cf = RouterosConfig(workdir=args.backupdir)
|
cf = RouterosConfig(workdir=args.backupdir)
|
||||||
elif args.type == 'ios':
|
elif args.type == 'ios':
|
||||||
cf = IosConfig(workdir=args.backupdir)
|
cf = IosConfig(workdir=args.backupdir)
|
||||||
|
elif args.type == 'nexus':
|
||||||
|
cf = NexusConfig(workdir=args.backupdir)
|
||||||
elif args.type == 'asa':
|
elif args.type == 'asa':
|
||||||
cf = AsaConfig(workdir=args.backupdir)
|
cf = AsaConfig(workdir=args.backupdir)
|
||||||
elif args.type == 'comware':
|
elif args.type == 'comware':
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: set router configuration backup directory
|
- name: set router configuration backup directory
|
||||||
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,hpcomware
|
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,cisconexus,hpcomware
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
tags: always
|
tags: always
|
||||||
tasks:
|
tasks:
|
||||||
@ -11,7 +11,7 @@
|
|||||||
routerbackup_maxage: 24
|
routerbackup_maxage: 24
|
||||||
|
|
||||||
- name: use router backup role
|
- name: use router backup role
|
||||||
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,hpcomware
|
hosts: routeros,ciscoasa,!ciscoasa_slave,ciscoios,cisconexus,hpcomware
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
roles:
|
roles:
|
||||||
- routerbackup
|
- routerbackup
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user