public static function setUpBeforeClass()
 {
     // add sample locations
     self::$first_location_id = $parent_location_id = commitAddObject('unit test location 0', NULL, 1562, NULL);
     for ($i = 1; $i <= self::$num_children; $i++) {
         $child_location_id = commitAddObject("unit test location {$i}", NULL, 1562, NULL);
         commitLinkEntities('location', $parent_location_id, 'location', $child_location_id);
         $parent_location_id = $child_location_id;
     }
     self::$last_location_id = $parent_location_id;
     // add sample objects
     usePreparedInsertBlade('Dictionary', array('chapter_id' => 1, 'dict_value' => 'unit test object type'));
     self::$objtype_id = lastInsertID();
     commitSupplementOPC(self::$objtype_id, self::$objtype_id);
     self::$first_object_id = $parent_object_id = commitAddObject('unit test object 0', NULL, self::$objtype_id, NULL);
     for ($i = 1; $i <= self::$num_children; $i++) {
         $child_object_id = commitAddObject("unit test object {$i}", NULL, self::$objtype_id, NULL);
         commitLinkEntities('object', $parent_object_id, 'object', $child_object_id);
         $parent_object_id = $child_object_id;
     }
     self::$last_object_id = $parent_object_id;
     // add sample tags
     usePreparedInsertBlade('TagTree', array('tag' => 'unit test tag 0'));
     self::$first_tag_id = $parent_tag_id = lastInsertID();
     for ($i = 1; $i <= self::$num_children; $i++) {
         usePreparedInsertBlade('TagTree', array('parent_id' => $parent_tag_id, 'tag' => "unit test tag {$i}"));
         $parent_tag_id = lastInsertID();
     }
     self::$last_tag_id = $parent_tag_id;
 }
示例#2
0
 public function setUp()
 {
     // create a nameless shelf which contains a modem (re: ticket #1115)
     $this->shelf_id = commitAddObject(NULL, NULL, 3, NULL);
     $this->modem_id = commitAddObject('unit test modem', NULL, 13, NULL);
     commitLinkEntities('object', $this->shelf_id, 'object', $this->modem_id);
 }
 /**
  * @expectedException RackTablesError
  */
 public function testUpdateLocationCircularReference()
 {
     // set A as the parent of B, and B as the parent of C
     commitLinkEntities('location', self::$locationa_id, 'location', self::$locationb_id);
     commitLinkEntities('location', self::$locationb_id, 'location', self::$locationc_id);
     // reversing the link between B and C should fail
     commitUpdateEntityLink('location', self::$locationb_id, 'location', self::$locationc_id, 'location', self::$locationc_id, 'location', self::$locationb_id);
 }
