/[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 92 by dpavlin, Fri Jul 31 19:42:29 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';  our $memory_size = 512;
10    our $mac = 'AC:DE:48:00:00:01'; # AC = private, AD = multicast, AE = local
11  if ( $interfaces !~ m{tap0.*$server::ip}s ) {  our $monitor = 'tcp:' . $server::ip . ':10000,server,nowait';
   
         system "sudo apt-get install vde2";  
   
         $interfaces .= qq{  
12    
13  iface tap0 inet static  sub start_fork { qw/monitor/ }
   address $server::ip  
   netmask $server::netmask  
   vde2-switch -  
14    
15          };  sub monitor {
16            exec "xterm -fg red -e nc $server::ip 10000";
17    }
18    
19          write_file '/etc/network/interfaces', $interfaces;  sub actions { qw/reset window/ }
20    
21    sub reset {
22            my $sock = IO::Socket::INET->new( $server::ip .':10000' );
23            print $sock "system_reset\n";
24            close $sock;
25  }  }
26    
27  if ( grep /tap0/, read_file '/proc/net/dev' ) {  sub window {
28          warn "tap0 started";          system "xdotool windowactivate `xdotool search --class kvm`"
 } else {  
         system "sudo ifup tap0";  
29  }  }
30    
31  our $memory_size = 512;  use network;
 our $mac = '52:54:00:00:00:01';  
32    
33  sub start {  sub start {
34    
35            warn 'tap ', network::tap();
36    
37          my $kvm = qq|          my $kvm = qq|
38                  vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac                  vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac
39                  -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl                  -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl
40                  -boot n                  -boot n
41                    -monitor $monitor
42          |;          |;
43          $kvm =~ s{\s+}{ }gs;          $kvm =~ s{\s+}{ }gs;
44    
45          warn $kvm;          warn $kvm;
46          system $kvm;          exec $kvm;
47    
48  }  }
49    

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

  ViewVC Help
Powered by ViewVC 1.1.26