aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2016-02-26 11:29:20 +0100
committerKristian Lyngstol <kristian@bohemians.org>2016-02-26 11:29:20 +0100
commite6fd0035555499fa186845f4c69b715e9ad246b9 (patch)
tree947cf37c74731490de28d7ef02d09d5db63db125 /tools
parent9da864a8da29082369cdd2dd91a735b03577a117 (diff)
More cleanup and adding add_switches.txt.pl
add_switches.txt.pl is not quite done yet
Diffstat (limited to 'tools')
-rwxr-xr-xtools/add_switches.txt.pl (renamed from tools/make-switch-placements.pl)70
-rwxr-xr-xtools/make-dummy-placement.sh12
2 files changed, 50 insertions, 32 deletions
diff --git a/tools/make-switch-placements.pl b/tools/add_switches.txt.pl
index efacfcc..c3def24 100755
--- a/tools/make-switch-placements.pl
+++ b/tools/add_switches.txt.pl
@@ -1,27 +1,29 @@
-#! /usr/bin/perl
+#!/usr/bin/perl
+# Usage: ./add_switches.txt.pl < switches.txt > switches.json
+#
+# Parses switches.txt into json and does some guesswork for placement based
+# on name, if possible.
+#
+# Actually adding them comes later.
+#
+
use strict;
use warnings;
+use Data::Dumper;
-my $switchtype = "ex2200";
-
-print "begin;\n";
-print "delete from placements where switch in (select switch from switches where switchtype = '$switchtype' and (sysname like 'e%') or sysname like '%creativia%');\n";
-
-my %ip;
-my $i = 1;
-while (<STDIN>) {
- chomp;
- my @info = split(/ /);
+my %switches = ();
- if (scalar @info < 5) {
- die "Unknown line: $_";
- }
+# Guesses placement from name to get a starting point
+# Largely courtesy of Knuta
+sub guess_placement {
my ($x, $y, $xx, $yy);
- my $name = $info[0];
+ my $name = $_[0];
+ my $src = "unknown";
if ($name =~ /^e\d+-\d+$/) {
$name =~ /e(\d+)-(\d+)/;
my ($e, $s) = ($1, $2);
+ $src = "main";
$x = int(232 + (($e-1)/2) * 31.1);
$y = undef;
@@ -52,6 +54,7 @@ while (<STDIN>) {
#$yy -= 56 if $name eq "e83-1";
} elsif ($name =~ /^sw(\d+)-creativia$/) {
my ($s) = ($1);
+ $src = "creativia";
$x = 1535;
$y = int(130 + 32.2 * $s);
$yy = $y + 20;
@@ -67,6 +70,7 @@ while (<STDIN>) {
} elsif ($name =~ /^crew(\d+)-(\d+)$/) {
my ($s, $n) = ($1, $2);
+ $src = "crew";
$x = 1023 + 45 * $n;
$y = int(329 + 20.5 * $s);
$xx = $x + 45;
@@ -76,11 +80,37 @@ while (<STDIN>) {
$xx += 25;
}
} else {
- next;
- }
+ # Fallback to have _some_ position
+ $src = "random";
+ $x = int(rand(500));
+ $y = int(rand(500));
+ $xx = $x + 20;
+ $yy = $y + 130;
+ };
- print "insert into placements select switch, box '(($x,$y),($xx,$yy))' from switches where sysname = '$name';\n";
- $i++;
+
+ my %box = (
+ 'src' => "$src",
+ 'x1' => $x,
+ 'y1' => $y,
+ 'xx' => $xx,
+ 'yy' => $yy
+ );
+ return %box;
+}
+while (<STDIN>) {
+ chomp;
+ my ($switch, $subnet4, $subnet6, $mgtmt4, $mgtmt6, $lolid, $distro) = split(/ /);
+ my %foo = guess_placement($switch);
+ $switches{$switch} = {
+ 'subnet4' => "$subnet4",
+ 'subnet6' => "$subnet6",
+ 'mgtmt4' => "$mgtmt4",
+ 'mgtmt6' => "$mgtmt6",
+ 'lolid' => "$lolid",
+ 'distro' => "$distro"
+ };
+ $switches{$switch}{'placement_guess'} = \%foo;
}
-print "end;\n";
+print Dumper(\%switches);
diff --git a/tools/make-dummy-placement.sh b/tools/make-dummy-placement.sh
deleted file mode 100755
index 192e3d3..0000000
--- a/tools/make-dummy-placement.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-# Generate a random placement-entry insert for a named switch (convenient
-# if you manually add a switch with no placement)
-
-for a in $* ; do
-X=$(( $RANDOM % 500 ))
-Y=$(( $RANDOM % 500 ))
-X1=$(( $X + 20 ))
-Y1=$(( $Y + 130 ))
-echo "insert into placements select switch, box '(($X,$Y),($X1,$Y1))' from switches where sysname = '$a';"
-done