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"); }
function snmpgeneric_opcreate() { $object_id = $_REQUEST['object_id']; $attr = getAttrValues($object_id); // sg_var_dump_html($_REQUEST); // sg_var_dump_html($attr); /* commitUpdateAttrValue ($object_id, $attr_id, $new_value); */ if (isset($_POST['updateattr'])) { foreach ($_POST['updateattr'] as $attr_id => $value) { // if(empty($attr[$attr_id]['value'])) if (!empty($value)) { commitUpdateAttrValue($object_id, $attr_id, $value); showSuccess("Attribute " . $attr[$attr_id]['name'] . " set to {$value}"); } } unset($attr_id); unset($value); } /* updateattr */ /* create ports */ if (isset($_POST['portcreate'])) { foreach ($_POST['portcreate'] as $if => $value) { $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : ''; $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : ''; $ifDescr = isset($_POST['ifDescr'][$if]) ? trim($_POST['ifDescr'][$if]) : ''; //$visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr; $visible_label = $ifAlias; if (empty($ifName)) { showError('Port without ifName ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress); } else { commitAddPort($object_id, $ifName, $_POST['porttypeid'][$if], $visible_label, $ifPhysAddress); showSuccess('Port created ' . $ifName . ', ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress); } } unset($if); unset($value); } /* portcreate */ /* net create */ if (isset($_POST['netcreate'])) { foreach ($_POST['netcreate'] as $id => $addrtype) { $range = $_POST['netprefix'][$id]; $name = $_POST['netname'][$id]; $is_reserved = isset($_POST['netreserve'][$id]); if ($addrtype == 'ipv4' || $addrtype == 'ipv4z') { createIPv4Prefix($range, $name, $is_reserved); } else { createIPv6Prefix($range, $name, $is_reserved); } showSuccess("{$range} {$name} created"); } unset($id); unset($addrtype); } /* netcreate */ /* allocate ipv6 adresses */ if (isset($_POST['ipv6addrcreate'])) { foreach ($_POST['ipv6addrcreate'] as $ipaddr => $if) { bindIPv6ToObject(ip6_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1); /* connected */ showSuccess("{$ipaddr} allocated"); } unset($ipaddr); unset($if); } /* allocate ip adresses */ if (isset($_POST['ipaddrcreate'])) { foreach ($_POST['ipaddrcreate'] as $ipaddr => $if) { bindIPToObject(ip_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1); /* connected */ showSuccess("{$ipaddr} allocated"); } unset($ipaddr); unset($if); } /* ipaddrecreate */ /* update label */ if (isset($_POST['updatelabel'])) { foreach ($_POST['updatelabel'] as $if => $port_id) { $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : ''; sg_commitUpdatePortLabel($object_id, $port_id, $ifAlias); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("label updated on {$ifName} to {$ifAlias}"); } unset($if); unset($port_id); } /* updatemac */ /* update mac addresses only */ if (isset($_POST['updatemac'])) { foreach ($_POST['updatemac'] as $if => $port_id) { $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : ''; sg_commitUpdatePortl2address($object_id, $port_id, $ifPhysAddress); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("l2address updated on {$ifName} to {$ifPhysAddress}"); } unset($if); unset($port_id); } /* updatemac */ /* update port type */ if (isset($_POST['updateporttype'])) { foreach ($_POST['updateporttype'] as $if => $port_id) { $porttypeid = isset($_POST['porttypeid'][$if]) ? trim($_POST['porttypeid'][$if]) : ''; sg_commitUpdatePortType($object_id, $port_id, $porttypeid); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("port type updated on {$ifName}"); } unset($if); unset($port_id); } /* updateporttype */ }
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; }
function bindIPv6ToObject($ip_bin, $object_id = 0, $name = '', $type = '') { if (strlen($ip_bin) != 16) { throw new InvalidArgException('ip_bin', $ip_bin, "Invalid binary IP"); } return bindIPToObject($ip_bin, $object_id, $name, $type); }
$_REQUEST['bond_name'] = ''; } // default value for bond_type // note on meanings of on 'bond_type' values: // 'regular': Connected // 'virtual': Loopback // 'shared': Shared // 'router': Router if (!isset($_REQUEST['bond_type'])) { $_REQUEST['bond_type'] = 'regular'; } // confirm that a network exists that matches the IP address if (getConfigVar('IPV4_JAYWALK') != 'yes' and NULL === getIPAddressNetworkId($ip_bin)) { throw new InvalidRequestArgException('ip', $_REQUEST['ip'], 'no network covering the requested IP address'); } bindIPToObject($ip_bin, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); redirectUser($_SERVER['SCRIPT_NAME'] . '?method=get_object&object_id=' . $_REQUEST['object_id']); break; // delete an IP address allocation for an object // UI equivalent: /index.php? // UI handler: delIPAllocation() // delete an IP address allocation for an object // UI equivalent: /index.php? // UI handler: delIPAllocation() case 'delete_object_ip_allocation': require_once 'inc/init.php'; $ip_bin = assertIPArg('ip'); assertUIntArg('object_id'); // TODO: raise exception if the IP doesn't exist unbindIPFromObject($ip_bin, $_REQUEST['object_id']); redirectUser($_SERVER['SCRIPT_NAME'] . '?method=get_object&object_id=' . $_REQUEST['object_id']);