IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42866


Ignore:
Timestamp:
May 19, 2025, 12:20:20 PM (14 months ago)
Author:
eugene
Message:

neb-host modifications to prevent xattr = 3 volumes from being set to state=up and xattr = 5 volumes from being set to up or repair

File:
1 edited

Legend:

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

    r42865 r42866  
    1616use Pod::Usage qw( pod2usage );
    1717
    18 my ($host, $state, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);
     18my ($host, $state, $xattr, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);
    1919
    2020# $db     = $ENV{'NEB_DB'} unless $db;
     
    4343    'host=s'         => \$host,
    4444    'state=s'        => \$state,
     45    'xattr=s'        => \$xattr,
    4546    'note=s'         => \$note,
    4647    'db=s'           => \$db,
     
    5253
    5354# 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?
    55 if (($#ARGV == 1) && (!defined($host)) && (!defined($state))) {
     55my $Narg = @ARGV;
     56
     57if (($Narg == 1) && (!defined($host)) && (!defined($state))) {
     58    # neb-host (host) : return volume into for specified host
     59    $host = shift(@ARGV);
     60}
     61if (($Narg == 2) && (!defined($host)) && (!defined($state))) {
    5662    $host = shift(@ARGV);
    5763    $state = shift(@ARGV);
     
    7581if (defined($host) && defined($state)) {
    7682
     83    # strip dangerous characters
     84    if (defined($note)) { $note =~ s/'/ /g; $note =~ s/;/ /g; $note =~ s/"/ /g; }
     85    if (defined($host)) { $host =~ s/'/ /g; $host =~ s/;/ /g; $host =~ s/"/ /g; }
     86
    7787    if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; }
    7888   
     
    103113    if ($state eq 'up')     {
    104114        $selections = "allocate = 1, available = 1";
    105         $constraint = "(name = '$host') AND (xattr != 3) AND (xattr != 5)";
     115        $constraint = "$hostWhere AND (xattr != 3) AND (xattr != 5)";
    106116    }
    107117
    108118    if ($state eq 'repair')     {
    109119        $selections = "allocate = 0, available = 1";
    110         $constraint = "(name = '$host') AND (xattr != 5)";
     120        $constraint = "$hostWhere AND (xattr != 5)";
    111121    }
    112122
    113123    if ($state eq 'down')     {
    114124        $selections = "allocate = 0, available = 0";
    115         $constraint = "(name = '$host')";
     125        $constraint = "$hostWhere";
    116126    }
    117127
     
    121131    if ($state eq 'up')     {
    122132        $selections = "allocate = 0, available = 1";
    123         $constraint = "(name = '$host') AND (xattr = 3)";
     133        $constraint = "$hostWhere AND (xattr = 3)";
    124134
    125135        &modify_hosts ($selections, $constraint, $note);
    126136    }
     137    exit 0;
    127138}
    128139
    129140my $sql = Nebulous::Server::SQL->new();
    130141my ($q, @bind);
    131 $q = $sql->get_volumes . " ORDER BY v.host, v.name";
     142
     143if (defined($host)) {
     144    if (defined($xattr)) {
     145        $q = $sql->get_volumes . " WHERE v.host = '$host' AND v.xattr = $xattr ORDER BY v.host, v.name";
     146    } else {
     147        $q = $sql->get_volumes . " WHERE v.host = '$host' ORDER BY v.host, v.name";
     148    }
     149} else {
     150    if (defined($xattr)) {
     151        $q = $sql->get_volumes . " WHERE v.xattr = $xattr ORDER BY v.host, v.name";
     152    } else {
     153        $q = $sql->get_volumes . " ORDER BY v.host, v.name";
     154    }
     155}
     156
    132157warn "$q\n" if $debug;
    133158my $query = $dbh->prepare($q);
     
    152177
    153178    my $note = $_[2];
     179    # print "NOTE: $note\n";
    154180
    155181    if (defined $note) { $selections = $selections . ", note = '$note'"; }
    156182
    157183    {
    158         my $sqlLine = "UPDATE volume SET ($selections) WHERE $constraint";
     184        my $sqlLine = "UPDATE volume SET $selections WHERE $constraint";
     185        # print "SQL: $sqlLine\n";
    159186        my $query = $dbh->prepare($sqlLine);
    160187        $query->execute() or die "error from Nebulous database\n";
     188        $dbh->commit;
    161189    }
    162190   
    163191    {
    164         my $sqlLine = "UPDATE mountedvol SET ($selections) WHERE $constraint";
     192        my $sqlLine = "UPDATE mountedvol SET $selections WHERE $constraint";
     193        # print "SQL: $sqlLine\n";
    165194        my $query = $dbh->prepare($sqlLine);
    166195        $query->execute() or die "error from Nebulous database\n";
     196        $dbh->commit;
    167197    }
    168198}
     
    184214    [--note '<status note>']
    185215    [--host <nebulous host>] [--state <up|down|repair>]
     216    [--xattr N]
    186217    [--volume]
    187218    [--dbhost <database host>] [--db <database name>]
     
    195226given, the host and state are read directly from the command line.  If nothing
    196227is specified, prints out the table of currently mounted volumes in nebulous.
     228If the state is not specified, but a host is supplied, the table of values is restricted
     229to the specified host.
    197230
    198231=head1 OPTIONS
     
    215248    repair Allocate = 0, Available = 1
    216249
     250=item * --xattr <N>
     251
     252Limit the listed volumes to the specified xattr value
     253
    217254=item * --volume
    218255
Note: See TracChangeset for help on using the changeset viewer.