Changeset 42865
- Timestamp:
- May 16, 2025, 2:22:13 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/neb-host-20250516/bin/neb-host
r41655 r42865 16 16 use Pod::Usage qw( pod2usage ); 17 17 18 my ($host, $state, $note, 19 $db, $dbhost, $dbpass, $dbuser, 20 $allocate, $available, $debug,$volume); 18 my ($host, $state, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume); 21 19 22 20 # $db = $ENV{'NEB_DB'} unless $db; … … 25 23 # $dbpass = $ENV{'NEB_PASS'} unless $dbpass; 26 24 27 # my $conffile = "/data/ippc64.1/ippitc/ippconfig/nebulous.config";28 25 # my $conffile = "/home/panstarrs/ipp/ippconfig/nebulous.config"; 29 26 my $conffile = "/home/panstarrs/ippps1/ippconfig/nebulous.config"; 30 27 31 28 if (-e $conffile) { 32 #printf STDERR "found config\n";29 # printf STDERR "found config\n"; 33 30 open(IN,$conffile); 34 31 while(<IN>) { 35 32 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; } 48 37 } 49 38 close(IN); 50 #print STDERR "$db $dbhost $dbuser $dbpass\n";39 # print STDERR "$db $dbhost $dbuser $dbpass\n"; 51 40 } 52 41 … … 60 49 'dbpass=s' => \$dbpass, 61 50 'volume' => \$volume, 62 63 51 ) || pod2usage( 2 ); 64 52 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? 55 if (($#ARGV == 1) && (!defined($host)) && (!defined($state))) { 66 56 $host = shift(@ARGV); 67 57 $state = shift(@ARGV); … … 83 73 ); 84 74 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 } 75 if (defined($host) && defined($state)) { 76 77 if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; } 101 78 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; 103 95 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); 135 126 } 136 127 } … … 152 143 $$row{ 'note' } = '-'; 153 144 } 154 155 145 printf($format, @$row{@columns}); 156 146 } 157 147 148 sub 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 158 171 __END__ 172 173 159 174 160 175 =pod
Note:
See TracChangeset
for help on using the changeset viewer.
