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

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

Whitespaces in beginnings and ends are evil get rid of them

  • 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 Geo::Coordinates::RDNAP->import(qw/from_rd to_rd dms/);
8} else {
9 sub from_rd {
10 return (0,0,0);
11 }
12}
13
14# RD X,Y -> RD Noorderbreedte, Oosterbreedte
15# http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
16
17# Little perl to convert genesis files into python config files,
18# Which gonna be used for more logic stuff ;-)
19
20$argc = $#ARGV + 1;
21if ($argc == 0) {
22 print STDERR "Usage $_ <wleiden.conf> ...\n";
23 exit 1;
24# Hack to easy support multiple files without remembering any variable in between
25} elsif ($argc > 1) {
26 foreach $file (@ARGV) {
27 $output = $file;
28 $output =~ s/conf$/yaml/;
29 print `perl $ENV{_} $file > $output`;
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 =~ m/[0-9]/);
75
76 print <<EOF;
77iface_$iflabel:
78EOF
79 %tmp = (
80 'dhcp' => 'False',
81 'compass' => 'None',
82 'interface' => $if,
83 );
84 foreach $line (split('\n',$config{$if})) {
85 ($key, $value) = split(/=/,$line);
86 # Remove trailing and leading white spaces
87 $value =~ s/^\s+//;
88 $value =~ s/\s+$//;
89 if ($key and (lc($key) =~ /^[a-z].*/)) {
90 #print "$key : $value\n";
91 $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
92 if ($key =~ /^type$/i) {
93 if ($value eq 'ethernet') {
94 $value = 'eth';
95 } else {
96 $value = '11b';
97 }
98 } elsif ($key =~ /^mode$/i) {
99 if ($value eq 'master') {
100 $value = 'ap-wds';
101 } else { # managed
102 $value = 'station-wds';
103 }
104 } elsif ($key =~ /^polar$/i) {
105 if ($value eq 'hor') {
106 $value = 'hr';
107 } else {
108 $value = 'vr';
109 }
110 } elsif ($key =~ /^essid$/i) {
111 $key = 'ssid';
112
113 # Dirty hack to fetch compass direction of essid
114 $value =~ /[a-z]+-([a-z]+)\..*/;
115 $direction = $1;
116 # Translate into English
117 if ($direction ne "omni") {
118 $direction =~ tr/oz/es/;
119 }
120 # node AMwtrt1 and 'test' directions
121 if ($direction eq "wtrtr" or $direction eq "test") {
122 $direction = 'None';
123 }
124 $tmp{'compass'} = $direction;
125 } elsif ($key =~ /^gain$/i) {
126 $value =~ s/dbi//;
127 }
128 $tmp{lc($key)} = $value;
129 }
130 }
131# ethernet2wifi bridges
132 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
133 $tmp{type} = 'eth';
134 }
135# 11a
136 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
137 $tmp{type} = '11a';
138 }
139
140 foreach $key (sort keys %tmp) {
141 printf " %-11s: '$tmp{$key}'\n", $key;
142 }
143 print "\n";
144}
145
Note: See TracBrowser for help on using the repository browser.