http://blog.rot13.org/2009/08/tap_magic_kvm_bridge_ssh_ethernet_tunnel.html
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 24 Aug 2009 18:07:19 +0000 (18:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 24 Aug 2009 18:07:19 +0000 (18:07 +0000)
turned into simple package for pxelator... nice and simple
(runs same commands on both hosts :-)

lib/PXElator/ssh.pm [new file with mode: 0644]
lib/PXElator/t/ssh.t [new file with mode: 0755]

diff --git a/lib/PXElator/ssh.pm b/lib/PXElator/ssh.pm
new file mode 100644 (file)
index 0000000..0b67bd9
--- /dev/null
@@ -0,0 +1,29 @@
+package ssh;
+
+use Net::OpenSSH;
+
+my $id = 2;
+
+sub ethernet_bridge_to {
+       my $host = shift;
+
+       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' ],
+       );
+
+       foreach my $command ( "ifconfig tap$id up", "brctl addif virtual tap$id" ) {
+               warn "# $command";
+               system $command;
+               $ssh->system( $command ) or die "$command ", $ssh->error;
+       }
+
+       warn "press enter to close tunnel to $host from $id";
+       <STDIN>;
+
+}
+
+1;
diff --git a/lib/PXElator/t/ssh.t b/lib/PXElator/t/ssh.t
new file mode 100755 (executable)
index 0000000..097bf85
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'ssh';
+
+ok( ssh::ethernet_bridge_to( '10.60.0.94' ), 'ethernet_bridge' );