Changeset d38ff56


Ignore:
Timestamp:
May 25, 2010 5:42:25 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
b10375f
Parents:
479a7d9
Message:

More flexible and useful gateway aliasing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedkit/federate.pl

    r479a7d9 rd38ff56  
    2424my %services;
    2525my %aliases;
    26 my @added;
     26my %added;
    2727my $perl;
    2828
     
    9595    /Service:\s+(.*)/i && do { $services{$1}++;};
    9696    /PortalAlias:\s+(.*)/i && do { $aliases{$1}++;};
    97     /AddedNode:\s+(.*)/i && do { push(@added, $1); };
    98 }
    99 
    100 # If nodes have been added with this name, do not alias the name to the portal
    101 for my $a (@added) {
    102     chomp $a;
    103     delete $aliases{$a} if $aliases{$a};
     97    /AddedNode:\s+(.*)/i && do { $added{$1}++; };
    10498}
    10599$client->close();
     
    123117    print $new_hosts $_;
    124118}
     119print $new_hosts "\n";
    125120$config_hosts->close();
    126121
    127122# Add gateway aliases
    128 if (%aliases) {
    129     if ( my $hent = gethostbyname($gateway) ) {
    130         my $gwip = inet_ntoa($hent->addr_list->[0]);
    131 
    132         for my $k (keys %aliases) {
    133             if ($exp && $proj) {
    134                 print $new_hosts "\n$gwip\t$k.$exp.$proj $k\n";
    135             }
    136             else {
    137                 print $new_hosts "\n$gwip\t$k\n";
    138             }
    139         }
    140     }
     123for my $k (keys %aliases) {
     124    # If we added a node, it's a node without a local address.  Bind the name
     125    # to the IP in /etc/hosts.  If we didn't add a node, it's the gateway node.
     126    (my $lname = $gateway) =~ s/^[^\.]+/$k/;
     127    my $ip = gateway_lib::get_ip($added{$k} ? $lname : $gateway);
     128    if ($ip) {
     129        # We have an IP.  Make a hosts entry for teh key and the key plus the
     130        # first two subdomains (which is an emulab setup)
     131        my @x = split(/\./, $lname);
     132        if (@x > 3 ) { splice(@x, 3); }
     133        my $out = join(".", @x);
     134        print $new_hosts "$ip\t$out $k\n";
     135    }
     136    else { print $new_hosts "# Can't get ip for $lname\n"; }
    141137}
    142138$new_hosts->close();
Note: See TracChangeset for help on using the changeset viewer.