dump all other peaces in, first configuration which can again boot
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 29 Jul 2009 22:04:58 +0000 (22:04 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 29 Jul 2009 22:04:58 +0000 (22:04 +0000)
(wrong image, that is :-)

12 files changed:
bin/kvm-vde.sh
bin/start-split.sh
lib/PXElator/boolean.pm
lib/PXElator/dhcpd.pm
lib/PXElator/html.pm
lib/PXElator/httpd.pm
lib/PXElator/pxe.pm [new file with mode: 0644]
lib/PXElator/server.pm
lib/PXElator/t/dhcpd.t [new file with mode: 0755]
lib/PXElator/t/pxe.t [new file with mode: 0755]
lib/PXElator/t/tftpd.t [new file with mode: 0755]
lib/PXElator/tftpd.pm [new file with mode: 0644]

index cb6da07..c686a97 100755 (executable)
@@ -18,6 +18,10 @@ fi
 sudo ifup tap0
 rm conf/server.ip ; ln -sf 172.16.10.1 conf/server.ip
 
+./bin/start-split.sh &
+
+#sudo tshark -i tap0 &
+
 vdeq kvm -m 512 -net nic,vlan=1,macaddr=52:54:00:12:01:00 \
        -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl \
        -boot n
index 0d28ca7..4183cba 100755 (executable)
@@ -14,11 +14,11 @@ startup_message off
 sessionname PXElator
 
 split
-screen -t dhcpd sudo ./bin/dhcpd.pl
+screen -t dhcpd sudo perl -Ilib/PXElator -Ilib -Mdhcpd -e start
 logfile /tmp/pxelator.dhcpd.log
 log on
 focus down
-screen -t tftpd sudo ./bin/tftpd.pl
+screen -t tftpd sudo perl -Ilib/PXElator -Ilib -Mtftpd -e tftpd::start
 logfile /tmp/pxelator.tftp.log
 log on
 
@@ -26,4 +26,4 @@ ____
 
 screen="screen -R PXElator -c /tmp/screenrc"
 
-test ! -z "$DISPLAY" && xterm -e $screen || $screen
+test ! -z "$DISPLAY" && xterm -e $screen
index 60f6b68..e2fcf8e 100644 (file)
@@ -5,4 +5,6 @@ sub toggle {
        return $v ? 0 : 1;
 }
 
+warn "loaded";
+
 1;
index 4b8bd0c..c857f81 100755 (executable)
@@ -26,21 +26,19 @@ use Net::DHCP::Packet;
 use Net::DHCP::Constants 0.67;
 
 use server;
+use pxe;
 
 my $debug = 1;
 
-our ( $file, $gpxe_file );
-our ( $ip_from, $ip_to ) = ( 10, 100 );
-
 if ( ! $server::ip ) {
        my $server_ip = `/sbin/ifconfig`;
        $server_ip =~ s/^.+?addr:([\d\.]+).*$/$1/gs;
        $server::ip = $server_ip;
 }
 
-warn "server ip $server::ip\n";
+warn "server ip $server::ip file: $pxe::file range: $server::ip_from - $server::ip_to\n";
 
-my $addr = $ip_from;
+my $addr = $server::ip_from;
 
 sub client_ip {
        my ( $mac ) = @_;
@@ -63,7 +61,7 @@ sub client_ip {
        my $ip = $prefix . $addr;
        while ( -e "conf/ip/$ip" || $p->ping( $ip ) ) {
                $ip = $prefix . $addr++;
-               die "all addresses allocated!" if $addr == $ip_to;
+               die "all addresses allocated!" if $addr == $server::ip_to;
        }
 
        write_file "$conf/mac/$mac", $ip;
@@ -121,7 +119,7 @@ sub process_packet {
                Siaddr  => $server::ip,
                Giaddr  => $dhcp->giaddr(),
                Chaddr  => $dhcp->chaddr(),
-               File    => $file,
+               File    => $pxe::file,
        };
 
        my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
@@ -152,7 +150,7 @@ sub process_packet {
                warn "$messagetype igored (bootp?)";
        }
 
-       warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n";
+       warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n";
 
        $packet = new Net::DHCP::Packet( %$packet );
        warn "## ",$packet->toString(),"\n" if $debug;
@@ -196,4 +194,6 @@ sub start {
        }
 }
 
+warn "loaded";
+
 1;
index 0578060..7c37ae5 100644 (file)
@@ -11,4 +11,6 @@ sub table {
        $html .= qq{</tr>\n</table>};
 }
 
+warn "loaded";
+
 1;
index a203176..4741657 100644 (file)
@@ -137,4 +137,6 @@ sub start {
        die "server died";
 }
 
+warn "loaded";
+
 1;
diff --git a/lib/PXElator/pxe.pm b/lib/PXElator/pxe.pm
new file mode 100644 (file)
index 0000000..4a7be53
--- /dev/null
@@ -0,0 +1,35 @@
+package pxe;
+
+use warnings;
+use strict;
+
+use File::Slurp;
+
+use server;
+use tftpd;
+
+our $file = 'gpxelinux.0';
+my $path = "$tftpd::dir/$file";
+symlink '/usr/lib/syslinux/gpxelinux.0', $path unless -l $path;
+warn "file $path ", -s $path;
+
+my $url = "http://$server::ip/pxelator/debian-live/";
+my $squash = tftpd::path('debian-live/*squashfs');
+
+
+my $config = "$ftpd::dir/pxelinux.cfg/default";
+
+write_file $config, qq{
+
+default linux
+label linux
+       kernel $url/vmlinuz1
+       append initrd=$url/initrd1.img boot=live union=aufs noswap noprompt vga=normal fetch=$url/$squash
+
+};
+
+warn "config $config ", -s $config;
+
+warn "loaded";
+
+1;
index 4dad1a8..a8ba059 100644 (file)
@@ -2,3 +2,6 @@ package server;
 
 our $ip = '172.16.10.1';
 
+our ( $ip_from, $ip_to ) = ( 10, 100 );
+
+warn "loaded";
diff --git a/lib/PXElator/t/dhcpd.t b/lib/PXElator/t/dhcpd.t
new file mode 100755 (executable)
index 0000000..f769009
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'dhcpd';
+
+ok( ! $dhcpd::transaction, 'transaction' );
diff --git a/lib/PXElator/t/pxe.t b/lib/PXElator/t/pxe.t
new file mode 100755 (executable)
index 0000000..a691051
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'pxe';
+
+ok( my $file = $pxe::file, 'file' );
+diag $file;
diff --git a/lib/PXElator/t/tftpd.t b/lib/PXElator/t/tftpd.t
new file mode 100755 (executable)
index 0000000..bcc54f6
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'tftpd';
+
+ok( my $path = tftpd::path('*'), 'path' );
+diag $path;
diff --git a/lib/PXElator/tftpd.pm b/lib/PXElator/tftpd.pm
new file mode 100644 (file)
index 0000000..4f58b18
--- /dev/null
@@ -0,0 +1,93 @@
+package tftpd;
+
+use warnings;
+use strict;
+
+use Net::TFTPd 0.03 qw(%OPCODES);
+use Data::Dump qw/dump/;
+
+our $dir  = '/home/dpavlin/llin/pxelator/tftp';
+
+sub path {
+       my $glob = shift;
+       my $path = glob("$dir/$glob");
+       die "can't find anything for $dir/$glob" unless $path;
+warn $path;
+       $path =~ s{^$dir}{};
+       return $path;
+}
+
+sub transfer_status {
+       my $req = shift;
+       if( $req->{'_REQUEST_'}{'OPCODE'} eq $OPCODES{'RRQ'} ) {
+               printf "RRQ %u\/%u\r", $req->{'_REQUEST_'}{'LASTACK'}, $req->{'_REQUEST_'}{'LASTBLK'};
+       } elsif ( $req->{'_REQUEST_'}{'OPCODE'} eq $OPCODES{'WRQ'} ) {
+               die "WRQ disabled";
+               printf "WRQ: %u\/%u\n", $req->{'_REQUEST_'}{'LASTBLK'}, $req->{'_REQUEST_'}{'LASTACK'};
+       } else {
+               warn "IGNORED: ", dump( $req );
+       }
+}
+
+sub tftp_request {
+       my $request = shift;
+
+       if ( $request->{RootDir} ne $dir ) {
+               $request->{RootDir} = $dir;
+               warn "new root: $dir";
+       }
+
+       # received request
+       printf "Received a %s for file '%s'\n", $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, $request->{'_REQUEST_'}{'FileName'};
+
+       # process the request
+       if( $request->processRQ() ) {
+               print "OK, transfer completed successfully\n";
+       } else {
+               warn Net::TFTPd->error;
+               $request->processRQ();
+       }
+
+}
+
+use server;
+
+sub start {
+
+       warn 'start';
+
+       my $listener = Net::TFTPd->new(
+               RootDir => $dir,
+               Writable => 0,
+               Timeout => 3600, 
+               CallBack => \&transfer_status,
+#              LocalAddr => $server::ip,
+#              BlkSize => 8192,
+#              BlkSize => 512,
+               BlkSize => 1456,        # IBM GE seems to be picky
+               Debug => 99,
+       ) || die Net::TFTPd->error;
+
+       warn 'listener: ',dump( $listener );
+
+       while(1) {
+       
+               printf "TFTP listen %s:%d timeout: %d dir: $dir\n",
+                       $listener->{LocalAddr},
+                       $listener->{LocalPort},
+                       $listener->{Timeout};
+
+               # wait for any request (RRQ or WRQ)
+               if(my $request = $listener->waitRQ()) {
+                       tftp_request $request;
+               } else {
+                       warn Net::TFTPd->error;
+               }
+
+       }
+
+}
+
+warn "loaded";
+
+1;