r4532 support for mounting zero-U objects (#173)
authorAaron Dummer <aaron@dummer.info>
Tue, 31 May 2011 01:31:52 +0000 (01:31 +0000)
committerAaron Dummer <aaron@dummer.info>
Tue, 31 May 2011 01:31:52 +0000 (01:31 +0000)
ChangeLog
wwwroot/inc/database.php
wwwroot/inc/interface.php
wwwroot/inc/ophandlers.php

index 359b420..a9682bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
        update: markup IPv6 subnet-router on request (by Jens Weibler)
        update: convert racks and rows into objects (by Aaron Dummer)
        update: {$runs_8021Q} works for IPv4/IPv6 networks
+       update: support for mounting zero-U objects (#173, by Aaron Dummer)
        new feature: you can obtain who has made tag assignment, object's ports or IPv4 address changes by hovering cursor on these entities
        new feature: ability to open a terminal session to a device by clicking on its FQDN
        new feature: inverting tags on cell filter pages by clicking the checkboxes with Ctrl key
index 87f17ae..7c2c534 100644 (file)
@@ -269,8 +269,13 @@ function getMountInfo ($object_ids)
                'FROM RackSpace ' .
                'WHERE object_id IN(' . questionMarks (count ($object_ids)) . ') ' .
                'GROUP BY object_id, rack_id ' .
+               'UNION ' .
+               'SELECT child_entity_id AS object_id, parent_entity_id AS rack_id ' .
+               'FROM EntityLink ' .
+               'WHERE child_entity_id IN(' . questionMarks (count ($object_ids)) . ') ' .
+               "AND parent_entity_type = 'rack' AND child_entity_type = 'object' " .
                'ORDER BY rack_id ASC',
-               $object_ids
+               array_merge($object_ids, $object_ids)
        );
        $rackidlist = $objectlist = array();
        foreach ($result as $row)
@@ -818,14 +823,19 @@ function getEntityRelatives ($type, $entity_type, $entity_id)
        foreach ($rows as $row)
        {
                // get info of the relative (only objects supported now, others may be added later)
+               $relative = spotEntity ($row['entity_type'], $row['entity_id']);
                switch ($row['entity_type'])
                {
                        case 'object':
                                $page = 'object';
                                $id_name = 'object_id';
-                               $relative = spotEntity ($row['entity_type'], $row['entity_id']);
                                $name = $relative['dname'];
                                break;
+                       case 'rack':
+                               $page = 'rack';
+                               $id_name = 'rack_id';
+                               $name = $relative['name'];
+                               break;
                }
 
                // name needs to have some value for hrefs to work
@@ -869,7 +879,22 @@ function commitUpdateEntityLink ($link_id, $parent_entity_type, $parent_entity_i
        );
 }
 
-function commitUnlinkEntities ($link_id)
+function commitUnlinkEntities ($parent_entity_type, $parent_entity_id, $child_entity_type, $child_entity_id)
+{
+       usePreparedDeleteBlade
+       (
+               'EntityLink',
+               array
+               (
+                       'parent_entity_type' => $parent_entity_type,
+                       'parent_entity_id' => $parent_entity_id,
+                       'child_entity_type' => $child_entity_type,
+                       'child_entity_id' => $child_entity_id
+               )
+       );
+}
+
+function commitUnlinkEntitiesByLinkID ($link_id)
 {
        usePreparedDeleteBlade ('EntityLink', array ('id' => $link_id));
 }
@@ -1235,7 +1260,13 @@ function getOperationMolecules ($op_id = 0)
 
 function getResidentRacksData ($object_id = 0, $fetch_rackdata = TRUE)
 {
-       $result = usePreparedSelectBlade ('SELECT DISTINCT rack_id FROM RackSpace WHERE object_id = ? ORDER BY rack_id', array ($object_id));
+       // Include racks that the object is directly mounted in,
+       // as well as racks that is 'Zero-U' mounted in
+       $result = usePreparedSelectBlade (
+               'SELECT rack_id FROM RackSpace WHERE object_id = ? ' .
+               'UNION ' .
+               "SELECT parent_entity_id AS rack_id FROM EntityLink where parent_entity_type = 'rack' AND child_entity_type = 'object' AND child_entity_id = ?" .
+               'ORDER BY rack_id', array ($object_id, $object_id));
        $rows = $result->fetchAll (PDO::FETCH_NUM);
        unset ($result);
        $ret = array();
index 6726186..0ae990d 100644 (file)
@@ -441,6 +441,33 @@ function renderRow ($row_id)
        echo "</td></tr></table>";
 }
 
+// Used by renderRack()
+function printObjectDetailsForRenderRack ($object_id)
+{
+       $objectData = spotEntity ('object', $object_id);
+       if (strlen ($objectData['asset_no']))
+               $prefix = "<div title='${objectData['asset_no']}";
+       else
+               $prefix = "<div title='no asset tag";
+       // Don't tell about label, if it matches common name.
+       $body = '';
+       if ($objectData['name'] != $objectData['label'] and strlen ($objectData['label']))
+               $body = ", visible label is \"${objectData['label']}\"";
+       // Display list of child objects, if any
+       $objectChildren = getEntityRelatives ('children', 'object', $objectData['id']);
+       if (count($objectChildren) > 0)
+       {
+               foreach ($objectChildren as $child)
+                       $childNames[] = $child['name'];
+               natsort($childNames);
+               $suffix = sprintf(", contains %s'>", implode(', ', $childNames));
+       }
+       else
+               $suffix = "'>";
+       echo $prefix . $body . $suffix;
+       echo "<a href='".makeHref(array('page'=>'object', 'object_id'=>$objectData['id']))."'>${objectData['dname']}</a></div>";
+}
+
 // This function renders rack as HTML table.
 function renderRack ($rack_id, $hl_obj_id = 0)
 {
@@ -493,28 +520,7 @@ function renderRack ($rack_id, $hl_obj_id = 0)
                        switch ($state)
                        {
                                case 'T':
-                                       $objectData = spotEntity ('object', $rackData[$i][$locidx]['object_id']);
-                                       if (strlen ($objectData['asset_no']))
-                                               $prefix = "<div title='${objectData['asset_no']}";
-                                       else
-                                               $prefix = "<div title='no asset tag";
-                                       // Don't tell about label, if it matches common name.
-                                       $body = '';
-                                       if ($objectData['name'] != $objectData['label'] and strlen ($objectData['label']))
-                                               $body = ", visible label is \"${objectData['label']}\"";
-                                       // Display list of child objects, if any
-                                       $objectChildren = getEntityRelatives ('children', 'object', $objectData['id']);
-                                       if (count($objectChildren) > 0)
-                                       {
-                                               foreach ($objectChildren as $child)
-                                                       $childNames[] = $child['name'];
-                                               natsort($childNames);
-                                               $suffix = sprintf(", contains %s'>", implode(', ', $childNames));
-                                       }
-                                       else
-                                               $suffix = "'>";
-                                       echo $prefix . $body . $suffix;
-                                       echo "<a href='".makeHref(array('page'=>'object', 'object_id'=>$objectData['id']))."'>${objectData['dname']}</a></div>";
+                                       printObjectDetailsForRenderRack($rackData[$i][$locidx]['object_id']);
                                        break;
                                case 'A':
                                        echo '<div title="This rackspace does not exist">&nbsp;</div>';
@@ -533,7 +539,22 @@ function renderRack ($rack_id, $hl_obj_id = 0)
                }
                echo "</tr>\n";
        }
-       echo "</table></center>\n";
+       echo "</table>\n";
+       // Get a list of all of objects Zero-U mounted to this rack
+       $zeroUObjects = getEntityRelatives('children', 'rack', $rack_id);
+       if (count($zeroUObjects) > 0) {
+               echo "<br><table width='75%' class=rack border=0 cellspacing=0 cellpadding=1>\n";
+               echo "<tr><th>Zero-U:</th></tr>\n";
+               foreach ($zeroUObjects as $zeroUObject)
+               {
+                       $state = ($zeroUObject['entity_id'] == $hl_obj_id) ? 'Th' : 'T';
+                       echo "<tr><td class='atom state_${state}'>";
+                       printObjectDetailsForRenderRack($zeroUObject['entity_id']);
+                       echo "</td></tr>\n";
+               }
+               echo "</table>\n";
+       }
+       echo "</center>\n";
 }
 
 function renderNewRackForm ($row_id)
