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

Legend:
Removed from v.80  
changed lines
  Added in v.229

  ViewVC Help
Powered by ViewVC 1.1.26