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

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

Compass direction name got dodgy formatted (empty), causing syntax highlighting of vim to get confused for example.

  • Property svn:executable set to *
File size: 3.9 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 "# Processing $file\n";
30 `./genesis-to-yaml.pl $file > $output`;
31 }
32 exit 0;
33}
34
35
36do($ARGV[0]) || die;
37
38my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
39
40$interfaces = [];
41foreach $if (keys %config) {
42 push(@interfaces, $if) if ($if =~ m/^[a-z0-9]+$/g);
43}
44$interfaces = join(",",@interfaces);
45
46if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
47 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
48} else {
49 $lat = $lon = $h = 0;
50}
51
52$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
53$comment = $comment || 'None';
54
55print <<EOF;
56# Genesis config yaml style
57# vim:ts=2:et:sw=2:ai
58#
59comment : $comment
60interfaces: $interfaces
61latitude : $lat
62location : $location
63longitude : $lon
64masterip : $master_ip
65nodename : $nodename
66nodetype : $nodetype
67rdnap_x : $X
68rdnap_y : $Y
69status : $status
70EOF
71
72
73foreach $if (keys %config) {
74 ($iflabel, $alias) = split(':',$if);
75 $iflabel .= "_alias${alias}" if ($alias =~ m/[0-9]/);
76
77 print <<EOF;
78iface_$iflabel:
79EOF
80 %tmp = (
81 'dhcp' => 'False',
82 'compass' => 'None',
83 'interface' => $if,
84 );
85 foreach $line (split('\n',$config{$if})) {
86 ($key, $value) = split(/=/,$line);
87 # Remove trailing and leading white spaces
88 $value =~ s/^\s+//;
89 $value =~ s/\s+$//;
90 if ($key and (lc($key) =~ /^[a-z].*/)) {
91 #print "$key : $value\n";
92 $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
93 if ($key =~ /^type$/i) {
94 if ($value eq 'ethernet') {
95 $value = 'eth';
96 } else {
97 $value = '11b';
98 }
99 } elsif ($key =~ /^mode$/i) {
100 if ($value eq 'master') {
101 $value = 'ap-wds';
102 } else { # managed
103 $value = 'station-wds';
104 }
105 } elsif ($key =~ /^polar$/i) {
106 if ($value eq 'hor') {
107 $value = 'hr';
108 } else {
109 $value = 'vr';
110 }
111 } elsif ($key =~ /^essid$/i) {
112 $key = 'ssid';
113
114 # Dirty hack to fetch compass direction of essid
115 $value =~ /[a-z]+-([a-z]+)\..*/;
116 $direction = $1;
117 # Translate into English
118 if ($direction ne "omni") {
119 $direction =~ tr/oz/es/;
120 }
121 # node AMwtrt1 and 'test' directions
122 if ($direction eq "wtrtr" or $direction eq "test") {
123 $direction = 'None';
124 }
125 if ($direction) {
126 $tmp{'compass'} = $direction;
127 } else {
128 $tmp{'compass'} = 'None';
129 }
130 } elsif ($key =~ /^gain$/i) {
131 $value =~ s/dbi//;
132 }
133 $tmp{lc($key)} = $value;
134 }
135 }
136# ethernet2wifi bridges
137 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
138 $tmp{type} = 'eth';
139 }
140# 11a
141 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
142 $tmp{type} = '11a';
143 }
144
145 foreach $key (sort keys %tmp) {
146 printf " %-11s: '$tmp{$key}'\n", $key;
147 }
148 print "\n";
149}
150
Note: See TracBrowser for help on using the repository browser.