Last active
July 12, 2018 21:24
-
-
Save robinkunde/691384f6b77a93c4b03454519771d0d5 to your computer and use it in GitHub Desktop.
Use this script to generate `configure` commands for static DHCP IP address assignment on EdgeRouter X
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import os | |
import csv | |
usage = '''Use this script to generate configure commands. | |
Expected input csv format: identifier,identifier_suffix(optional),ignored,mac-address-with-dashes,ip4-address | |
First line is ignored. | |
Any line that is missing required fields is ignored. | |
Assumes 192.168.1.0/24 subnet. | |
Steps: | |
1. Send output file to Edgerouter using scp | |
2. SSH to Edgerouter | |
3. Switch to root if needed | |
4. $ configure | |
5. $ source output-file | |
6. $ exit | |
''' | |
parser = argparse.ArgumentParser(description=usage, formatter_class=argparse.RawDescriptionHelpFormatter) | |
parser.add_argument('path') | |
args = parser.parse_args() | |
print("edit service dhcp-server shared-network-name LAN subnet 192.168.1.0/24") | |
print("delete static-mapping") | |
with open(args.path, 'r') as csvfile: | |
reader = csv.reader(csvfile) | |
next(reader, None) # skip the headers | |
for row in reader: | |
row = [c.strip() for c in row] | |
if not row[0]: continue | |
if not row[2]: continue | |
if not row[4]: continue | |
identifier = f"{row[0].lower()}" | |
if row[1]: | |
identifier += f"_{row[1].lower().replace(' ', '_')}" | |
print(f"set static-mapping {identifier} mac-address {row[2].upper()}") | |
print(f"set static-mapping {identifier} ip-address {row[4]}") | |
print("commit") | |
print("save") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment