Commit b9bc3a5e authored by Robert Ricci's avatar Robert Ricci

Use card numbers rather than iface names.

Provide a way to re-number interfaces, in case the MFS discovers
them in something other than the preffered (ie. Linux) order.

Use the switch class from showmac to avoid problems where there is
leakage between the control and experimental net, so we see a MAC
on both.

Fix a dumb php bug - can you beleive the in_array() function wasn't
in php3?
parent 0f7a6de1
......@@ -11,7 +11,7 @@
# node-adding page.
#
function find_switch_macs($mac_list) {
function find_switch_macs(&$mac_list) {
global $uid, $gid, $TBSUEXEC_PATH;
......@@ -25,25 +25,30 @@ function find_switch_macs($mac_list) {
#
# XXX - error checking
#
$line = fgets($macs);
while (!feof($macs)) {
$line = fgets($macs);
$line = rtrim($line);
$exploded = explode(",",$line);
$MAC = $exploded[0];
$switchport = $exploded[1];
$vlan = $exploded[2];
$iface = $exploded[3];
$class = $exploded[4];
if (!preg_match("/^([\w-]+)\/(\d+)\.(\d+)$/",$switchport,$matches)) {
echo "<h3>Bad line from switchmac: $line\n";
return 0;
}
$switch = $matches[0];
$card = $matches[1];
$port = $matches[2];
if (in_array($MAC,$mac_list)) {
$switch = $matches[1];
$card = $matches[2];
$port = $matches[3];
echo "Class is ($class), (" . $mac_list[$MAC]["class"] . ")";
if ($mac_list[$MAC] && (!$mac_list[$MAC]["class"] ||
($mac_list[$MAC]["class"] == $class))) {
$mac_list[$MAC]["switch"] = $switch;
$mac_list[$MAC]["card"] = $card;
$mac_list[$MAC]["port"] = $port;
$mac_list[$MAC]["switch_card"] = $card;
$mac_list[$MAC]["switch_port"] = $port;
}
$line = fgets($macs);
}
pclose($macs);
......
......@@ -43,17 +43,17 @@ if ($node_id) {
# Same for interface update information
#
foreach ($HTTP_GET_VARS as $key => $value) {
if (preg_match("/iface(\w+)_mac/",$key,$matches)) {
$iface = $matches[1];
$mac = $HTTP_GET_VARS["iface${iface}_mac"];
$type = $HTTP_GET_VARS["iface${iface}_type"];
$switch_id = $HTTP_GET_VARS["iface${iface}_switch_id"];
$switch_card = $HTTP_GET_VARS["iface${iface}_switch_card"];
$switch_port = $HTTP_GET_VARS["iface${iface}_switch_port"];
if (preg_match("/iface(\d+)_mac/",$key,$matches)) {
$card = $matches[1];
$mac = $HTTP_GET_VARS["iface${card}_mac"];
$type = $HTTP_GET_VARS["iface${card}_type"];
$switch_id = $HTTP_GET_VARS["iface${card}_switch_id"];
$switch_card = $HTTP_GET_VARS["iface${card}_switch_card"];
$switch_port = $HTTP_GET_VARS["iface${card}_switch_port"];
DBQueryFatal("UPDATE new_interfaces SET mac='$mac', " .
"interface_type='$type', switch_id='$switch_id', " .
"switch_card='$switch_card', switch_port='$switch_port' " .
"WHERE new_node_id=$id AND iface='$iface'");
"WHERE new_node_id=$id AND card='$card'");
}
}
......@@ -127,26 +127,26 @@ $row = mysql_fetch_array($query_result)
<?
$query_result = DBQueryFatal("SELECT iface, mac, interface_type, switch_id, " .
$query_result = DBQueryFatal("SELECT card, mac, interface_type, switch_id, " .
"switch_card, switch_port FROM new_interfaces where new_node_id=$id");
while ($row = mysql_fetch_array($query_result)) {
$iface = $row['iface'];
$card = $row['card'];
$mac = $row['mac'];
$type = $row['interface_type'];
$switch_id = $row['switch_id'];
$switch_card = $row['switch_card'];
$switch_port = $row['switch_port'];
echo "<tr>\n";
echo "<td>$iface</td>\n";
echo "<td><input type='text' name='iface${iface}_mac' size=12 " .
echo "<td>$card</td>\n";
echo "<td><input type='text' name='iface${card}_mac' size=12 " .
"value='$mac'></td>\n";
echo "<td><input type='text' name='iface${iface}_type' size=5 " .
echo "<td><input type='text' name='iface${card}_type' size=5 " .
"value='$type'></td>\n";
echo "<td><input type='text' name='iface${iface}_switch_id' size=10 " .
echo "<td><input type='text' name='iface${card}_switch_id' size=10 " .
"value='$switch_id'></td>\n";
echo "<td><input type='text' name='iface${iface}_switch_card' size=3 " .
echo "<td><input type='text' name='iface${card}_switch_card' size=3 " .
"value='$switch_card'></td>\n";
echo "<td><input type='text' name='iface${iface}_switch_port' size=3 " .
echo "<td><input type='text' name='iface${card}_switch_port' size=3 " .
"value='$switch_port'></td>\n";
echo "</tr>\n";
}
......
......@@ -114,26 +114,35 @@ if ($research) {
# Get the MACs we're supposed to be looking for
#
$query_result = DBQueryFatal("SELECT i.mac, i.new_node_id, n.node_id, " .
"i.iface FROM new_interfaces as i LEFT JOIN new_nodes as n " .
"ON i.new_node_id = n.new_node_id WHERE $whereclause_qualified");
"i.card, i.card=t.control_net AS is_control " .
"FROM new_interfaces as i LEFT JOIN new_nodes as n " .
"ON i.new_node_id = n.new_node_id " .
"LEFT JOIN node_types as t on n.type = t.type " .
"WHERE $whereclause_qualified");
$mac_list = array();
while ($row = mysql_fetch_array($query_result)) {
if ($row["is_control"]) {
$class = "control";
} else {
$class = "experimental";
}
$mac_list[$row["mac"]] = array( "new_node_id" => $row["new_node_id"],
"node_id" => $row["node_id"], "iface" => $row["iface"]);
"node_id" => $row["node_id"], "card" => $row["card"],
"class" => $class);
}
echo "<h3>Looking for MACs, this could take a while...</h3>";
find_switch_macs($mac_list);
foreach ($mac_list as $mac => $switchport) {
if (in_array("switch",$switchport)) {
if ($switchport["switch"]) {
DBQueryFatal("UPDATE new_interfaces SET " .
"switch_id='$switchport[switch]', " .
"switch_card='$switchport[card]', " .
"switch_port='$switchport[port]', ".
"switch_card='$switchport[switch_card]', " .
"switch_port='$switchport[switch_port]' ".
"WHERE new_node_id='$switchport[new_node_id]' " .
"AND iface='$switchport[iface]'");
"AND card=$switchport[card]");
} else {
echo "<h4>Unable to find $switchport[node_id]:$switchport[iface] " .
echo "<h4>Unable to find $switchport[node_id]:$switchport[card] " .
"on switches, not updating</h4>\n";
}
}
......@@ -200,13 +209,42 @@ if ($newprefix || $addnumber) {
}
}
#
# Re-number interfaces
#
if ($renumber) {
#
# Move them out of the way
#
foreach ($remap as $index => $value) {
if ($value != "") {
DBQueryFatal("UPDATE new_interfaces SET card = card + 100 WHERE " .
"card = $index AND ($whereclause)");
}
}
#
# Move them back to the correct location
#
foreach ($remap as $index => $value) {
if ($value != "") {
DBQueryFatal("UPDATE new_interfaces SET card = $value WHERE " .
"card = " . ($index + 100) . " AND ($whereclause)");
}
}
}
#
# Okay, now get the node information and display the form
#
$query_result = DBQueryFatal("SELECT n.new_node_id, node_id, n.type, IP, " .
"DATE_FORMAT(created,'%M %e %H:%i:%s') as created, i.MAC, " .
"i.switch_id, i.switch_card, i.switch_port " .
"FROM new_nodes AS n " .
"LEFT JOIN node_types AS t on n.type=t.type " .
"LEFT JOIN new_interfaces AS i ON n.new_node_id=i.new_node_id " .
" AND t.control_iface = i.iface " .
" AND t.control_net = i.card " .
"ORDER BY n.new_node_id");
?>
......@@ -290,13 +328,8 @@ while ($row = mysql_fetch_array($query_result)) {
</table>
<br>
<center>
<table>
<tr>
<td colspan=2 align="center"><b>Actions</b></th>
</tr>
<table>
<tr>
<th>Set Type</th>
<td><input type="text" width="10" name="newtype"></td>
......@@ -317,35 +350,50 @@ while ($row = mysql_fetch_array($query_result)) {
<input type="submit" value="Update selected nodes" name="submit">
</td>
</tr>
</table>
<br><br>
<table>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Recalculate IPs for selected nodes" name="calc">
</td>
<th>0</th>
<td><input type="text" size=2 name="remap[0]"></td>
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Swap Node IDs and IPs for selected nodes" name="swap">
</td>
<th>1</th>
<td><input type="text" size=2 name="remap[1]"></td>
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Re-search switches for selected nodes" name="research">
</td>
<th>2</th>
<td><input type="text" size=2 name="remap[2]"></td>
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Create selected nodes" name="create">
&nbsp;
<input type="submit" value="Delete selected nodes" name="delete">
<th>3</th>
<td><input type="text" size=2 name="remap[3]"></td>
</tr>
<tr>
<th>4</th>
<td><input type="text" size=2 name="remap[4]"></td>
</tr>
<tr>
<td colspan=2>
<input type="submit" value="Re-number interfaces of selected nodes"
name="renumber">
</td>
</tr>
</table>
</center>
<br><br>
<input type="submit" value="Recalculate IPs for selected nodes" name="calc">
<br><br>
<input type="submit" value="Swap Node IDs and IPs for selected nodes" name="swap">
<br><br>
<input type="submit" value="Re-search switches for selected nodes" name="research">
<br><br>
<input type="submit" value="Create selected nodes" name="create">
<br><br>
<input type="submit" value="Delete selected nodes" name="delete">
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment