/[pxelator]/lib/PXElator/kvm.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/kvm.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 67 by dpavlin, Thu Jul 30 21:31:30 2009 UTC revision 170 by dpavlin, Thu Aug 6 22:11:02 2009 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5  use autodie;  use autodie;
6    
 use File::Slurp;  
   
7  use server;  use server;
8    
9  our $debug = server::debug;  use Data::Dump qw/dump/;
10    
11  my $interfaces = read_file '/etc/network/interfaces';  our $memory_size = 512;
12    
13  if ( $interfaces !~ m{tap0.*$server::ip}s ) {  # AC = private, AD = multicast, AE = local
14    
15          system "sudo apt-get install vde2";  our $nr = 0;
16    
17          $interfaces .= qq{  sub port {
18            my $del = shift;
19            my $port = 10000 + $nr;
20            return join( $del, $server::ip, $port );
21    }
22    
23  iface tap0 inet static  sub start_fork { qw/monitor wireshark/ }
   address $server::ip  
   netmask $server::netmask  
   vde2-switch -  
24    
25          };  use x11;
26    
27          write_file '/etc/network/interfaces', $interfaces;  sub monitor {
28            x11::xterm( "monitor $nr" => 'nc ' . port(' ') );
29    }
30    
31    sub wireshark {
32            exec "wireshark -k -i tap0";
33  }  }
34    
35  if ( grep /tap0/, read_file '/proc/net/dev' ) {  sub actions { qw/reset activate/ }
36          warn "tap0 started";  
37  } else {  sub reset {
38          system "sudo ifup tap0";          my $sock = IO::Socket::INET->new( port(':') );
39            print $sock "system_reset\n";
40            close $sock;
41  }  }
42    
43  our $memory_size = 512;  sub activate {
44  our $mac = 'AC:DE:48:00:00:01'; # AC = private, AD = multicast, AE = local          system "xdotool windowactivate `xdotool search --class kvm`"
45    }
46    
47  sub start {  sub start {
48            my $nr = shift || 0;
49    
50            my $mac = sprintf('AC:DE:48:00:00:%02x', $nr);
51            my $mon = port(':');
52    
53          my $kvm = qq|          my $kvm = qq|
54                  vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac                  vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac
55                  -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl                  -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl
56                  -boot n                  -boot n
57                  -monitor stdio                  -monitor tcp:$mon,server,nowait
58          |;          |;
   
   
         $kvm = "xterm -e $kvm" if $ENV{DISPLAY};  
   
59          $kvm =~ s{\s+}{ }gs;          $kvm =~ s{\s+}{ }gs;
60    
61          warn $kvm;          warn $kvm;
62          exec $kvm;          exec $kvm;
63    

Legend:
Removed from v.67  
changed lines
  Added in v.170

  ViewVC Help
Powered by ViewVC 1.1.26