IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42865


Ignore:
Timestamp:
May 16, 2025, 2:22:13 PM (14 months ago)
Author:
eugene
Message:

fix neb-host to handle xattr = 3, xattr = 5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/neb-host-20250516/bin/neb-host

    r41655 r42865  
    1616use Pod::Usage qw( pod2usage );
    1717
    18 my ($host, $state, $note,
    19     $db, $dbhost, $dbpass, $dbuser,
    20     $allocate, $available, $debug,$volume);
     18my ($host, $state, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);
    2119
    2220# $db     = $ENV{'NEB_DB'} unless $db;
     
    2523# $dbpass = $ENV{'NEB_PASS'} unless $dbpass;
    2624
    27 # my $conffile = "/data/ippc64.1/ippitc/ippconfig/nebulous.config";
    2825# my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config";
    2926my $conffile = "/home/panstarrs/ippps1/ippconfig/nebulous.config";
    3027
    3128if (-e $conffile) {
    32 #    printf STDERR "found config\n";
     29    # printf STDERR "found config\n";
    3330    open(IN,$conffile);
    3431    while(<IN>) {
    3532        chomp;
    36         if ($_ =~ /NEB_DB\s+/) {
    37             $db = (split /\s+/,$_)[2];
    38         }
    39         elsif ($_ =~ /NEB_DBHOST/) {
    40             $dbhost = (split /\s+/,$_)[2];
    41         }
    42         elsif ($_ =~ /NEB_USER/) {
    43             $dbuser = (split /\s+/,$_)[2];
    44         }
    45         elsif ($_ =~ /NEB_PASS/) {
    46             $dbpass = (split /\s+/,$_)[2];
    47         }
     33        if ($_ =~ /NEB_DB\s+/)  { $db     = (split /\s+/,$_)[2]; next; }
     34        if ($_ =~ /NEB_DBHOST/) { $dbhost = (split /\s+/,$_)[2]; next; }
     35        if ($_ =~ /NEB_USER/)   { $dbuser = (split /\s+/,$_)[2]; next; }
     36        if ($_ =~ /NEB_PASS/)   { $dbpass = (split /\s+/,$_)[2]; next; }
    4837    }
    4938    close(IN);
    50 #    print STDERR  "$db $dbhost $dbuser $dbpass\n";
     39    # print STDERR  "$db $dbhost $dbuser $dbpass\n";
    5140}
    5241
     
    6049    'dbpass=s'       => \$dbpass,
    6150    'volume'         => \$volume,
    62    
    6351    ) || pod2usage( 2 );
    6452
    65 if (($#ARGV == 1)&&(!defined($host))&&(!defined($state))) {
     53# if --host and --state are not supplied, look for positional arguments
     54# XXX this is wrong, it should say $#ARGV == 3 -- but it seems to work?
     55if (($#ARGV == 1) && (!defined($host)) && (!defined($state))) {
    6656    $host = shift(@ARGV);
    6757    $state = shift(@ARGV);
     
    8373    );
    8474
    85 if ((defined($host))&&(defined($state))) {
    86     if ($state eq 'up') {
    87         $allocate = 1;
    88         $available = 1;
    89     }
    90     elsif ($state eq 'down') {
    91         $allocate = 0;
    92         $available = 0;
    93     }
    94     elsif ($state eq 'repair') {
    95         $allocate = 0;
    96         $available = 1;
    97     }
    98     else {
    99         die "Unknown state '$state'";
    100     }
     75if (defined($host) && defined($state)) {
     76
     77    if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; }
    10178   
    102     my %constraint;
     79    # for 'up', we want to exclude set volumes with xattr = 3, and possible issue an equivalent of 'repair' for xattr = 3
     80    # for 'up' and 'repair', we should exclude volumes with xattr = 5
     81    # for 'down', all volumes are ok
     82   
     83    # up:
     84    # UPDATE volume SET (allocate = 1, available = 1, note = '$note') WHERE (name = '$host') AND (xattr != 3) AND (xattr != 5)
     85    # UPDATE volume SET (allocate = 0, available = 1, note = '$note') WHERE (name = '$host') AND (xattr = 3)
     86
     87    # repair:
     88    # UPDATE volume SET (allocate = 0, available = 1, note = '$note') WHERE (name = '$host') AND (xattr != 5)
     89
     90    # down:
     91    # UPDATE volume SET (allocate = 0, available = 0, note = '$note') WHERE (name = '$host')
     92
     93    # $volume is a boolean which means 'use' the supplied host as the 'name' field
     94    my $hostWhere;
    10395    if (defined($volume)) {
    104         $constraint{'v.name'} = $host;
    105     }
    106     else {
    107         $constraint{'v.host'} = $host;
    108     }
    109     my %set;
    110     $set{'v.allocate'} = $allocate if defined $allocate;
    111     $set{'v.available'} = $available if defined $available;
    112     $set{'v.note'} = $note if defined $note;
    113 
    114     eval {
    115         my ($q, @bind) = sql_interp("UPDATE volume AS v SET", \%set, "WHERE", \%constraint);
    116         warn "$q\n" if $debug;
    117         my $query = $dbh->prepare($q);
    118         $query->execute(@bind);
    119         $dbh->commit;
    120     };
    121     if ($@) {
    122         $dbh->rollback;
    123         die $@;
    124     }
    125     eval {
    126         my ($q, @bind) = sql_interp("UPDATE mountedvol AS v SET", \%set, "WHERE", \%constraint);
    127         warn "$q\n" if $debug;
    128         my $query = $dbh->prepare($q);
    129         $query->execute(@bind);
    130         $dbh->commit;
    131     };
    132     if ($@) {
    133         $dbh->rollback;
    134         die $@;
     96        $hostWhere = "(name = '$host')";
     97    } else {
     98        $hostWhere = "(host = '$host')";
     99    }
     100
     101    my ($selections, $constraint);
     102
     103    if ($state eq 'up')     {
     104        $selections = "allocate = 1, available = 1";
     105        $constraint = "(name = '$host') AND (xattr != 3) AND (xattr != 5)";
     106    }
     107
     108    if ($state eq 'repair')     {
     109        $selections = "allocate = 0, available = 1";
     110        $constraint = "(name = '$host') AND (xattr != 5)";
     111    }
     112
     113    if ($state eq 'down')     {
     114        $selections = "allocate = 0, available = 0";
     115        $constraint = "(name = '$host')";
     116    }
     117
     118    &modify_hosts ($selections, $constraint, $note);
     119
     120    ## for 'up', make a second call to set hosts with (xattr = 3) to 'repair':
     121    if ($state eq 'up')     {
     122        $selections = "allocate = 0, available = 1";
     123        $constraint = "(name = '$host') AND (xattr = 3)";
     124
     125        &modify_hosts ($selections, $constraint, $note);
    135126    }
    136127}
     
    152143        $$row{ 'note' } = '-';
    153144    }
    154 
    155145    printf($format, @$row{@columns});
    156146}
    157147
     148sub modify_hosts {
     149
     150    my $selections = $_[0];
     151    my $constraint = $_[1];
     152
     153    my $note = $_[2];
     154
     155    if (defined $note) { $selections = $selections . ", note = '$note'"; }
     156
     157    {
     158        my $sqlLine = "UPDATE volume SET ($selections) WHERE $constraint";
     159        my $query = $dbh->prepare($sqlLine);
     160        $query->execute() or die "error from Nebulous database\n";
     161    }
     162   
     163    {
     164        my $sqlLine = "UPDATE mountedvol SET ($selections) WHERE $constraint";
     165        my $query = $dbh->prepare($sqlLine);
     166        $query->execute() or die "error from Nebulous database\n";
     167    }
     168}
     169
     170
    158171__END__
     172
     173
    159174
    160175=pod
Note: See TracChangeset for help on using the changeset viewer.