aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cables.py22
-rw-r--r--main.py27
-rw-r--r--switches.py4
3 files changed, 45 insertions, 8 deletions
diff --git a/cables.py b/cables.py
index 9226d88..a7ff5de 100644
--- a/cables.py
+++ b/cables.py
@@ -65,7 +65,23 @@ def write_csv(data, outfile="cable_labels.csv", split_per_num=100):
len(split_data), outfile.replace(".", "-1.")))
-def make_cable_labels(switches, uplinks=3):
+def read_aps_file(path):
+ aps = []
+ with open(path, "r") as f:
+ aps = [line.replace("\n", "").strip() for line in f.readlines()]
+
+ return aps
+
+
+def make_cable_labels(switches, ap_file=None, aps=[], copies=2, outfile="cable_labels.csv", split_per_num=100, uplinks=3):
print("Generating labels for cables")
- labels = generate_labels(switches, uplinks=uplinks, aps=[])
- write_csv(labels)
+
+ list_of_aps = aps
+ if ap_file:
+ list_of_aps.extend(read_aps_file(ap_file))
+
+ if len(list_of_aps):
+ print("Generating labels for {} APs".format(len(list_of_aps)))
+
+ labels = generate_labels(switches, copies=copies, uplinks=uplinks, aps=aps)
+ write_csv(labels, outfile=outfile, split_per_num=split_per_num)
diff --git a/main.py b/main.py
index 90a0eb8..b4f7c53 100644
--- a/main.py
+++ b/main.py
@@ -5,7 +5,9 @@ from cables import make_cable_labels
from gondul import fetch_gondul_switches
from switches import make_switch_labels
-parser = argparse.ArgumentParser("Label generator script 2000")
+parser = argparse.ArgumentParser(
+ "Label generator script 2000",
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("labler", type=str,
help="The label function to run. Either [c]ables or [s]witches.")
parser.add_argument("--gondul-user", type=str,
@@ -18,6 +20,20 @@ parser.add_argument("--gondul-switches", type=str,
help="Gondul switches endpoint. Overrides env GONDUL_SWITCHES_ENDPOINT")
parser.add_argument("--match-switches", type=str, default="^e(.*)",
help="Regex for matching switches")
+parser.add_argument("--outfile", "-o", type=str, default="cable_labels.csv",
+ help="Output (base) file name. Might be appended with numbers for cables.")
+
+cables_args = parser.add_argument_group("cables")
+cables_args.add_argument("--ap", type=str, action="append",
+ help="Name of a switch where an AP should be connected")
+cables_args.add_argument("--aps-file", type=str,
+ help="Path to a newline-separated file with switches where an AP should be connected")
+cables_args.add_argument("--copies", "-c", type=int, default=2,
+ help="Number of copies per label")
+cables_args.add_argument("--uplinks", "-u", type=int, default=3,
+ help="Number of uplinks per switch")
+cables_args.add_argument("--split", "-s", type=int, default=100,
+ help="Split into CSV files of this size")
if __name__ == "__main__":
args = parser.parse_args()
@@ -31,9 +47,14 @@ if __name__ == "__main__":
)
if args.labler[0] == "c":
- make_cable_labels(switches)
+ make_cable_labels(switches,
+ aps=args.ap,
+ ap_file=args.aps_file,
+ copies=args.copies,
+ outfile=args.outfile,
+ split_per_num=args.split)
elif args.labler[0] == "s":
- make_switch_labels(switches)
+ make_switch_labels(switches, outfile=args.outfile)
else:
parser.print_help()
sys.exit("Invalid labler operation.")
diff --git a/switches.py b/switches.py
index ab444c6..a218489 100644
--- a/switches.py
+++ b/switches.py
@@ -37,7 +37,7 @@ def write_html_to_file(html, outfile="switch_labels.html"):
print("Wrote labels to '{}'.\nOpen the file in your browser and print it.".format(outfile))
-def make_switch_labels(switches):
+def make_switch_labels(switches, outfile="switch_labels.html"):
print("Generating labels for switches")
labels = generate_labels(switches)
- write_html_to_file(labels)
+ write_html_to_file(labels, outfile=outfile)