X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FPXElator%2Fssh.pm;h=7895593f5faf82a92420b265e91c71b1a98328b7;hb=ab32c7adffa6af6f360791ef72945efc90359661;hp=20eafc3528ef304fb22eeb21634805e4c451bf00;hpb=bd29c456dbedddf4dcc43c52705f346de5d1499f;p=pxelator diff --git a/lib/PXElator/ssh.pm b/lib/PXElator/ssh.pm index 20eafc3..7895593 100644 --- a/lib/PXElator/ssh.pm +++ b/lib/PXElator/ssh.pm @@ -9,19 +9,34 @@ use Data::Dump qw/dump/; use client; use CouchDB; -my $id = 2; +my $id = 3; +my $id_rsa = '/root/.ssh/id_rsa'; + +sub copy_id { + my $ip = shift; + my $ssh = client::ip_path( $ip, 'ssh' ); + return if -l $ssh; + my $id = $id_rsa . '.pub'; + my $cmd = "sudo ssh-copy-id -i $id root\@$ip"; + warn "# $cmd\n"; + system $cmd; + warn "$id -> $ssh"; + symlink $id, $ssh; +} sub ethernet_bridge_to { - my $host = shift; + my $ip = shift; die "you need to run this as root\n" unless $UID == 0; + copy_id $ip; + warn "# reset local IP address"; system "ifconfig virtual 172.16.10.$id"; - warn "# connect to $host"; - my $ssh = Net::OpenSSH->new( $host, - master_opts => [ -w => "$id:$id", -o => 'Tunnel=ethernet' ], + warn "# connect to $ip"; + my $ssh = Net::OpenSSH->new( $ip, + master_opts => [ -i => $id_rsa, -w => "$id:$id", -o => 'Tunnel=ethernet' ], ); foreach my $command ( "ifconfig tap$id up", "brctl addif virtual tap$id" ) { @@ -30,15 +45,22 @@ sub ethernet_bridge_to { $ssh->system( $command ) or die "$command ", $ssh->error; } - warn "press enter to close tunnel to $host from $id"; + warn "press enter to close tunnel to $ip from $id"; ; + system "ifconfig virtual 172.16.10.1"; + } sub shell { my $ip = shift; - my $ssh = Net::OpenSSH->new( $ip ); + copy_id $ip; + + warn "# ssh $ip -i $id_rsa"; + my $ssh = Net::OpenSSH->new( $ip, + master_opts => [ -i => $id_rsa ], + ); my $html; my @shell; @@ -57,16 +79,4 @@ sub shell { return $html; } -my $id_pub = '/root/.ssh/id_rsa.pub'; - -sub copy_id { - my $ip = shift; - my $ssh = client::ip_path( $ip, 'ssh' ); - return if -l $ssh; - my $cmd = "sudo ssh-copy-id -i $id_pub root\@$ip"; - warn "# $cmd\n"; - system $cmd; - symlink $id_pub, $ssh; -} - 1;