Show
Ignore:
Timestamp:
02/10/10 10:29:18 (2 years ago)
Author:
Ted Faber <faber@…>
Children:
bbd00399d41bbe4da7582776a71d47bc5e0f0a82
Parents:
b73cc45c6ebf1b7485b5d0532772c42a6eb4f79a
git-committer:
Ted Faber <faber@isi.edu> / 2010-02-10T18:29:18Z+0000
Message:

Add support for parameters via files in a standard emulab location

Also moved combo_active.pl to combo.pl and added support for passive gateways.

Location:
fedkit
Files:
4 modified
1 moved

Legend:

Unmodified
Added
Removed
  • fedkit/Makefile

    r2edec46 r8d4e4fb  
    11BINARIES=federate.sh smbmount.FreeBSD.pl smbmount.Linux.pl \ 
    22         make_hosts fed-tun.pl fed_evrepeater rc.fedaccounts \ 
    3          config_from_tunnelip.pl active_config.pl combo_active.pl \ 
     3         config_from_tunnelip.pl active_config.pl combo.pl \ 
    44         prep_gateway.pl port_forward.pl setup_bridge.pl 
    55 
    66LIBRARIES=gateway_lib.pm  
    77 
    8 fedkit.tgz:     ${BINARIES} ${PATCHES} 
     8fedkit.tgz:     ${LIBRARIES} ${BINARIES} ${PATCHES} 
    99        mkdir -p /tmp/fedkit/local/federation/bin 
    1010        mkdir -p /tmp/fedkit/local/federation/lib 
  • fedkit/active_config.pl

    r2b35261 r8d4e4fb  
    1515my $fedkit_dir= "/usr/local/federation"; 
    1616my $perl = "/usr/bin/perl"; 
    17 my $iface_file; 
     17my $iface_file = "/var/emulab/boot/ifmap"; 
    1818my $ssh = "/usr/bin/ssh"; 
     19my $use_file; 
    1920 
    20 exit(20) unless GetOptions( 
     21my %opts = ( 
    2122    'ssh_pubkey=s' => \$ssh_pubkey, 
    2223    'ssh_privkey=s' => \$ssh_privkey, 
     
    2728    'interfaces=s' => \$iface_file, 
    2829    'ssh=s' => \$ssh, 
     30    'use_file' => \$use_file, 
    2931); 
    3032 
     33exit(20) unless GetOptions(%opts); 
     34 
     35gateway_lib::read_config(gateway_lib::emulab_config_filename(), \%opts) 
     36    if $use_file; 
    3137 
    3238my $tunnelparam = $tunnelip ? '--tunnelip' : ''; 
     
    109115connectivity information 
    110116 
     117=item B<use_file> 
     118 
     119If given read additional parameters from the file in 
     120/proj/I<project>/exp/I<experiment/tmp/I<hostname>.gw/conf where those are the 
     121current testbed project and experiment and the hostname is before the first 
     122dot.  The file is option: value. 
     123 
     124 
    111125=back 
    112126 
  • fedkit/combo.pl

    r2b35261 r8d4e4fb  
    1111my $ssh_pubkey; 
    1212my $ssh_privkey; 
     13my $active; 
    1314my $tunnelip; 
    1415my $peer; 
    1516my $fedkit_dir= "/usr/local/federation"; 
    1617my $perl = "/usr/bin/perl"; 
    17 my $iface_file; 
     18my $iface_file = "/var/emulab/boot/ifmap"; 
    1819my $ssh = "/usr/bin/ssh"; 
    1920my @ports; 
     21my $use_file; 
    2022 
    21 exit(20) unless GetOptions( 
     23my %opts = ( 
    2224    'ssh_pubkey=s' => \$ssh_pubkey, 
    2325    'ssh_privkey=s' => \$ssh_privkey, 
     
    2830    'interfaces=s' => \$iface_file, 
    2931    'ssh=s' => \$ssh, 
    30     'port=s', \@ports, 
     32    'port=s' => \@ports, 
     33    'active' => \$active,  
     34    'use_file' => \$use_file, 
    3135); 
    3236 
     37exit(20) unless GetOptions(%opts); 
     38 
     39gateway_lib::read_config(gateway_lib::emulab_config_filename(), \%opts) 
     40    if $use_file; 
    3341 
    3442my $tunnelparam = $tunnelip ? '--tunnelip' : ''; 
    35 my $portparam = join(" --port=", @ports); 
     43if ($active) { 
     44    my $portparam = join(" --port=", @ports); 
    3645 
    37 # join doesn't prefix the first one 
    38 $portparam="--port=$portparam" if $portparam; 
     46    # join doesn't prefix the first one 
     47    $portparam="--port=$portparam" if $portparam; 
    3948 
    40 system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/active_config.pl " . 
    41     "--peer=$peer --ssh_pubkey=$ssh_pubkey --ssh_privkey=$ssh_privkey " . 
    42     " $tunnelparam --fedkit=$fedkit_dir --perl=$perl " . 
    43     "--ssh=$ssh --interfaces=$iface_file"); 
    44 exit(20) if $?; 
     49    system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/active_config.pl " . 
     50        "--peer=$peer --ssh_pubkey=$ssh_pubkey --ssh_privkey=$ssh_privkey " . 
     51        " $tunnelparam --fedkit=$fedkit_dir --perl=$perl " . 
     52        "--ssh=$ssh --interfaces=$iface_file"); 
     53    exit(20) if $?; 
    4554 
    46 system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/port_forward.pl " . 
    47     "--peer=$peer --ssh_pubkey=$ssh_pubkey --ssh_privkey=$ssh_privkey " . 
    48     " $tunnelparam --fedkit=$fedkit_dir --perl=$perl " . 
    49     "--ssh=$ssh $portparam"); 
    50 exit(20) if $?; 
     55    system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/port_forward.pl " . 
     56        "--peer=$peer --ssh_pubkey=$ssh_pubkey --ssh_privkey=$ssh_privkey " . 
     57        " $tunnelparam --fedkit=$fedkit_dir --perl=$perl " . 
     58        "--ssh=$ssh $portparam"); 
     59    exit(20) if $?; 
     60} 
     61else { 
     62    system("$perl -I$fedkit_dir/lib $fedkit_dir/bin/prep_gateway.pl " .  
     63        "--peer=$peer --ssh_pubkey=$ssh_pubkey $tunnelparam"); 
     64    exit(20) if $?; 
     65} 
    5166 
    5267=pod 
     
    108123connectivity information 
    109124 
     125=item B<use_file> 
     126 
     127If given read additional parameters from the file in 
     128/proj/I<project>/exp/I<experiment/tmp/I<hostname>.gw/conf where those are the 
     129current testbed project and experiment and the hostname is before the first 
     130dot.  The file is option: value. 
     131 
    110132=back 
    111133 
  • fedkit/gateway_lib.pm

    r2b35261 r8d4e4fb  
    99@EXPORT_OK=qw(set_sshd_params import_key wait_for_DNS deter_tunnelip  
    1010    configure_outgoing_iface add_route bind_tap_to_iface iface_to_addr 
    11     dest_to_iface addr_to_iface); 
     11    dest_to_iface addr_to_iface read_config emulab_config_filename); 
     12 
    1213 
    1314use strict; 
     
    2425my $TMCC = "/usr/local/etc/emulab/tmcc"; 
    2526my $FINDIF = "/usr/local/etc/emulab/findif"; 
     27my $TMCC = "/usr/local/etc/emulab/tmcc"; 
    2628 
    2729# Takes an ssh config file and a reference to a hash of keys whose values must 
     
    242244} 
    243245 
     246# untested 
     247sub read_config { 
     248    my($file, $map) = @_; 
     249    my %param; 
     250    my %keywords; 
     251    my $f; 
     252 
     253    foreach my $k (keys %{$map}) { 
     254        if ( $k =~ /(\S+)=[si]/ ) { 
     255            $keywords{$1} = $map->{$k}; 
     256            $param{$1}++; 
     257        } 
     258        else { 
     259            $keywords{$k} = $map->{$k}; 
     260        } 
     261    } 
     262 
     263    $f = new IO::File($file) || die "Can't open $file: $!\n"; 
     264    while (<$f>) { 
     265        /^\s*([^:]+):\s*(.*)/ && do { 
     266            my $keyw = $1; 
     267            my $val = $2; 
     268 
     269            $keyw =~ tr [A-Z] [a-z]; 
     270 
     271            if ($keywords{$keyw} ) { 
     272                if ( $param{$keyw} ) {  
     273                    if ( ref($keywords{$keyw}) eq 'SCALAR') { 
     274                        ${$keywords{$keyw}} = $val; 
     275                    } 
     276                    elsif( ref($keywords{$keyw}) eq 'ARRAY') { 
     277                        push(@{$keywords{$keyw}}, $val); 
     278                    } 
     279                    else { 
     280                        die "Unknown variable type for $keyw\n"; 
     281                    } 
     282                } 
     283                else  { ${$keywords{$keyw}}++; } 
     284            } 
     285            next; 
     286        }; 
     287    } 
     288    $f->close(); 
     289} 
     290 
     291 
     292sub emulab_config_filename { 
     293    # Find the configuration file in the usual place, which depends on what 
     294    # experiment and project we're in. 
     295    my $pid; 
     296    my $eid; 
     297    my $filename; 
     298    my $tmcd = new IO::Pipe() || die "Can't create pipe: $!\n"; 
     299 
     300    $tmcd->reader("$TMCC status"); 
     301 
     302    while (<$tmcd>) { 
     303        chomp; 
     304        /ALLOCATED=([^\/]+)\/(\S+)/ && do { 
     305            $pid = $1; 
     306            $eid = $2; 
     307        }; 
     308    } 
     309    $tmcd->close(); 
     310    my $hn = `hostname`; 
     311    chomp $hn; 
     312    $hn =~ s/\..*//; 
     313    $filename = "/proj/$pid/exp/$eid/tmp/$hn.gw.conf" 
     314        if $pid and $eid; 
     315 
     316    return $filename; 
     317} 
     318 
    2443191; 
  • fedkit/prep_gateway.pl

    r2b35261 r8d4e4fb  
    1010my $tunnelip; 
    1111my $peer; 
    12  
    13 exit(20) unless GetOptions('ssh_pubkey=s' => \$ssh_pubkey, 
     12my $use_file; 
     13my %opts = ( 
     14    'ssh_pubkey=s' => \$ssh_pubkey, 
    1415    'tunnelip' => \$tunnelip, 
    1516    'peer=s' => \$peer, 
     17    'use_file' => \$use_file, 
    1618); 
     19 
     20exit(20) unless GetOptions(%opts); 
     21 
     22gateway_lib::read_config(gateway_lib::emulab_config_filename(), \%opts) 
     23    if $use_file; 
    1724 
    1825gateway_lib::set_sshd_params(  
     
    6471connectivity information 
    6572 
     73=item B<use_file> 
     74 
     75If given read additional parameters from the file in 
     76/proj/I<project>/exp/I<experiment/tmp/I<hostname>.gw/conf where those are the 
     77current testbed project and experiment and the hostname is before the first 
     78dot.  The file is option: value. 
     79 
     80 
    6681=back 
    6782