Verified Commit 81a93df9 authored by Jenny's avatar Jenny
Browse files

added configure_switch for 54xx switches

parent 54a769f4
#!/usr/bin/env python3
import argparse
import os
import sys
start = """
#!/usr/bin/expect -f
set timeout 10
spawn telnet {switch_ip}
expect "Press any key to continue"
send "\\r"
expect "#"
send "configure\\r"
expect "(config)"
send "snmp-server host {server_ip} community {snmp_community} trap-level all\\r"
"""
end = """
expect "(config)"
send "write memory \\r"
expect "(config)"
send "logout \\r"
expect "Do you want to log out"
send "y\\r"
"""
def main():
parser = argparse.ArgumentParser(description='Configure a SWV-Switch (Version for 54XX Switches)')
parser.add_argument('switch_ip', type=str, help='IP of the Switch')
parser.add_argument('server_ip', type=str, help='IP of the SNMP-Server')
parser.add_argument('snmp_community', type=str, help='SNMP-Community-String')
args = parser.parse_args()
content = start + "\n"
ctr = 1200
for i in ('A', 'C', 'E'):
for j in range(1, 25):
content += 'expect "(config)"\n'
content += 'send "vlan ' + str(ctr) + ' untagged ' + i + str(j) + '\\r"\n'
ctr = ctr + 1
content += end
content = content.format(
switch_ip=args.switch_ip,
server_ip=args.server_ip,
snmp_community=args.snmp_community
)
outfile = open("/tmp/switchconfig.expect", "w")
outfile.write(content)
outfile.close()
os.system("expect -f /tmp/switchconfig.expect")
if __name__ == '__main__':
sys.exit(main())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment