Changeset 42866
- Timestamp:
- May 19, 2025, 12:20:20 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/neb-host-20250516/bin/neb-host
r42865 r42866 16 16 use Pod::Usage qw( pod2usage ); 17 17 18 my ($host, $state, $ note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume);18 my ($host, $state, $xattr, $note, $db, $dbhost, $dbpass, $dbuser, $debug, $volume); 19 19 20 20 # $db = $ENV{'NEB_DB'} unless $db; … … 43 43 'host=s' => \$host, 44 44 'state=s' => \$state, 45 'xattr=s' => \$xattr, 45 46 'note=s' => \$note, 46 47 'db=s' => \$db, … … 52 53 53 54 # 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))) { 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))) { 56 62 $host = shift(@ARGV); 57 63 $state = shift(@ARGV); … … 75 81 if (defined($host) && defined($state)) { 76 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 77 87 if (($state ne 'up') && ($state ne 'down') && ($state ne 'repair')) { die "Unknown state '$state'"; } 78 88 … … 103 113 if ($state eq 'up') { 104 114 $selections = "allocate = 1, available = 1"; 105 $constraint = " (name = '$host')AND (xattr != 3) AND (xattr != 5)";115 $constraint = "$hostWhere AND (xattr != 3) AND (xattr != 5)"; 106 116 } 107 117 108 118 if ($state eq 'repair') { 109 119 $selections = "allocate = 0, available = 1"; 110 $constraint = " (name = '$host')AND (xattr != 5)";120 $constraint = "$hostWhere AND (xattr != 5)"; 111 121 } 112 122 113 123 if ($state eq 'down') { 114 124 $selections = "allocate = 0, available = 0"; 115 $constraint = " (name = '$host')";125 $constraint = "$hostWhere"; 116 126 } 117 127 … … 121 131 if ($state eq 'up') { 122 132 $selections = "allocate = 0, available = 1"; 123 $constraint = " (name = '$host')AND (xattr = 3)";133 $constraint = "$hostWhere AND (xattr = 3)"; 124 134 125 135 &modify_hosts ($selections, $constraint, $note); 126 136 } 137 exit 0; 127 138 } 128 139 129 140 my $sql = Nebulous::Server::SQL->new(); 130 141 my ($q, @bind); 131 $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 132 157 warn "$q\n" if $debug; 133 158 my $query = $dbh->prepare($q); … … 152 177 153 178 my $note = $_[2]; 179 # print "NOTE: $note\n"; 154 180 155 181 if (defined $note) { $selections = $selections . ", note = '$note'"; } 156 182 157 183 { 158 my $sqlLine = "UPDATE volume SET ($selections) WHERE $constraint"; 184 my $sqlLine = "UPDATE volume SET $selections WHERE $constraint"; 185 # print "SQL: $sqlLine\n"; 159 186 my $query = $dbh->prepare($sqlLine); 160 187 $query->execute() or die "error from Nebulous database\n"; 188 $dbh->commit; 161 189 } 162 190 163 191 { 164 my $sqlLine = "UPDATE mountedvol SET ($selections) WHERE $constraint"; 192 my $sqlLine = "UPDATE mountedvol SET $selections WHERE $constraint"; 193 # print "SQL: $sqlLine\n"; 165 194 my $query = $dbh->prepare($sqlLine); 166 195 $query->execute() or die "error from Nebulous database\n"; 196 $dbh->commit; 167 197 } 168 198 } … … 184 214 [--note '<status note>'] 185 215 [--host <nebulous host>] [--state <up|down|repair>] 216 [--xattr N] 186 217 [--volume] 187 218 [--dbhost <database host>] [--db <database name>] … … 195 226 given, the host and state are read directly from the command line. If nothing 196 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. 197 230 198 231 =head1 OPTIONS … … 215 248 repair Allocate = 0, Available = 1 216 249 250 =item * --xattr <N> 251 252 Limit the listed volumes to the specified xattr value 253 217 254 =item * --volume 218 255
Note:
See TracChangeset
for help on using the changeset viewer.