示例#4
0
文件: importer.php 项目: xtha/salt
/** Create a Virtual Machine in the specified pool
	@param name 	The name of the new Virtual Machine
	@param ip		The IP address to assign the VM
	@param asset	Asset tag to use (VM UUID)
	@param osInfo	Operating System information (to be stored as a comment)
	@param taglist	Array of tags to use for this new object
	@param poolID	Virtual Machine pool to parent this object to
*/
function createVMInPool($name, $ip, $asset, $osInfo, $taglist, $poolID, $vmTypeID)
{
    // make sure there's no duplicates
    if (getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2)) {
        return FALSE;
    }
    // commitAddObject ($new_name, $new_label, $new_type_id, $new_asset_no, $taglist = array())
    $newObject = commitAddObject($name, $name, $vmTypeID, $asset, $taglist);
    // add IP address to new object
    if (!empty($ip)) {
        bindIpToObject(ip_parse($ip), $newObject, 'eth0', 'regular');
    }
    // add OS info to new object
    if (!empty($osInfo)) {
        usePreparedUpdateBlade('Object', array('comment' => $osInfo), array('id' => $newObject));
    }
    // set container
    //commitLinkEntities($parent_entity_type, $parent_entity_id, $child_entity_type, $child_entity_id);
    commitLinkEntities("object", $poolID, "object", $newObject);
}
示例#5
0
文件: ophandlers.php 项目: xtha/salt
function autoPopulateUCS()
{
    global $ucsproductmap;
    $ucsm_id = getBypassValue();
    $oinfo = spotEntity('object', $ucsm_id);
    $chassis_id = array();
    $done = 0;
    # There are three request parameters (use_terminal_settings, ucs_login and
    # ucs_password) not processed here. These are asserted and used inside
    # queryTerminal().
    try {
        $contents = queryDevice($ucsm_id, 'getinventory');
    } catch (RTGatewayError $e) {
        showError($e->getMessage());
        return;
    }
    foreach ($contents as $item) {
        $mname = preg_replace('#^sys/(.+)$#', $oinfo['name'] . '/\\1', $item['DN']);
        if ($item['type'] == 'NetworkElement') {
            $new_object_id = commitAddObject($mname, NULL, 8, NULL);
            #    Set H/W Type for Network Switch
            if (array_key_exists($item['model'], $ucsproductmap)) {
                commitUpdateAttrValue($new_object_id, 2, $ucsproductmap[$item['model']]);
            }
            #  	 Set Serial#
            commitUpdateAttrValue($new_object_id, 1, $item['serial']);
            commitLinkEntities('object', $ucsm_id, 'object', $new_object_id);
            bindIPToObject(ip_parse($item['OOB']), $new_object_id, 'mgmt0', 'regular');
            $done++;
        } elseif ($item['type'] == 'EquipmentChassis') {
            $chassis_id[$item['DN']] = $new_object_id = commitAddObject($mname, NULL, 1502, NULL);
            #    Set H/W Type for Server Chassis
            if (array_key_exists($item['model'], $ucsproductmap)) {
                commitUpdateAttrValue($new_object_id, 2, $ucsproductmap[$item['model']]);
            }
            #  	 Set Serial#
            commitUpdateAttrValue($new_object_id, 1, $item['serial']);
            commitLinkEntities('object', $ucsm_id, 'object', $new_object_id);
            $done++;
        } elseif ($item['type'] == 'ComputeBlade') {
            if ($item['assigned'] == '') {
                $new_object_id = commitAddObject($mname, NULL, 4, NULL);
            } else {
                $spname = preg_replace('#.+/ls-(.+)#i', '${1}', $item['assigned']) . "(" . $oinfo['name'] . ")";
                $new_object_id = commitAddObject($spname, NULL, 4, NULL);
            }
            #    Set H/W Type for Blade Server
            if (array_key_exists($item['model'], $ucsproductmap)) {
                commitUpdateAttrValue($new_object_id, 2, $ucsproductmap[$item['model']]);
            }
            #  	 Set Serial#
            commitUpdateAttrValue($new_object_id, 1, $item['serial']);
            #  	 Set Slot#
            commitUpdateAttrValue($new_object_id, 28, $item['slot']);
            $parent_name = preg_replace('#^([^/]+)/([^/]+)/([^/]+)$#', '${1}/${2}', $item['DN']);
            if (array_key_exists($parent_name, $chassis_id)) {
                commitLinkEntities('object', $chassis_id[$parent_name], 'object', $new_object_id);
            }
            $done++;
        }
    }
    # endfor
    showSuccess("Auto-populated UCS Domain '{$oinfo['name']}' with {$done} items");
}
示例#6
0
function addModules($parent_id, $object_id, $module_key = NULL)
{
    $self = __FUNCTION__;
    global $chapter_to_objtype_map, $known_modules, $iftable_processors, $snmp_data, $objectInfo;
    $count = count($snmp_data['entPhysicalContainedIn']);
    $children = array_keys($snmp_data['entPhysicalContainedIn'], $parent_id);
    foreach ($children as $id) {
        // it should be added as a port
        if (array_key_exists($id, $snmp_data['entToIfMapping'])) {
            addModulePort($id, $object_id, $module_key);
        }
        // it should be added as an object
        foreach ($known_modules as $key => $attr) {
            // the model string may be stored in entPhysicalDescr or entPhysicalModelName
            if (preg_match($attr['pattern'], $snmp_data['entPhysicalDescr'][$id]) or preg_match($attr['pattern'], $snmp_data['entPhysicalModelName'][$id])) {
                $module_key = $key;
                // sometimes ports are registered to a child object such as a motherboard
                // in such cases, we want them assigned to the origin object itself (example: Cisco 2801 ISR)
                if (isset($known_modules[$module_key]['assign_to_origin'])) {
                    addModulePort($id, $object_id, $module_key);
                    break;
                }
                showSuccess($known_modules[$module_key]['text']);
                // entPhysicalName contains the name of the slot in most cases.
                // But sometimes it contains a non-unique string, such as 'Linecard'.
                // If that is true, use the id instead, which can be assumed to be unique.
                $module_name_known = TRUE;
                $module_name = $snmp_data['entPhysicalName'][$id];
                if (count(array_keys($snmp_data['entPhysicalName'], $module_name)) > 1) {
                    $module_name_known = FALSE;
                    $module_name = "module {$id}";
                }
                // determine object type
                $dict_entry = getDictionaryEntry($attr['dict_key']);
                if (!array_key_exists($dict_entry['chapter_id'], $chapter_to_objtype_map)) {
                    showError('No dictionary entry, terminating');
                    break 2;
                }
                $objtype_id = $chapter_to_objtype_map[$dict_entry['chapter_id']];
                $child_object_id = commitAddObject("{$objectInfo['name']} - {$module_name}", NULL, $objtype_id, NULL);
                $child_objectInfo = spotEntity('object', $child_object_id);
                $child_objectInfo['attrs'] = getAttrValues($child_object_id);
                updateStickerForCell($child_objectInfo, 1, $snmp_data['entPhysicalSerialNum'][$id]);
                // OEM S/N 1
                updateStickerForCell($child_objectInfo, 2, $attr['dict_key']);
                // HW type
                updateStickerForCell($child_objectInfo, 5, $snmp_data['entPhysicalFirmwareRev'][$id]);
                // SW version
                if ($module_name_known) {
                    updateStickerForCell($child_objectInfo, 28, $module_name);
                }
                // Slot number
                commitLinkEntities('object', $object_id, 'object', $child_object_id);
                // add model-specific module details
                switch ($module_key) {
                    case 'J8726A':
                        checkPIC('1-681');
                        commitAddPort($child_object_id, 'con0', '1-681', 'console', '');
                        // DB-9 RS-232 console
                        break;
                    case 'NPE-G1':
                    case 'NPE-G2':
                        checkPIC('1-29');
                        commitAddPort($child_object_id, 'con0', '1-29', 'console', '');
                        // RJ-45 RS-232 console
                        commitAddPort($child_object_id, 'aux0', '1-29', 'auxillary', '');
                        // RJ-45 RS-232 aux port
                        checkPIC('1-19');
                        commitAddPort($child_object_id, 'mgmt', '1-19', '', '');
                        // 100Mb OOB mgmt
                        break;
                    case 'WS-SUP720-3B':
                    case 'WS-X6K-SUP2-2GE':
                    case 'WS-XSUP720-3BXL':
                        checkPIC('1-29');
                        commitAddPort($child_object_id, 'con0', '1-29', 'console', '');
                        // RJ-45 RS-232 console
                        break;
                    case 'WS-X4515':
                        checkPIC('1-29');
                        commitAddPort($child_object_id, 'con0', '1-29', 'console', '');
                        // RJ-45 RS-232 console
                        checkPIC('1-19');
                        commitAddPort($child_object_id, 'eobc', '1-19', 'mgmt', '');
                        // 100Mb OOB mgmt
                        break;
                }
                break;
            }
        }
        // if a new child object was just created, find children of that; otherwise, find children of the object passed as an argument
        $search_object_id = isset($child_object_id) ? $child_object_id : $object_id;
        $self($id, $search_object_id, $module_key);
    }
}
function initRackTablesObject($rackDatas)
{
    // zabbix host data
    $params = array('output' => 'extend');
    $result = doPost('host.get', $params);
    $hosts = isset($result['result']) ? $result['result'] : array();
    $objectDatas = array();
    foreach ($hosts as $host) {
        $object_type_id = 4;
        $object_name = isset($host['host']) ? $host['host'] : "";
        $object_label = "";
        $object_asset_no = "";
        $taglist = array();
        $has_problems = $host['status'] == 0 ? 'no' : 'yes';
        $object_id = commitAddObject($object_name, $object_label, $object_type_id, $object_asset_no, $taglist);
        usePreparedUpdateBlade('Object', array('has_problems' => $has_problems), array('id' => $object_id));
        $objectDatas[$host['hostid']] = $object_id;
        // set hostgroup
        $params = array('output' => array('name'), 'hostids' => array($host['hostid']));
        $result = doPost('hostgroup.get', $params);
        $hostgroups = isset($result['result']) ? $result['result'] : array();
        $rack_ids = array();
        $_REQUEST = array();
        foreach ($hostgroups as $hostgroup) {
            if (isset($rackDatas[$hostgroup['name']])) {
                $rack = $rackDatas[$hostgroup['name']];
                amplifyCell($rack);
                array_push($rack_ids, $rack['id']);
                $height = $rack['height'];
                for ($i = 0; $i < 3; $i++) {
                    for ($j = $height; $j > 0; $j--) {
                        if ($rack[$j][$i]['state'] == 'F') {
                            # state == "T" : mounted
                            $_REQUEST['atom_' . $rack['id'] . "_{$j}" . "_{$i}"] = 'on';
                            break 2;
                        }
                    }
                }
            }
        }
        $_REQUEST['object_id'] = $object_id;
        $_REQUEST['rackmulti'] = $rack_ids;
        $object = spotEntity('object', $object_id);
        $changecnt = 0;
        // Get a list of rack ids which are parents of the object
        $parentRacks = reduceSubarraysToColumn(getParents($object, 'rack'), '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;
            } else {
                $rackData = $workingRacksData[$cand_id];
            }
            $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE);
            // 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)) {
                if ($is_ro) {
                    continue;
                }
                $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)) {
                if ($is_ro) {
                    continue;
                }
                $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) {
            $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE);
            if ($is_ro || !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);
            global $remote_username, $sic;
            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']));
        }
        // set IP
        $params = array('output' => 'extend', 'hostids' => $host['hostid']);
        $result = doPost('hostinterface.get', $params);
        $hostinterfaces = isset($result['result']) ? $result['result'] : array();
        foreach ($hostinterfaces as $interface) {
            if (isset($interface['ip']) && $interface['ip'] != '127.0.0.1') {
                $allocs = getObjectIPAllocations($object_id);
                $current_ips = array();
                foreach ($allocs as $alloc) {
                    $ip = $alloc["addrinfo"]["ip"];
                    $current_ips[$ip] = $ip;
                }
                $ip = $interface['ip'];
                if (!in_array($ip, array_values($current_ips))) {
                    // new IP
                    $ip_bin = ip_parse($ip);
                    if (null == getIPAddressNetworkId($ip_bin)) {
                        // if ip is not exists, adding it into RackTables IPv4Prefix.
                        $range = substr($ip, 0, strripos($ip, '.')) . '.0/24';
                        $vlan_ck = NULL;
                        $net_id = createIPv4Prefix($range, 'admim', isCheckSet('is_connected'), $taglist);
                        $net_cell = spotEntity('ipv4net', $net_id);
                        if (isset($vlan_ck)) {
                            if (considerConfiguredConstraint($net_cell, 'VLANIPV4NET_LISTSRC')) {
                                commitSupplementVLANIPv4($vlan_ck, $net_id);
                            }
                        }
                    }
                    bindIPToObject($ip_bin, $object_id, "", "");
                }
            }
        }
    }
    return $objectDatas;
}
示例#8
0
文件: api.php 项目: xtha/salt
     }
 }
 $workingRacksData = array();
 // iterate over all involved racks (old and new) to get the detailed rack data
 // also deal with zero-U allocations and de-allocations
 foreach (array_unique(array_merge($allocationsOld, $zeroURacksNew, array_keys($allocationsNew))) as $rack_id) {
     if (!isset($workingRacksData[$rack_id])) {
         $rackData = spotEntity('rack', $rack_id);
         amplifyCell($rackData);
         $workingRacksData[$rack_id] = $rackData;
     }
     // It's zero-U allocated to this rack in the API request, but not in the DB.  Mount it.
     if (in_array($rack_id, $zeroURacksNew) && !in_array($rack_id, $zeroURacksOld)) {
         $changecnt++;
         error_log("zero-u mounting object id: {$object_id} from rack id: {$rack_id}");
         commitLinkEntities('rack', $rack_id, 'object', $object_id);
     }
     // It's not zero-U allocated to this rack in the API request, but it is in the DB.  Unmount it.
     if (!in_array($rack_id, $zeroURacksNew) && in_array($rack_id, $zeroURacksOld)) {
         $changecnt++;
         error_log("zero-u UN- mounting object id: {$object_id} from rack id: {$rack_id}");
         commitUnlinkEntities('rack', $rack_id, 'object', $object_id);
     }
 }
 foreach ($workingRacksData as &$rd) {
     applyObjectMountMask($rd, $object_id);
 }
 // quick DB operation to save old data for logging
 $oldMolecule = getMoleculeForObject($object_id);
 foreach ($workingRacksData as $rack_id => $rackData) {
     $rackchanged = FALSE;
示例#9
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();
    $rf1 = $_REQUEST['rfid'];
    if (isset($_REQUEST['rfid'])) {
        //	$rf1 = 1000000;//$_REQUEST['rfid'];
        $result = usePreparedSelectBlade("SELECT object_id FROM objecttorf WHERE rf_id = ?", array($rf1));
        $row = $result->fetch(PDO::FETCH_ASSOC);
        if (isset($row)) {
            $object_id = $row['object_id'];
        }
        //получить значение из базы где rf1=njvenj
        //showError ('Permission deniedddddddd, "' . $object_id . '" left unchanged');
    }
    $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));
}
示例#10
0
function addVmToParent($vms, $newmachine)
{
    $search_for_child = "select id from RackObject WHERE name REGEXP '^ *{$vms}\\\\.'";
    unset($result);
    $result = usePreparedSelectBlade($search_for_child);
    $resultarray = $result->fetchAll(PDO::FETCH_ASSOC);
    $child = $resultarray[0]['id'];
    if (!empty($child)) {
        //make sure the association doesn't exist already or deal with it
        $current_container = "SELECT parent_entity_id from EntityLink WHERE child_entity_id = {$child}";
        unset($result);
        $result = usePreparedSelectBlade($current_container);
        $resultarray = $result->fetchAll(PDO::FETCH_ASSOC);
        $current_parent = $resultarray[0]['parent_entity_id'];
        if ($current_parent != $newmachine && !empty($current_parent)) {
            commitUpdateEntityLink('object', $current_parent, 'object', $child, 'object', $newmachine, 'object', $child);
        } else {
            if (empty($current_parent)) {
                commitLinkEntities('object', $newmachine, 'object', $child);
            }
        }
    } else {
        echo "WARNING: The {$vms} VM does not exist for this Parent \n";
    }
}