source: genesis/nodes/genesis-to-yaml.pl@ 8266

Last change on this file since 8266 was 8266, checked in by rick, 14 years ago

Convert genesis files to YAML

  • Property svn:executable set to *
File size: 3.7 KB
Line 
1#!/usr/bin/env perl
2
3eval {
4 require Geo::Coordinates::RDNAP;
5};
6if (! $@) {
7 print "Foo";
8 Geo::Coordinates::RDNAP->import(qw/from_rd to_rd dms/);
9} else {
10 print STDERR "[WARN] Geo::Coordinates::RDNAP not installed\n";
11 sub from_rd {
12 return (0,0,0);
13 }
14}
15
16# RD X,Y -> RD Noorderbreedte, Oosterbreedte
17# http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
18
19# Little perl to convert genesis files into python config files,
20# Which gonna be used for more logic stuff ;-)
21
22$argc = $#ARGV + 1;
23if ($argc == 0) {
24 print STDERR "Usage $_ <wleiden.conf> ...\n";
25 exit 1;
26# Hack to easy support multiple files without remembering any variable in between
27} elsif ($argc > 1) {
28 foreach $file (@ARGV) {
29 print `perl $ENV{_} $file`;
30 }
31 exit 0;
32}
33
34
35do($ARGV[0]) || die;
36
37my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
38
39$interfaces = [];
40foreach $if (keys %config) {
41 push(@interfaces, $if) if ($if =~ m/^[a-z0-9]+$/g);
42}
43$interfaces = join(",",@interfaces);
44
45if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
46 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
47} else {
48 $lat = $lon = $h = 0;
49}
50
51$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
52$comment = $comment || 'None';
53
54print <<EOF;
55# Genesis config yaml style
56# vim:ts=2:et:sw=2:ai
57#
58comment : $comment
59interfaces: $interfaces
60latitude : $lat
61location : $location
62longitude : $lon
63masterip : $master_ip
64nodename : $nodename
65nodetype : $nodetype
66rdnap_x : $X
67rdnap_y : $Y
68status : $status
69EOF
70
71
72foreach $if (keys %config) {
73 ($iflabel, $alias) = split(':',$if);
74 $iflabel .= "_alias${alias}" if ($alias);
75
76 print <<EOF;
77iface_$iflabel:
78EOF
79 %tmp = (
80 'configtype' => 'interface',
81 'dhcp' => 'False',
82 'compass_direction' => 'None',
83 'nodename' => $nodename,
84 'interface' => $if,
85 );
86 foreach $line (split('\n',$config{$if})) {
87 ($key, $value) = split(/=/,$line);
88 if ($key and (lc($key) =~ /^[a-z].*/)) {
89 #print "$key : $value\n";
90 $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
91 if ($key =~ /^type$/i) {
92 if ($value eq 'ethernet') {
93 $value = 'eth';
94 } else {
95 $value = '11b';
96 }
97 } elsif ($key =~ /^mode$/i) {
98 if ($value eq 'master') {
99 $value = 'ms';
100 } else { # managed
101 $value = 'mn';
102 }
103 } elsif ($key =~ /^polar$/i) {
104 if ($value eq 'hor') {
105 $value = 'hr';
106 } else {
107 $value = 'vr';
108 }
109 } elsif ($key =~ /^essid$/i) {
110 $key = 'ssid';
111
112 # Dirty hack to fetch compass direction of essid
113 $value =~ /[a-z]+-([a-z]+)\..*/;
114 $direction = $1;
115 # Translate into English
116 if ($direction ne "omni") {
117 $direction =~ tr/oz/es/;
118 }
119 # node AMwtrt1 and 'test' directions
120 if ($direction eq "wtrtr" or $direction eq "test") {
121 $direction = 'None';
122 }
123 $tmp{'compass_direction'} = $direction;
124 } elsif ($key =~ /^gain$/i) {
125 $value =~ s/dbi//;
126 }
127 $tmp{lc($key)} = $value;
128 }
129 }
130# ethernet2wifi bridges
131 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
132 $tmp{type} = '11b';
133 }
134# 11a
135 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
136 $tmp{type} = '11a';
137 }
138
139 foreach $key (sort keys %tmp) {
140 printf " %-11s: $tmp{$key}\n", $key;
141 }
142 print "\n";
143}
144
Note: See TracBrowser for help on using the repository browser.