/[pxelator]/lib/PXElator/ssh.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/ssh.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 352 by dpavlin, Sat Aug 29 21:10:21 2009 UTC revision 353 by dpavlin, Sat Aug 29 22:10:37 2009 UTC
# Line 10  use client; Line 10  use client;
10  use CouchDB;  use CouchDB;
11    
12  my $id = 2;  my $id = 2;
13    my $id_rsa = '/root/.ssh/id_rsa';
14    
15    sub copy_id {
16            my $ip = shift;
17            my $ssh = client::ip_path( $ip, 'ssh' );
18            return if -l $ssh;
19            my $id = $id_rsa . '.pub';
20            my $cmd = "sudo ssh-copy-id -i $id root\@$ip";
21            warn "# $cmd\n";
22            system $cmd;
23            warn "$id -> $ssh";
24            symlink $id, $ssh;
25    }
26    
27  sub ethernet_bridge_to {  sub ethernet_bridge_to {
28          my $host = shift;          my $ip = shift;
29    
30          die "you need to run this as root\n" unless $UID == 0;          die "you need to run this as root\n" unless $UID == 0;
31    
32            copy_id $ip;
33    
34          warn "# reset local IP address";          warn "# reset local IP address";
35          system "ifconfig virtual 172.16.10.$id";          system "ifconfig virtual 172.16.10.$id";
36    
37          warn "# connect to $host";          warn "# connect to $ip";
38          my $ssh = Net::OpenSSH->new( $host,          my $ssh = Net::OpenSSH->new( $ip,
39                  master_opts => [ -w => "$id:$id", -o => 'Tunnel=ethernet' ],                  master_opts => [ -i => $id_rsa, -w => "$id:$id", -o => 'Tunnel=ethernet' ],
40          );          );
41    
42          foreach my $command ( "ifconfig tap$id up", "brctl addif virtual tap$id" ) {          foreach my $command ( "ifconfig tap$id up", "brctl addif virtual tap$id" ) {
# Line 30  sub ethernet_bridge_to { Line 45  sub ethernet_bridge_to {
45                  $ssh->system( $command ) or die "$command ", $ssh->error;                  $ssh->system( $command ) or die "$command ", $ssh->error;
46          }          }
47    
48          warn "press enter to close tunnel to $host from $id";          warn "press enter to close tunnel to $ip from $id";
49          <STDIN>;          <STDIN>;
50    
51            system "ifconfig virtual 172.16.10.1";
52    
53  }  }
54    
55  sub shell {  sub shell {
56          my $ip = shift;          my $ip = shift;
57    
58          my $ssh = Net::OpenSSH->new( $ip );          copy_id $ip;
59    
60            warn "# ssh $ip -i $id_rsa";
61            my $ssh = Net::OpenSSH->new( $ip,
62                    master_opts => [ -i => $id_rsa ],
63            );
64    
65          my $html;          my $html;
66          my @shell;          my @shell;
# Line 57  sub shell { Line 79  sub shell {
79          return $html;          return $html;
80  }  }
81    
 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;  
 }  
   
82  1;  1;

Legend:
Removed from v.352  
changed lines
  Added in v.353

  ViewVC Help
Powered by ViewVC 1.1.26