aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@frank.tg14.gathering.org>2014-04-17 18:55:20 +0200
committerroot <root@frank.tg14.gathering.org>2014-04-17 18:55:20 +0200
commit80977a88fde6f849f68c5864f18fe61a4b2dae64 (patch)
tree9b75bc2aeb7f0a52b1961d660dc5517e7e8be827
parent2ba6a83e9a7a4b3ae0def6a287bbb2d443538f41 (diff)
Add a little script to make switches flat on the placement.
-rwxr-xr-xclients/flatify.pl21
-rw-r--r--clients/update-switch-placements.pl53
2 files changed, 21 insertions, 53 deletions
diff --git a/clients/flatify.pl b/clients/flatify.pl
new file mode 100755
index 0000000..f2aa18a
--- /dev/null
+++ b/clients/flatify.pl
@@ -0,0 +1,21 @@
+#! /usr/bin/perl
+
+# Make the given switch into a D-Link placement-wise.
+
+use strict;
+use warnings;
+use lib '../include';
+use nms;
+
+my $dbh = nms::db_connect();
+my $q = $dbh->prepare('SELECT switch,placement FROM switches NATURAL JOIN placements WHERE sysname LIKE ?');
+$q->execute('%'.$ARGV[0].'%');
+
+while (my $ref = $q->fetchrow_hashref) {
+ $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/ or die;
+ my ($x1,$y1,$x2,$y2) = ($1, $2, $3, $4);
+ my $placement = sprintf "(%d,%d),(%d,%d)", $x2 - 100, $y2 - 16, $x2, $y2;
+ $dbh->do("UPDATE placements SET placement=? WHERE switch=?",
+ undef, $placement, $ref->{'switch'});
+ last; # Take only one.
+}
diff --git a/clients/update-switch-placements.pl b/clients/update-switch-placements.pl
deleted file mode 100644
index d635f87..0000000
--- a/clients/update-switch-placements.pl
+++ /dev/null
@@ -1,53 +0,0 @@
-#! /usr/bin/perl
-
-print "begin;\n";
-print "delete from placements;\n";
-
-open PATCHLIST, "../patchlist.txt"
- or die "../patchlist.txt: $!";
-
-my $RANGE = "87.76.";
-
-my $i = 1;
-while (<PATCHLIST>) {
- chomp;
- my ($name, $distro, $port) = split / /;
-
- $name =~ /e(\d+)-(\d+)/;
- my ($e, $s) = ($1, $2);
-
- my $x = int(168 + $e * 11);
- my $y;
-
- $x += 1 if ($e >= 11);
- $x += 2 if ($e >= 15);
- $x += 2 if ($e >= 15 && $e < 45 && $s > 2);
- $x += 2 if ($e >= 21);
- $x += 2 if ($e >= 27 && $e < 45 && $s > 2);
- $x += 9 if ($e >= 29);
- $x += 1 if ($e >= 31);
- $x += 2 if ($e >= 35);
- $x += 15 if ($e >= 45);
- $x += 2 if ($e >= 51);
- $x += 11 if ($e >= 61);
- $x += 1 if ($e >= 67);
- $x += 1 if ($e >= 71);
- $x += 1 if ($e >= 75);
- $x += 1 if ($e >= 81);
-
- if ($s > 2) {
- $y = 152 + 88 - 88 * ($s-3);
- } else {
- $y = 357 + 88 - 88 * ($s-1);
- }
-
- my $xx = $x + 16;
- my $yy = $y + 88;
-
- # Justeringer
-
- print "insert into placements (switch, placement) values ($i, box '(($x,$y),($xx,$yy))');\n";
- $i++;
-}
-
-print "end;\n";