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

Last change on this file since 8493 was 8342, checked in by rick, 14 years ago
  • genesis-to-yaml.pl wildcard hack
  • merge does not need to have initial file
  • Property svn:executable set to *
File size: 3.8 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 $tmp{'compass'} = $direction;
126 } elsif ($key =~ /^gain$/i) {
127 $value =~ s/dbi//;
128 }
129 $tmp{lc($key)} = $value;
130 }
131 }
132# ethernet2wifi bridges
133 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
134 $tmp{type} = 'eth';
135 }
136# 11a
137 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
138 $tmp{type} = '11a';
139 }
140
141 foreach $key (sort keys %tmp) {
142 printf " %-11s: '$tmp{$key}'\n", $key;
143 }
144 print "\n";
145}
146
Note: See TracBrowser for help on using the repository browser.