we need to open ethernet tunnel as root, so check it
[pxelator] / lib / PXElator / ssh.pm
1 package ssh;
2
3 use Net::OpenSSH;
4 use English;
5
6 my $id = 2;
7
8 sub ethernet_bridge_to {
9         my $host = shift;
10
11         die "you need to run this as root\n" unless $UID == 0;
12
13         warn "# reset local IP address";
14         system "ifconfig virtual 172.16.10.$id";
15
16         warn "# connect to $host";
17         my $ssh = Net::OpenSSH->new( $host,
18                 master_opts => [ -w => "$id:$id", -o => 'Tunnel=ethernet' ],
19         );
20
21         foreach my $command ( "ifconfig tap$id up", "brctl addif virtual tap$id" ) {
22                 warn "# $command";
23                 system $command;
24                 $ssh->system( $command ) or die "$command ", $ssh->error;
25         }
26
27         warn "press enter to close tunnel to $host from $id";
28         <STDIN>;
29
30 }
31
32 1;