/[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 289 by dpavlin, Tue Aug 25 17:39:28 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 ($port,$del) = @_;
19            $port += $nr;
20            return join( $del, $server::ip, $port );
21    }
22    
23  iface tap0 inet static  sub fork_if_active { qw/monitor serial/ }
   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(10000,' ') );
29    }
30    
31    sub serial {
32            x11::xterm( "serial $nr" => 'nc ' . port(11000,' ') );
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(10000,':') );
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 $kvm = qq|          my $mac = sprintf('AC:DE:48:00:00:%02x', $nr);
51                  vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac          my $mon = port(10000,':');
52                  -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl          my $ser = port(11000,':');
                 -boot n  
                 -monitor stdio  
         |;  
53    
54            my $ifname = 'kvm0';
55    
56          $kvm = "xterm -e $kvm" if $ENV{DISPLAY};  #       system "ifconfig $ifname down";
57    #       system "brctl delif virtual $ifname";
58    #       system "tunctl -d $ifname";
59    
60            system "tunctl -t $ifname"; # -u $server::user
61            system "ifconfig $ifname up";
62            system "brctl addif virtual $ifname";
63    
64            my $kvm = qq|
65                    kvm -m $memory_size -net nic,macaddr=$mac
66                    -net tap,ifname=$ifname,script=no
67                    -boot n
68                    -monitor tcp:$mon,server,nowait
69                    -serial  tcp:$ser,server,nowait
70            |;
71            #       -runas $server::user
72          $kvm =~ s{\s+}{ }gs;          $kvm =~ s{\s+}{ }gs;
73    
74          warn $kvm;          warn $kvm;
75          exec $kvm;          exec $kvm;
76    

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

  ViewVC Help
Powered by ViewVC 1.1.26