/[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 283 by dpavlin, Mon Aug 24 18:07:19 2009 UTC revision 351 by dpavlin, Sat Aug 29 21:10:21 2009 UTC
# Line 1  Line 1 
1  package ssh;  package ssh;
2    
3    use warnings;
4    use strict;
5    
6  use Net::OpenSSH;  use Net::OpenSSH;
7    use English;
8    use Data::Dump qw/dump/;
9    use client;
10    use CouchDB;
11    
12  my $id = 2;  my $id = 2;
13    
14  sub ethernet_bridge_to {  sub ethernet_bridge_to {
15          my $host = shift;          my $host = shift;
16    
17            die "you need to run this as root\n" unless $UID == 0;
18    
19          warn "# reset local IP address";          warn "# reset local IP address";
20          system "ifconfig virtual 172.16.10.$id";          system "ifconfig virtual 172.16.10.$id";
21    
# Line 26  sub ethernet_bridge_to { Line 35  sub ethernet_bridge_to {
35    
36  }  }
37    
38    sub shell {
39            my $ip = shift;
40    
41            my $ssh = Net::OpenSSH->new( $ip );
42    
43            my $html;
44            my @shell;
45    
46            foreach my $command ( @_ ) {
47                    warn "root\@$ip:# $command\n";
48                    my ($out,$err) = $ssh->capture2( $command ) or die "$command ", $ssh->error;
49                    warn "$out\n$err";
50    
51                    CouchDB::audit( $ip, $command, { ip => $ip, command => $command, out => $out, err => $err } );
52    
53                    $html .= qq|<tt style="color: grey">root\@$ip:# <b>$command</b></tt><pre>$out</pre>|;
54                    $html .= qq|<pre style="color: red">$err</pre>| if $err;
55            }
56    
57            return $html;
58    }
59    
60    my $id_pub = '/root/.ssh/id_rsa.pub';
61    
62    sub copy_id {
63            my $ip = shift;
64            my $ssh = client::ip_path( $ip, 'ssh' );
65            return if -l $ssh;
66            my $cmd = "sudo ssh-copy-id -i $id_pub root\@$ip";
67            warn "# $cmd\n";
68            system $cmd;
69            symlink $id_pub, $ssh;
70    }
71    
72  1;  1;

Legend:
Removed from v.283  
changed lines
  Added in v.351

  ViewVC Help
Powered by ViewVC 1.1.26