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

Legend:
Removed from v.54  
changed lines
  Added in v.225

  ViewVC Help
Powered by ViewVC 1.1.26