Example #1
0
function updateObjectAllocation()
{
    global $remote_username, $sic;
    if (!isset($_REQUEST['got_atoms'])) {
        unset($_GET['page']);
        unset($_GET['tab']);
        unset($_GET['op']);
        unset($_POST['page']);
        unset($_POST['tab']);
        unset($_POST['op']);
        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 that 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) {
        if (!isset($workingRacksData[$cand_id])) {
            $rackData = spotEntity('rack', $cand_id);
            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);
    foreach ($workingRacksData as $rack_id => $rackData) {
        if (!processGridForm($rackData, 'F', 'T', $object_id)) {
            continue;
        }
        $changecnt++;
        // Reload our working copy after form processing.
        $rackData = spotEntity('rack', $cand_id);
        amplifyCell($rackData);
        applyObjectMountMask($rackData, $object_id);
        $workingRacksData[$rack_id] = $rackData;
    }
    if ($changecnt) {
        // Log a record.
        $newMolecule = getMoleculeForObject($object_id);
        usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment']));
    }
    showFuncMessage(__FUNCTION__, 'OK', array($changecnt));
}
Example #2
0
File: api.php Project: xtha/salt
     //    UI handler: updateObjectAllocation()
 // update where an object is installed in rackspace
 //    UI equivalent: submitting form at /index.php?page=object&tab=rackspace&object_id=1013
 //    UI handler: updateObjectAllocation()
 case 'update_object_allocation':
     require_once 'inc/init.php';
     assertUIntArg('object_id');
     $object_id = $_REQUEST['object_id'];
     global $remote_username, $loclist, $dbxlink;
     $zeroURacksOld = array();
     $allocationsOld = array();
     $zeroURacksNew = array();
     $allocationsNew = array();
     $changecnt = 0;
     // determine current zero-u allocations
     foreach (getEntityRelatives('parents', 'object', $object_id) as $parentData) {
         if ($parentData['entity_type'] == 'rack') {
             // this is exactly as in updateObjectAllocation(), but it means there can
             // only ever be one rack that an object is zero-U mounted in
             $zeroURacksOld[] = $parentData['entity_id'];
         }
     }
     // determine current "normal" allocations
     foreach (array_keys(getResidentRacksData($object_id)) as $rack_id) {
         $allocationsOld[] = $rack_id;
     }
     // get the object's new allocations from the request parameters (might not be any)
     if (isset($_REQUEST['allocate_to'])) {
         foreach ($_REQUEST['allocate_to'] as $allocation) {
             // zero-U
             if (preg_match('/^zerou_(\\d+)$/', $allocation, $matches)) {
Example #3
0
function renderRackSpaceForObject($object_id)
{
    // Always process occupied racks plus racks chosen by user. First get racks with
    // already allocated rackspace...
    $workingRacksData = getResidentRacksData($object_id);
    // ...and then add those chosen by user (if any).
    if (isset($_REQUEST['rackmulti'])) {
        foreach ($_REQUEST['rackmulti'] as $cand_id) {
            if (!isset($workingRacksData[$cand_id])) {
                $rackData = spotEntity('rack', $cand_id);
                amplifyCell($rackData);
                $workingRacksData[$cand_id] = $rackData;
            }
        }
    }
    // Get a list of all of this object's parents,
    // then trim the list to only include parents that 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>";
    // Left portlet with rack list.
    echo "<td class=pcleft height='1%'>";
    startPortlet('Racks');
    $allRacksData = listCells('rack');
    // filter rack list to match only racks having common tags with the object (reducing $allRacksData)
    if (!isset($_REQUEST['show_all_racks']) and getConfigVar('FILTER_RACKLIST_BY_TAGS') == 'yes') {
        $matching_racks = array();
        $object = spotEntity('object', $object_id);
        $matched_tags = array();
        foreach ($allRacksData as $rack) {
            foreach ($object['etags'] as $tag) {
                if (tagOnChain($tag, $rack['etags']) or tagOnChain($tag, $rack['itags'])) {
                    $matching_racks[$rack['id']] = $rack;
                    $matched_tags[$tag['id']] = $tag;
                    break;
                }
            }
        }
        // add current object's racks even if they dont match filter
        foreach ($workingRacksData as $rack_id => $rack) {
            if (!isset($matching_racks[$rack_id])) {
                $matching_racks[$rack_id] = $rack;
            }
        }
        // if matching racks found, and rack list is reduced, show 'show all' link
        if (count($matching_racks) and count($matching_racks) != count($allRacksData)) {
            $filter_text = '';
            foreach ($matched_tags as $tag) {
                $filter_text .= (empty($filter_text) ? '' : ' or ') . '{' . $tag['tag'] . '}';
            }
            $href_show_all = trim($_SERVER['REQUEST_URI'], '&');
            $href_show_all .= htmlspecialchars('&show_all_racks=1');
            echo "(filtered by <span class='filter-text'>{$filter_text}</span>, <a href='{$href_show_all}'>show all</a>)<p>";
            $allRacksData = $matching_racks;
        }
    }
    if (count($allRacksData) <= getConfigVar('RACK_PRESELECT_THRESHOLD')) {
        foreach ($allRacksData as $rack) {
            if (!array_key_exists($rack['id'], $workingRacksData)) {
                amplifyCell($rack);
                $workingRacksData[$rack['id']] = $rack;
            }
        }
    }
    foreach (array_keys($workingRacksData) as $rackId) {
        applyObjectMountMask($workingRacksData[$rackId], $object_id);
    }
    printOpFormIntro('updateObjectAllocation');
    renderRackMultiSelect('rackmulti[]', $allRacksData, array_keys($workingRacksData));
    echo "<br><br>";
    finishPortlet();
    echo "</td>";
    // Middle portlet with comment and submit.
    echo "<td class=pcleft>";
    startPortlet('Comment (for Rackspace History)');
    echo "<textarea name=comment rows=10 cols=40></textarea><br>\n";
    echo "<input type=submit value='Save' name=got_atoms>\n";
    echo "<br><br>";
    finishPortlet();
    echo "</td>";
    // Right portlet with rendered racks. If this form submit is not final, we have to
    // reflect the former state of the grid in current form.
    echo "<td class=pcright rowspan=2 height='1%'>";
    startPortlet('Working copy');
    includeJQueryUI(false);
    addJS('js/racktables.js');
    addJS('js/bulkselector.js');
    echo '<table border=0 cellspacing=10 align=center><tr>';
    foreach ($workingRacksData as $rack_id => $rackData) {
        // Order is important here: only original allocation is highlighted.
        highlightObject($rackData, $object_id);
        markupAtomGrid($rackData, 'T');
        // If we have a form processed, discard user input and show new database
        // contents.
        if (isset($_REQUEST['rackmulti'][0])) {
            // is an update
            mergeGridFormToRack($rackData);
        }
        echo "<td valign=top>";
        echo "<center>\n<h2>{$rackData['name']}</h2>\n";
        echo "<table class=rack id=selectableRack border=0 cellspacing=0 cellpadding=1>\n";
        echo "<tr><th width='10%'>&nbsp;</th>";
        echo "<th width='20%'><a href='javascript:;' onclick=\"toggleColumnOfAtoms('{$rack_id}', '0', {$rackData['height']})\">Front</a></th>";
        echo "<th width='50%'><a href='javascript:;' onclick=\"toggleColumnOfAtoms('{$rack_id}', '1', {$rackData['height']})\">Interior</a></th>";
        echo "<th width='20%'><a href='javascript:;' onclick=\"toggleColumnOfAtoms('{$rack_id}', '2', {$rackData['height']})\">Back</a></th></tr>\n";
        renderAtomGrid($rackData);
        echo "<tr><th width='10%'>&nbsp;</th>";
        echo "<th width='20%'><a href='javascript:;' onclick=\"toggleColumnOfAtoms('{$rack_id}', '0', {$rackData['height']})\">Front</a></th>";
        echo "<th width='50%'><a href='javascript:;' onclick=\"toggleColumnOfAtoms('{$rack_id}', '1', {$rackData['height']})\">Interior</a></th>";
        echo "<th width='20%'><a href='javascript:;' onclick=\"toggleColumnOfAtoms('{$rack_id}', '2', {$rackData['height']})\">Back</a></th></tr>\n";
        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 "<label for=zerou_{$rack_id}>Zero-U:</label> <input type=checkbox {$checked} name=zerou_{$rack_id} id=zerou_{$rack_id}>\n<br><br>\n";
        echo "<input type='button' onclick='uncheckAll();' value='Uncheck all'>\n";
        echo '</center></td>';
    }
    echo "</tr></table>";
    finishPortlet();
    echo "</td>\n";
    echo "</form>\n";
    echo "</tr></table>\n";
}
Example #4
0
function renderRack($rack_id, $hl_obj_id = 0)
{
    $rackData = spotEntity('rack', $rack_id);
    amplifyCell($rackData);
    markAllSpans($rackData);
    if ($hl_obj_id > 0) {
        highlightObject($rackData, $hl_obj_id);
    }
    $prev_id = getPrevIDforRack($rackData['row_id'], $rack_id);
    $next_id = getNextIDforRack($rackData['row_id'], $rack_id);
    echo "<center><table border=0><tr valign=middle>";
    echo '<td><h2>' . mkA($rackData['row_name'], 'row', $rackData['row_id']) . ' :</h2></td>';
    if ($prev_id != NULL) {
        echo '<td>' . mkA(getImageHREF('prev', 'previous rack'), 'rack', $prev_id) . '</td>';
    }
    echo '<td><h2>' . mkA($rackData['name'], 'rack', $rackData['id']) . '</h2></td>';
    if ($next_id != NULL) {
        echo '<td>' . mkA(getImageHREF('next', 'next rack'), 'rack', $next_id) . '</td>';
    }
    echo "</h2></td></tr></table>\n";
    $result = usePreparedSelectBlade("SELECT * FROM racktemperature WHERE rackid = ?", array($rack_id));
    $row = $result->fetch(PDO::FETCH_ASSOC);
    if (isset($row['top'])) {
        echo "<table align=left border=1>\n";
        echo "<tr><th>Sensor</th><th>Temperature</th></tr>\n";
        for ($i = $rackData['height']; $i > 5; $i--) {
            if ($i == 40) {
                echo "<tr><td>top</td><td>{$row['top']}</td></tr>\n";
            } else {
                if ($i == 23) {
                    echo "<tr><td>middle</td><td>{$row['middle']}</td></tr>\n";
                } else {
                    if ($i == 11) {
                        echo "<tr><td>bottom</td><td>{$row['bottom']}</td></tr>\n";
                    } else {
                        echo "<tr><td>&nbsp</td><td>&nbsp</td></tr>\n";
                    }
                }
            }
        }
        echo "</table>";
    }
    echo "<table class=rack align=center border=0 cellspacing=0 cellpadding=1>\n";
    echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
    echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
    for ($i = $rackData['height']; $i > 0; $i--) {
        echo "<tr><th>" . inverseRackUnit($i, $rackData) . "</th>";
        for ($locidx = 0; $locidx < 3; $locidx++) {
            if (isset($rackData[$i][$locidx]['skipped'])) {
                continue;
            }
            $state = $rackData[$i][$locidx]['state'];
            echo "<td class='atom state_{$state}";
            if (isset($rackData[$i][$locidx]['hl'])) {
                echo $rackData[$i][$locidx]['hl'];
            }
            echo "'";
            if (isset($rackData[$i][$locidx]['colspan'])) {
                echo ' colspan=' . $rackData[$i][$locidx]['colspan'];
            }
            if (isset($rackData[$i][$locidx]['rowspan'])) {
                echo ' rowspan=' . $rackData[$i][$locidx]['rowspan'];
            }
            echo ">";
            switch ($state) {
                case 'T':
                    printObjectDetailsForRenderRack($rackData[$i][$locidx]['object_id'], $hl_obj_id);
                    break;
                case 'A':
                    echo '<div title="This rackspace does not exist">&nbsp;</div>';
                    break;
                case 'F':
                    echo '<div title="Free rackspace">&nbsp;</div>';
                    break;
                case 'U':
                    echo '<div title="Problematic rackspace, you CAN\'T mount here">&nbsp;</div>';
                    break;
                default:
                    echo '<div title="No data">&nbsp;</div>';
                    break;
            }
            echo '</td>';
        }
        echo "</tr>\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 renderReducedRack($rack_id, $hl_obj_id = 0)
{
    $rackData = spotEntity('rack', $rack_id);
    amplifyCell($rackData);
    markAllSpans($rackData);
    if ($hl_obj_id > 0) {
        highlightObject($rackData, $hl_obj_id);
    }
    // markupObjectProblems ($rackData); // Function removed in 0.20.5
    echo "<center><table border=0><tr valign=middle>";
    echo '<td><h2>' . mkA($rackData['name'], 'rack', $rackData['id']) . '</h2></td>';
    echo "</h2></td></tr></table>\n";
    echo "<table class=rackphg border=0 cellspacing=0 cellpadding=1>\n";
    echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
    echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
    for ($i = $rackData['height']; $i > 0; $i--) {
        echo "<tr><td>" . inverseRackUnit($i, $rackData) . "</td>";
        for ($locidx = 0; $locidx < 3; $locidx++) {
            if (isset($rackData[$i][$locidx]['skipped'])) {
                continue;
            }
            $state = $rackData[$i][$locidx]['state'];
            echo "<td class='atom state_{$state}";
            if (isset($rackData[$i][$locidx]['hl'])) {
                echo $rackData[$i][$locidx]['hl'];
            }
            echo "'";
            if (isset($rackData[$i][$locidx]['colspan'])) {
                echo ' colspan=' . $rackData[$i][$locidx]['colspan'];
            }
            if (isset($rackData[$i][$locidx]['rowspan'])) {
                echo ' rowspan=' . $rackData[$i][$locidx]['rowspan'];
            }
            echo ">";
            switch ($state) {
                case 'T':
                    printObjectDetailsForRenderRack($rackData[$i][$locidx]['object_id']);
                    // TODO set background color based on the tag
                    $o = spotEntity('object', $rackData[$i][$locidx]['object_id']);
                    while (list($key, $val) = each($o['etags'])) {
                        echo "<div style='font: 8px Verdana,sans-serif; text-decoration:none; color=black'>";
                        echo $val['tag'];
                        echo "</div>";
                        break;
                    }
                    break;
                case 'A':
                    echo '<div title="This rackspace does not exist">&nbsp;</div>';
                    break;
                case 'F':
                    echo '<div title="Free rackspace">&nbsp;</div>';
                    break;
                case 'U':
                    echo '<div title="Problematic rackspace, you CAN\'T mount here">&nbsp;</div>';
                    break;
                default:
                    echo '<div title="No data">&nbsp;</div>';
                    break;
            }
            echo '</td>';
        }
        echo "</tr>\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 __construct($object_id = NULL, $port_id = NULL, $allports = false, $hl = NULL, $remote_id = NULL)
 {
     $this->allports = $allports;
     $this->object_id = $object_id;
     $this->port_id = $port_id;
     $this->remote_id = $remote_id;
     $this->hl = $hl;
     $hllabel = "";
     /* suppress strict standards warnings for Image_GraphViz and PHP 5.4.0
      * output would corrupt image data
      */
     $this->errorlevel = error_reporting();
     error_reporting($this->errorlevel & ~E_STRICT);
     $graphattr = array('rankdir' => 'LR', 'nodesep' => '0');
     unset($_GET['module']);
     $_GET['all'] = 1;
     $graphattr['URL'] = $this->_makeHrefProcess($_GET);
     unset($_GET['all']);
     switch ($hl) {
         case 'o':
         case 'p':
             $this->alpha = '30';
             break;
     }
     //$this->gv = new Image_GraphViz(true, $graphattr, "map".$object_id);
     $this->gv = new lm_Image_GraphViz(true, $graphattr, "map" . $object_id);
     /* --------------------------- */
     if ($object_id === NULL) {
         /* all objects ! */
         unset($_GET['all']);
         $_GET['hl'] = 'o';
         $this->gv->addAttributes(array('label' => 'Showing all objects' . $hllabel, 'labelloc' => 't'));
         $objects = listCells('object');
         foreach ($objects as $obj) {
             //$this->addlinkchainsobject($obj['id']); // longer runtimes !!
             $this->_add($this->gv, $obj['id'], NULL);
         }
         // for all still faster and nicer looking graph
         return;
     } else {
         $object = spotEntity('object', $object_id);
         $this->gv->addAttributes(array('label' => "Graph for {$object['dname']}{$hllabel}", 'labelloc' => 't'));
         $this->addlinkchainsobject($object_id);
         //$this->_add($this->gv, $object_id, $port_id);
         $children = getEntityRelatives('children', 'object', $object_id);
         //'entity_id'
         foreach ($children as $child) {
             $this->addlinkchainsobject($child['entity_id']);
         }
         //	$this->_add($this->gv, $child['entity_id'], NULL);
     }
     /* add hl label */
     $this->gv->addAttributes(array('label' => $this->gv->graph['attributes']['label'] . $hllabel));
     //	portlist::var_dump_html($this->gv);
     //		portlist::var_dump_html($this->data);
     //		echo json_encode($this->data);
     //	$this->gv->saveParsedGraph('/tmp/graph.txt');
     //	error_reporting( E_ALL ^ E_NOTICE);
 }
Example #7
0
function highlightObject(&$rackData, $object_id)
{
    // Also highlight parent objects
    $parents = getEntityRelatives('parents', 'object', $object_id);
    $parent_ids = array();
    foreach ($parents as $parent) {
        $parent_ids[] = $parent['entity_id'];
    }
    for ($unit_no = $rackData['height']; $unit_no > 0; $unit_no--) {
        for ($locidx = 0; $locidx < 3; $locidx++) {
            if ($rackData[$unit_no][$locidx]['state'] == 'T' and ($rackData[$unit_no][$locidx]['object_id'] == $object_id or in_array($rackData[$unit_no][$locidx]['object_id'], $parent_ids))) {
                $rackData[$unit_no][$locidx]['hl'] = 'h';
            } else {
                unset($rackData[$unit_no][$locidx]['hl']);
            }
        }
    }
}
function renderPortletWattConsumption($info)
{
    $rackTotalWattage = 0;
    $rackData = spotEntity('rack', $info['id']);
    amplifyCell($rackData);
    $objectChildren = getEntityRelatives('children', 'object', $objectData['id']);
    foreach ($rackData['mountedObjects'] as $object) {
        $objectData = spotEntity('object', $object);
        amplifyCell($objectData);
        foreach (getAttrValues($objectData['id']) as $record) {
            if ($record['name'] == 'Wattage consumption') {
                $rackTotalWattage += $record['value'];
            }
        }
    }
    startPortlet('Wattage Consumption');
    echo "<table border=0 cellspacing=5 align='center'><tr>";
    echo "<td>The total for attribute Wattage consuption is:  <b>{$rackTotalWattage}</b></td>\n";
    echo "</tr></table>\n";
    finishPortlet();
}