diff --git a/xCAT-web/machines/discover.php b/xCAT-web/machines/discover.php index b78060dae..59f1dd4b9 100644 --- a/xCAT-web/machines/discover.php +++ b/xCAT-web/machines/discover.php @@ -49,13 +49,29 @@ function expandNR($nr) { // see pping as an example of the client/server for noderange expansion $a = array(); if (empty($nr)) return $a; + +// Check for square bracket range +$parts = array(); +if (preg_match('/(.*?)\[(.*?)\](.*)/',$nr,$parts)) { + $range = preg_split('/([\-\:])/', $parts[2]); + if (count($range) < 2) { msg('E', "Invalid node range: $parts[2]"); return $a; } // ill-formed range + $numlen = strlen($range[0]); + for ($i=$range[0]; $i<=$range[1]; $i++) { + $istr = "$i"; + if (strlen($istr) < $numlen) { $istr = substr('000000',0,$numlen-strlen($istr)) . $istr; } + $a = array_merge($a, expandNR("$parts[1]$istr$parts[3]")); + } + return $a; +} + +// Check for range with dash if (strpos($nr,'-')===FALSE) { $a[] = $nr; return $a; } // a single node list($begin, $end) = explode('-', $nr); $begParts = array(); -if (!preg_match('/^(\D+)(\d+)$/', $begin, $begParts)) { msg('E',"Error in noderange syntax: $nr"); return NULL; } +if (!preg_match('/^(\D+)(\d+)$/', $begin, $begParts)) { $a[] = $nr; return $a; } // a single node $endParts = array(); -if (!preg_match('/^(\D+)(\d+)$/', $end, $endParts)) { msg('E',"Error in noderange syntax: $nr"); return NULL; } -if ($begParts[1] != $endParts[1]) { msg('E',"Error in noderange syntax: $nr"); return NULL; } +if (!preg_match('/^(\D+)(\d+)$/', $end, $endParts)) { $a[] = $nr; return $a; } // a single node +if ($begParts[1] != $endParts[1]) { $a[] = $nr; return $a; } // a single node $numlen = strlen($begParts[2]); for ($i=$begParts[2]; $i<=$endParts[2]; $i++) { $istr = "$i"; @@ -99,6 +115,7 @@ echo "