Ignore:
Timestamp:
Feb 10, 2010 10:29:18 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
bbd0039
Parents:
b73cc45
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedkit/gateway_lib.pm

    rb73cc45 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;
Note: See TracChangeset for help on using the changeset viewer.