@@ -1686,6 +1707,14 @@ function renderRackSpaceForObject ($object_id)
                                $workingRacksData[$cand_id] = $rackData;
                        }
 
+       // Get a list of all of this object's parents,
+       // then trim the list to only include parents which are racks
+       $objectParents = getEntityRelatives('parents', 'object', $object_id);
+       $parentRacks = array();
+       foreach ($objectParents as $parentData)
+               if ($parentData['entity_type'] == 'rack')
+                       $parentRacks[] = $parentData['entity_id'];
+
        // Main layout starts.
        echo "<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>";
 
@@ -1776,8 +1805,15 @@ function renderRackSpaceForObject ($object_id)
                echo "<th width='20%'><a href='javascript:;' oncontextmenu=\"blockToggleColumnOfAtoms('${rack_id}', '0', ${rackData['height']}); return false;\" onclick=\"toggleColumnOfAtoms('${rack_id}', '0', ${rackData['height']})\">Front</a></th>";
                echo "<th width='50%'><a href='javascript:;' oncontextmenu=\"blockToggleColumnOfAtoms('${rack_id}', '1', ${rackData['height']}); return false;\" onclick=\"toggleColumnOfAtoms('${rack_id}', '1', ${rackData['height']})\">Interior</a></th>";
                echo "<th width='20%'><a href='javascript:;' oncontextmenu=\"blockToggleColumnOfAtoms('${rack_id}', '2', ${rackData['height']}); return false;\" onclick=\"toggleColumnOfAtoms('${rack_id}', '2', ${rackData['height']})\">Back</a></th></tr>\n";
