Changeset 42879
- Timestamp:
- May 20, 2025, 3:38:12 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-ops-20220906/Nebulous-Server/bin/neb-host
- Property svn:mergeinfo set to (toggle deleted branches)
r41655 r42879 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, $xattr, $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 … … 54 43 'host=s' => \$host, 55 44 'state=s' => \$state, 45 'xattr=s' => \$xattr, 56 46 'note=s' => \$note, 57 47 'db=s' => \$db, … … 60 50 'dbpass=s' => \$dbpass, 61 51 'volume' => \$volume, 62 63 52 ) || pod2usage( 2 ); 64 53 65 if (($#ARGV == 1)&&(!defined($host))&&(!defined($state))) { 54 # if --host and --state are not supplied, look for positional arguments 55 my $Narg = @ARGV; 56 57 if (($Narg == 1) && (!defined($host)) && (!defined($state))) { 58 # neb-host (host) : return volume into for specified host 59 $host = shift(@ARGV); 60 } 61 if (($Narg == 2) && (!defined($host)) && (!defined($state))) { 66 62 $host = shift(@ARGV); 67 63 $state = shift(@ARGV); … … 83 79 ); 84 80 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 } 81 if (defined($host) && defined($state)) { 82 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 87 if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; } 101 88 102 my %constraint; 89 # for 'up', we want to exclude set volumes with xattr = 3, and possible issue an equivalent of 'repair' for xattr = 3 90 # for 'up' and 'repair', we should exclude volumes with xattr = 5 91 # for 'down', all volumes are ok 92 93 # up: 94 # UPDATE volume SET (allocate = 1, available = 1, note = '$note') WHERE (name = '$host') AND (xattr != 3) AND (xattr != 5) 95 # UPDATE volume SET (allocate = 0, available = 1, note = '$note') WHERE (name = '$host') AND (xattr = 3) 96 97 # repair: 98 # UPDATE volume SET (allocate = 0, available = 1, note = '$note') WHERE (name = '$host') AND (xattr != 5) 99 100 # down: 101 # UPDATE volume SET (allocate = 0, available = 0, note = '$note') WHERE (name = '$host') 102 103 # $volume is a boolean which means 'use' the supplied host as the 'name' field 104 my $hostWhere; 103 105 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 $@; 135 }106 $hostWhere = "(name = '$host')"; 107 } else { 108 $hostWhere = "(host = '$host')"; 109 } 110 111 my ($selections, $constraint); 112 113 if ($state eq 'up') { 114 $selections = "allocate = 1, available = 1"; 115 $constraint = "$hostWhere AND (xattr != 3) AND (xattr != 5)"; 116 } 117 118 if ($state eq 'repair') { 119 $selections = "allocate = 0, available = 1"; 120 $constraint = "$hostWhere AND (xattr != 5)"; 121 } 122 123 if ($state eq 'down') { 124 $selections = "allocate = 0, available = 0"; 125 $constraint = "$hostWhere"; 126 } 127 128 &modify_hosts ($selections, $constraint, $note); 129 130 ## for 'up', make a second call to set hosts with (xattr = 3) to 'repair': 131 if ($state eq 'up') { 132 $selections = "allocate = 0, available = 1"; 133 $constraint = "$hostWhere AND (xattr = 3)"; 134 135 &modify_hosts ($selections, $constraint, $note); 136 } 137 exit 0; 136 138 } 137 139 138 140 my $sql = Nebulous::Server::SQL->new(); 139 141 my ($q, @bind); 140 $q = $sql->get_volumes . " ORDER BY v.host, v.name"; 142 143 if (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 141 157 warn "$q\n" if $debug; 142 158 my $query = $dbh->prepare($q); … … 152 168 $$row{ 'note' } = '-'; 153 169 } 154 155 170 printf($format, @$row{@columns}); 156 171 } 157 172 173 sub modify_hosts { 174 175 my $selections = $_[0]; 176 my $constraint = $_[1]; 177 178 my $note = $_[2]; 179 # print "NOTE: $note\n"; 180 181 if (defined $note) { $selections = $selections . ", note = '$note'"; } 182 183 { 184 my $sqlLine = "UPDATE volume SET $selections WHERE $constraint"; 185 # print "SQL: $sqlLine\n"; 186 my $query = $dbh->prepare($sqlLine); 187 $query->execute() or die "error from Nebulous database\n"; 188 $dbh->commit; 189 } 190 191 { 192 my $sqlLine = "UPDATE mountedvol SET $selections WHERE $constraint"; 193 # print "SQL: $sqlLine\n"; 194 my $query = $dbh->prepare($sqlLine); 195 $query->execute() or die "error from Nebulous database\n"; 196 $dbh->commit; 197 } 198 } 199 200 158 201 __END__ 202 203 159 204 160 205 =pod … … 169 214 [--note '<status note>'] 170 215 [--host <nebulous host>] [--state <up|down|repair>] 216 [--xattr N] 171 217 [--volume] 172 218 [--dbhost <database host>] [--db <database name>] … … 180 226 given, the host and state are read directly from the command line. If nothing 181 227 is specified, prints out the table of currently mounted volumes in nebulous. 228 If the state is not specified, but a host is supplied, the table of values is restricted 229 to the specified host. 182 230 183 231 =head1 OPTIONS … … 200 248 repair Allocate = 0, Available = 1 201 249 250 =item * --xattr <N> 251 252 Limit the listed volumes to the specified xattr value 253 202 254 =item * --volume 203 255
Note:
See TracChangeset
for help on using the changeset viewer.
