6 |
|
|
7 |
use server; |
use server; |
8 |
|
|
9 |
|
use Data::Dump qw/dump/; |
10 |
|
|
11 |
our $memory_size = 512; |
our $memory_size = 512; |
|
our $mac = 'AC:DE:48:00:00:01'; # AC = private, AD = multicast, AE = local |
|
|
our $monitor = 'tcp:' . $server::ip . ':10000,server,nowait'; |
|
12 |
|
|
13 |
sub start_fork { qw/monitor/ } |
# AC = private, AD = multicast, AE = local |
14 |
|
|
15 |
|
sub nr { $ENV{nr} || 0 }; |
16 |
|
|
17 |
|
sub port { |
18 |
|
my ($port,$del) = @_; |
19 |
|
$port += nr(); |
20 |
|
return join( $del, $server::ip, $port ); |
21 |
|
} |
22 |
|
|
23 |
|
sub fork_if_active { qw/monitor serial/ } |
24 |
|
|
25 |
|
use x11; |
26 |
|
|
27 |
sub monitor { |
sub monitor { |
28 |
exec "xterm -fg red -e nc $server::ip 10000"; |
x11::xterm( 'monitor ' . nr() => 'nc ' . port(10000,' ') ); |
29 |
|
} |
30 |
|
|
31 |
|
sub serial { |
32 |
|
my $nr = $ENV{nr} || 0; |
33 |
|
x11::xterm( 'serial ' . nr() => 'nc ' . port(11000,' ') ); |
34 |
} |
} |
35 |
|
|
36 |
sub actions { qw/reset/ } |
sub actions { qw/reset activate/ } |
37 |
|
|
38 |
sub reset { |
sub reset { |
39 |
my $sock = IO::Socket::INET->new( $server::ip .':10000' ); |
my $sock = IO::Socket::INET->new( port(10000,':') ); |
40 |
print $sock "system_reset\n"; |
print $sock "system_reset\n"; |
41 |
close $sock; |
close $sock; |
42 |
} |
} |
43 |
|
|
44 |
use network; |
sub activate { |
45 |
|
system "xdotool windowactivate `xdotool search --class kvm`" |
46 |
|
} |
47 |
|
|
48 |
sub start { |
sub start { |
49 |
|
my $nr = $ENV{nr} || 0; |
50 |
|
|
51 |
warn 'tap ', network::tap(); |
my $mac = sprintf('AC:DE:48:00:00:%02x', $nr); |
52 |
|
my $mon = port(10000,':'); |
53 |
|
my $ser = port(11000,':'); |
54 |
|
|
55 |
|
my $ifname = 'kvm' . $nr; |
56 |
|
|
57 |
|
warn "# kvm start $nr $mac $mon $ser $ifname"; |
58 |
|
|
59 |
|
# system "ifconfig $ifname down"; |
60 |
|
# system "brctl delif virtual $ifname"; |
61 |
|
# system "tunctl -d $ifname"; |
62 |
|
|
63 |
|
my $ifconfig = `/sbin/ifconfig $ifname`; |
64 |
|
|
65 |
|
# FIXME tunctl -u $server::user |
66 |
|
system "tunctl -t $ifname" |
67 |
|
unless $ifconfig =~ m{$ifname}; |
68 |
|
system "ifconfig $ifname up" |
69 |
|
unless $ifconfig =~ m{UP}; |
70 |
|
system "brctl addif virtual $ifname" |
71 |
|
unless `brctl show` =~ m{$ifname}; |
72 |
|
|
73 |
my $kvm = qq| |
my $kvm = qq| |
74 |
vdeq kvm -m $memory_size -net nic,vlan=1,macaddr=$mac |
kvm -m $memory_size -net nic,macaddr=$mac |
75 |
-net vde,vlan=1,sock=/var/run/vde2/tap0.ctl |
-net tap,ifname=$ifname,script=no |
76 |
-boot n |
-boot n |
77 |
-monitor $monitor |
-monitor tcp:$mon,server,nowait |
78 |
|
-serial tcp:$ser,server,nowait |
79 |
|; |
|; |
80 |
|
# -runas $server::user |
81 |
$kvm =~ s{\s+}{ }gs; |
$kvm =~ s{\s+}{ }gs; |
82 |
|
|
83 |
warn $kvm; |
warn $kvm; |
85 |
|
|
86 |
} |
} |
87 |
|
|
88 |
|
sub nr_from_mac { |
89 |
|
my $mac = shift; |
90 |
|
$mac =~ s{^.+:([0-9a-f]{2})$}{hex($1)}e; |
91 |
|
$mac; |
92 |
|
} |
93 |
|
|
94 |
|
sub next_nr { |
95 |
|
my @kvms = glob "$server::conf/mac/AC:DE:48:00:00:*"; |
96 |
|
my $nr = nr_from_mac( pop @kvms ); |
97 |
|
return $nr + 1; |
98 |
|
} |
99 |
|
|
100 |
warn 'loaded'; |
warn 'loaded'; |
101 |
|
|
102 |
1; |
1; |