-               echo "</table></center>\n";
-               echo '</td>';
+               echo "</table>\n<br>\n";
+               // Determine zero-u checkbox status.
+               // If form has been submitted, use form data, otherwise use DB data.
+               if (isset($_REQUEST['op'])) 
+                       $checked = isset($_REQUEST['zerou_'.$rack_id]) ? 'checked' : '';
+               else
+                       $checked = in_array($rack_id, $parentRacks) ? 'checked' : '';
+               echo "Zero-U: <input type=checkbox ${checked} name=zerou_${rack_id} id=zerou_${rack_id}>";
+               echo '</center></td>';
        }
        echo "</tr></table>";
        finishPortlet();
@@ -9014,7 +9050,7 @@ function formatIfTypeVariants ($variants, $select_name)
                if (isTranceiverEmpty ($item['left']['portinfo']))
                {
                        $creting_tranceivers = TRUE;
-                       $text = ' ' . $text;
+                       $text = 'â†� ' . $text;
                        $params['a_oif'] = $item['left']['id'];
                        if (isset ($oif_usage_stat[$item['left']['id']]))
                                $popularity_count += $oif_usage_stat[$item['left']['id']];
@@ -9022,7 +9058,7 @@ function formatIfTypeVariants ($variants, $select_name)
                if (isTranceiverEmpty ($item['right']['portinfo']))
                {
                        $creting_tranceivers = TRUE;
-                       $text = $text . ' ';
+                       $text = $text . ' â†’';
                        $params['b_oif'] = $item['right']['id'];
                        if (isset ($oif_usage_stat[$item['right']['id']]))
                                $popularity_count += $oif_usage_stat[$item['right']['id']];
@@ -9043,7 +9079,7 @@ function formatIfTypeVariants ($variants, $select_name)
        if ($creting_tranceivers and ! $tranceivers_hint_shown)
        {
                $tranceivers_hint_shown = TRUE;
-               showNotice ('The arrow (← or →) means to create a tranceiver in the suitable port');
+               showNotice ('The arrow (â†� or â†’) means to create a tranceiver in the suitable port');
        }
 
        return getSelect ($select, array('name' => $select_name), $selected_key, !$creting_tranceivers);
index 6c67f39..9982212 100644 (file)
@@ -1004,6 +1004,14 @@ function updateObjectAllocation ()
                return buildRedirectURL (NULL, NULL, $_REQUEST);
        }
        $object_id = getBypassValue();
+       $changecnt = 0;
+       // Get a list of all of this object's parents,
+       // then trim the list to only include parents which are racks
+       $objectParents = getEntityRelatives('parents', 'object', $object_id);
+       $parentRacks = array();
+       foreach ($objectParents as $parentData)
+               if ($parentData['entity_type'] == 'rack')
+                       $parentRacks[] = $parentData['entity_id'];
        $workingRacksData = array();
        foreach ($_REQUEST['rackmulti'] as $cand_id)
        {
@@ -1013,13 +1021,24 @@ function updateObjectAllocation ()
                        amplifyCell ($rackData);
                        $workingRacksData[$cand_id] = $rackData;
                }
+               // It's zero-U mounted to this rack on the form, but not in the DB.  Mount it.
+               if (isset($_REQUEST["zerou_${cand_id}"]) && !in_array($cand_id, $parentRacks))
+               {
+                       $changecnt++;
+                       commitLinkEntities ('rack', $cand_id, 'object', $object_id);
+               }
+               // It's not zero-U mounted to this rack on the form, but it is in the DB.  Unmount it.
+               if (!isset($_REQUEST["zerou_${cand_id}"]) && in_array($cand_id, $parentRacks))
+               {
+                       $changecnt++;
+                       commitUnlinkEntities ('rack', $cand_id, 'object', $object_id);
+               }
        }
 
        foreach ($workingRacksData as &$rd)
                applyObjectMountMask ($rd, $object_id);
 
        $oldMolecule = getMoleculeForObject ($object_id);
-       $changecnt = 0;
        foreach ($workingRacksData as $rack_id => $rackData)
        {
                if (! processGridForm ($rackData, 'F', 'T', $object_id))
@@ -1973,7 +1992,7 @@ $msgcode['unlinkEntities']['OK'] = 49;
 function unlinkEntities ()
 {
        assertUIntArg ('link_id');
-       commitUnlinkEntities ($_REQUEST['link_id']);
+       commitUnlinkEntitiesByLinkID ($_REQUEST['link_id']);
        return showFuncMessage (__FUNCTION__,  'OK');
 }