source: genesis/tools/genesis-to-yaml.pl@ 10032

Last change on this file since 10032 was 9287, checked in by richardvm, 14 years ago

Make obsolute reference instead of fixed reference. Checkout path genesis is fixed.

  • Property svn:executable set to *
File size: 4.6 KB
RevLine 
[8266]1#!/usr/bin/env perl
[8621]2use File::Basename;
[9095]3use Module::Load::Conditional qw[check_install];
[8266]4
[9095]5if (check_install(module => 'Geo::Coordinates::RDNAP')) {
[8266]6 require Geo::Coordinates::RDNAP;
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) {
[8870]22 print STDERR "Usage $ENV{_} <wleiden.conf> ...\n";
[9287]23 $NODE_DIR = dirname(__FILE__) . "/../nodes";
24 @ARGV=`ls $NODE_DIR/*/wleiden.conf`;
[8870]25}
26
27if ($argc != 1) {
28 # Hack to easy support multiple files without remembering any variable in between
[8266]29 foreach $file (@ARGV) {
[8870]30 chomp($file);
[8294]31 $output = $file;
32 $output =~ s/conf$/yaml/;
[8870]33 print "# Processing $file -> $output\n";
[8621]34 $CMD=dirname(__FILE__) . "/genesis-to-yaml.pl";
35 `$CMD $file > $output`;
[8266]36 }
37 exit 0;
38}
39
40
41do($ARGV[0]) || die;
42
43my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
44
45$interfaces = [];
46foreach $if (keys %config) {
47 push(@interfaces, $if) if ($if =~ m/^[a-z0-9]+$/g);
48}
49$interfaces = join(",",@interfaces);
50
51if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
52 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
53} else {
54 $lat = $lon = $h = 0;
55}
56
57$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
58$comment = $comment || 'None';
59
60print <<EOF;
61# Genesis config yaml style
62# vim:ts=2:et:sw=2:ai
63#
64comment : $comment
65interfaces: $interfaces
66latitude : $lat
[8871]67location : '$location'
[8266]68longitude : $lon
69masterip : $master_ip
[8644]70release : $release
[8266]71nodename : $nodename
72nodetype : $nodetype
73rdnap_x : $X
74rdnap_y : $Y
75status : $status
76EOF
77
[8644]78if ($ileiden =~ /yes/) {
79 print "ileiden : yes\n";
80} else {
81 print "ileiden : no\n";
82}
[8266]83
84foreach $if (keys %config) {
85 ($iflabel, $alias) = split(':',$if);
[8270]86 $iflabel .= "_alias${alias}" if ($alias =~ m/[0-9]/);
[8266]87
88 print <<EOF;
89iface_$iflabel:
90EOF
91 %tmp = (
92 'dhcp' => 'False',
[8273]93 'compass' => 'None',
[8266]94 'interface' => $if,
95 );
96 foreach $line (split('\n',$config{$if})) {
97 ($key, $value) = split(/=/,$line);
[8300]98 # Remove trailing and leading white spaces
99 $value =~ s/^\s+//;
100 $value =~ s/\s+$//;
[8266]101 if ($key and (lc($key) =~ /^[a-z].*/)) {
102 #print "$key : $value\n";
103 $value = lc($value) if not lc($key) =~ m/(desc|comment)/;
104 if ($key =~ /^type$/i) {
105 if ($value eq 'ethernet') {
106 $value = 'eth';
107 } else {
108 $value = '11b';
109 }
[8644]110 } elsif ($key =~ /^status$/i) {
111 if ($value eq 'up') {
112 $value = 'up';
113 } else {
114 $value = 'down';
115 }
[8266]116 } elsif ($key =~ /^mode$/i) {
117 if ($value eq 'master') {
[8273]118 $value = 'ap-wds';
[8266]119 } else { # managed
[8273]120 $value = 'station-wds';
[8266]121 }
122 } elsif ($key =~ /^polar$/i) {
123 if ($value eq 'hor') {
124 $value = 'hr';
125 } else {
126 $value = 'vr';
127 }
128 } elsif ($key =~ /^essid$/i) {
129 $key = 'ssid';
130
131 # Dirty hack to fetch compass direction of essid
132 $value =~ /[a-z]+-([a-z]+)\..*/;
133 $direction = $1;
134 # Translate into English
135 if ($direction ne "omni") {
136 $direction =~ tr/oz/es/;
137 }
138 # node AMwtrt1 and 'test' directions
139 if ($direction eq "wtrtr" or $direction eq "test") {
140 $direction = 'None';
141 }
[8586]142 if ($direction) {
143 $tmp{'compass'} = $direction;
144 } else {
145 $tmp{'compass'} = 'None';
146 }
[8266]147 } elsif ($key =~ /^gain$/i) {
148 $value =~ s/dbi//;
149 }
[8644]150 # Als key niet bestaat, Dan key toevoegen
[8266]151 $tmp{lc($key)} = $value;
152 }
153 }
[8644]154# Status
155 if ( ! $tmp{status} ) {
156 $tmp{status} = 'up';
157 }
[8266]158# ethernet2wifi bridges
159 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
[8273]160 $tmp{type} = 'eth';
[8266]161 }
162# 11a
163 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
164 $tmp{type} = '11a';
165 }
166
167 foreach $key (sort keys %tmp) {
[8270]168 printf " %-11s: '$tmp{$key}'\n", $key;
[8266]169 }
170 print "\n";
171}
172
Note: See TracBrowser for help on using the repository browser.