Changeset 8d4e4fb for fedkit/gateway_lib.pm
- Timestamp:
- Feb 10, 2010 10:29:18 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- bbd0039
- Parents:
- b73cc45
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedkit/gateway_lib.pm
rb73cc45 r8d4e4fb 9 9 @EXPORT_OK=qw(set_sshd_params import_key wait_for_DNS deter_tunnelip 10 10 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 12 13 13 14 use strict; … … 24 25 my $TMCC = "/usr/local/etc/emulab/tmcc"; 25 26 my $FINDIF = "/usr/local/etc/emulab/findif"; 27 my $TMCC = "/usr/local/etc/emulab/tmcc"; 26 28 27 29 # Takes an ssh config file and a reference to a hash of keys whose values must … … 242 244 } 243 245 246 # untested 247 sub 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 292 sub 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 244 319 1;
Note: See TracChangeset
for help on using the changeset viewer.