IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2015, 3:12:58 PM (11 years ago)
Author:
watersc1
Message:

Updated remote code with ff support and ippconfig recipes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/sc_remote_exec.pl

    r38062 r38168  
    1313use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1414use Pod::Usage qw( pod2usage );
    15 
    16 # Hard coded values
    17 my $DMZ_HOST = 'wtrw';
    18 my @SEC_HOSTS= ('mu-fe1','mu-fe2','mu-fe3'
    19                 # ,'mu-fe4'
    20     );
    21 my $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))]; # 'mu-fe';
    22 my $IPP_PATH = '/turquoise/usr/projects/cosmo/mswarren/ipp/';
    23 my $remote_root  = '/scratch3/watersc1/';
    2415
    2516# tools
     
    2819my $scp        = can_run('scp')  or (warn "Can't find scp" and $missing_tools = 1);
    2920my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
     21my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    3022
    3123if ($missing_tools) {
     
    3527
    3628# Options
    37 my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera);
     29my ($remote_id,$job_id,$path_base,$dbname,$verbose,$no_update,$camera,$cmd_recipe);
    3830$verbose = 0;
    3931GetOptions(
     
    4234    'camera=s'      => \$camera,
    4335    'dbname=s'      => \$dbname,
     36    'recipe=s'       => \$cmd_recipe,
    4437    'verbose'       => \$verbose,
    4538    'no_update'     => \$no_update,
     
    4740
    4841pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    49 pod2usage( -msg => "Required options: --remote_id --path_base", -exitval => 3) unless
     42pod2usage( -msg => "Required options: --remote_id --path_base --recipe", -exitval => 3) unless
    5043    defined($path_base) and
     44    defined($camera) and
     45    defined($cmd_recipe) and
     46    defined($dbname) and
    5147    defined($remote_id);
     48
     49# Hard coded values
     50# Now accessible from a recipe
     51my %remote_recipe = ();
     52{
     53    my $verbose = 0;
     54    my $conf_cmd = "$ppConfigDump -dump-recipe REMOTE -";
     55    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     56        run(command => $conf_cmd, verbose => $verbose);
     57    unless ($success) {
     58        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     59        &my_die("Unable to perform ppConfigDump: $error_code", -1, $PS_EXIT_SYS_ERROR);
     60    }
     61    my $mdcParser = PS::IPP::Metadata::Config->new;
     62    my $metadata = $mdcParser->parse(join "", @$stdout_buf);
     63
     64    my $active_recipe = '';
     65    my %recipes = ();
     66   
     67#    print Dumper($metadata);
     68    foreach my $entry (@{ $metadata }) {
     69        if (${ $entry }{name} eq 'ACTIVE') {
     70            $active_recipe = ${ $entry }{value}; # Not actually used
     71        }
     72        else {
     73            if (${ $entry }{class} eq 'metadata') { # A real recipe
     74                my $name = ${ $entry }{name};
     75                foreach my $tentry (@{ ${ $entry }{value} }) {
     76                    if (${ $tentry }{class} eq 'scalar') { # A recipe value
     77                        $recipes{$name}{${ $tentry }{name}} = ${ $tentry }{value};
     78                    }
     79                    elsif (${ $tentry }{class} eq 'metadata') { # A recipe array
     80                        foreach my $arr_entry (@{ ${ $tentry }{value} }) {
     81                            push @{ $recipes{$name}{${ $tentry }{name}} }, ${ $arr_entry }{value};
     82                        }
     83                    }
     84                }
     85            }
     86        }
     87    }
     88   
     89    unless (exists($recipes{$cmd_recipe})) { &my_die("Cannot find recipe $cmd_recipe", -1, $PS_EXIT_CONFIG_ERROR) };
     90#    print Dumper(%recipes);
     91    %remote_recipe = %{ $recipes{$cmd_recipe} }; # Select the appropriate recipe.
     92#    print Dumper(\%remote_recipe);
     93}
     94
     95# Hard coded values
     96my $DMZ_HOST = $remote_recipe{DMZ_HOST};
     97my @SEC_HOSTS= @{ $remote_recipe{SEC_HOST} };
     98my $SEC_HOST;
     99if ($#SEC_HOSTS != -1) {
     100    $SEC_HOST = $SEC_HOSTS[int(rand(@SEC_HOSTS))];
     101}
     102else {
     103    $SEC_HOST = '';
     104}
     105my $IPP_PATH = $remote_recipe{IPP_PATH};
     106my $remote_root  = $remote_recipe{REMOTE_ROOT};
    52107
    53108my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
     
    141196    my $file = shift;
    142197    my $destination = shift;
    143     my $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
     198    my $cmd;
     199    if ($SEC_HOST ne '') {
     200        $cmd = "$scp $file ${DMZ_HOST}:${SEC_HOST}:${destination}";
     201    }
     202    else {
     203        $cmd = "$ssh -n $DMZ_HOST $cmd";
     204    }
    144205
    145206    my $directory = dirname($destination);
     
    157218    my $destination = shift;
    158219    my $file = shift;
    159 
    160     my $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
     220    my $cmd;
     221    if ($SEC_HOST ne '') {
     222        $cmd = "$scp ${DMZ_HOST}:${SEC_HOST}:${destination} $file ";
     223    }
     224    else {
     225        $cmd = "$ssh -n $DMZ_HOST $cmd";
     226    }
    161227
    162228    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    170236sub ssh_exec_command {
    171237    my $cmd = shift;
    172     $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
     238    if ($SEC_HOST ne '') {
     239        $cmd = "$ssh -n $DMZ_HOST ssh  ${SEC_HOST} $cmd";
     240    }
     241    else {
     242        $cmd = "$ssh -n $DMZ_HOST $cmd";
     243    }
     244
    173245    print "EXEC: $cmd\n";
    174246    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Note: See TracChangeset for help on using the changeset viewer.