--- lib/PXElator/kvm.pm 2009/07/30 14:16:13 56 +++ lib/PXElator/kvm.pm 2009/08/25 17:39:28 289 @@ -4,51 +4,73 @@ use strict; use autodie; -use File::Slurp; - use server; -my $interfaces = read_file '/etc/network/interfaces'; +use Data::Dump qw/dump/; -if ( $interfaces !~ m{tap0.*$server::ip}s ) { +our $memory_size = 512; - system "sudo apt-get install vde2"; +# AC = private, AD = multicast, AE = local - $interfaces .= qq{ +our $nr = 0; -iface tap0 inet static - address $server::ip - netmask $server::netmask - vde2-switch - +sub port { + my ($port,$del) = @_; + $port += $nr; + return join( $del, $server::ip, $port ); +} - }; +sub fork_if_active { qw/monitor serial/ } - write_file '/etc/network/interfaces', $interfaces; +use x11; +sub monitor { + x11::xterm( "monitor $nr" => 'nc ' . port(10000,' ') ); } -if ( grep /tap0/, read_file '/proc/net/dev' ) { - warn "tap0 started"; -} else { - system "sudo ifup tap0"; +sub serial { + x11::xterm( "serial $nr" => 'nc ' . port(11000,' ') ); } -our $memory_size = 512; -our $mac = '52:54:00:00:00:01'; +sub actions { qw/reset activate/ } + +sub reset { + my $sock = IO::Socket::INET->new( port(10000,':') ); + print $sock "system_reset\n"; + close $sock; +} + +sub activate { + system "xdotool windowactivate `xdotool search --class kvm`" +} sub start { + my $nr = shift || 0; - my $kvm = qq| - vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac - -net vde,vlan=1,sock=/var/run/vde2/tap0.ctl - -boot n - -monitor stdio - |; + my $mac = sprintf('AC:DE:48:00:00:%02x', $nr); + my $mon = port(10000,':'); + my $ser = port(11000,':'); + + my $ifname = 'kvm0'; +# system "ifconfig $ifname down"; +# system "brctl delif virtual $ifname"; +# system "tunctl -d $ifname"; - $kvm = "xterm -e $kvm" if $ENV{DISPLAY}; + system "tunctl -t $ifname"; # -u $server::user + system "ifconfig $ifname up"; + system "brctl addif virtual $ifname"; + my $kvm = qq| + kvm -m $memory_size -net nic,macaddr=$mac + -net tap,ifname=$ifname,script=no + -boot n + -monitor tcp:$mon,server,nowait + -serial tcp:$ser,server,nowait + |; + # -runas $server::user $kvm =~ s{\s+}{ }gs; + warn $kvm; exec $kvm;