function deleteRackTablesData() { // delete racktables items data $query = 'delete from item_information;'; usePreparedExecuteBlade($query); // delete racktables object data $allObjects = scanRealmByText('object'); foreach ($allObjects as $object) { $racklist = getResidentRacksData($object["id"], FALSE); commitDeleteObject($object["id"]); foreach ($racklist as $rack_id) { usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); } } // delete racktables rack data $allRacks = scanRealmByText('rack'); foreach ($allRacks as $rack) { releaseFiles('rack', $rack['id']); destroyTagsForEntity('rack', $rack['id']); usePreparedDeleteBlade('RackSpace', array('rack_id' => $rack['id'])); commitDeleteObject($rack['id']); resetRackSortOrder($rack['row_id']); } $query = 'delete from rack_position;'; usePreparedExecuteBlade($query); $query = 'delete from rack_airconditioner;'; usePreparedExecuteBlade($query); }
public function tearDown() { // delete any links created during the test usePreparedExecuteBlade("DELETE FROM EntityLink WHERE parent_entity_type='object' AND child_entity_type='object' " . 'AND (parent_entity_id IN (?,?,?) OR child_entity_id IN (?,?,?))', array(self::$objecta_id, self::$objectb_id, self::$objectc_id, self::$objecta_id, self::$objectb_id, self::$objectc_id)); usePreparedExecuteBlade("DELETE FROM EntityLink WHERE parent_entity_type='location' AND child_entity_type='location' " . 'AND (parent_entity_id IN (?,?,?) OR child_entity_id IN (?,?,?))', array(self::$locationa_id, self::$locationb_id, self::$locationc_id, self::$locationa_id, self::$locationb_id, self::$locationc_id)); usePreparedExecuteBlade("DELETE FROM EntityLink WHERE (child_entity_type='row' AND child_entity_id IN (?,?)) " . "OR (child_entity_type='rack' AND child_entity_id IN (?,?))", array(self::$rowa_id, self::$rowb_id, self::$racka_id, self::$rackb_id)); }
public function tearDown() { // remove sample data usePreparedExecuteBlade('UPDATE TagTree SET parent_id = NULL WHERE id IN (?,?,?)', array($this->taga_id, $this->tagb_id, $this->tagc_id)); usePreparedDeleteBlade('TagTree', array('id' => $this->taga_id)); usePreparedDeleteBlade('TagTree', array('id' => $this->tagb_id)); usePreparedDeleteBlade('TagTree', array('id' => $this->tagc_id)); }
public static function tearDownAfterClass() { usePreparedExecuteBlade('SET foreign_key_checks=0'); // remove sample locations usePreparedExecuteBlade('DELETE FROM Object WHERE id BETWEEN ? AND ?', array(self::$first_location_id, self::$last_location_id)); usePreparedExecuteBlade("DELETE FROM EntityLink WHERE parent_entity_type='location' AND child_entity_type='location' " . 'AND ((parent_entity_id BETWEEN ? AND ?) OR (child_entity_id BETWEEN ? AND ?))', array(self::$first_location_id, self::$last_location_id, self::$first_location_id, self::$last_location_id)); // remove sample objects usePreparedExecuteBlade('DELETE FROM Object WHERE id BETWEEN ? AND ?', array(self::$first_object_id, self::$last_object_id)); usePreparedExecuteBlade("DELETE FROM EntityLink WHERE parent_entity_type='object' AND child_entity_type='object' " . 'AND ((parent_entity_id BETWEEN ? AND ?) OR (child_entity_id BETWEEN ? AND ?))', array(self::$first_object_id, self::$last_object_id, self::$first_object_id, self::$last_object_id)); commitReduceOPC(self::$objtype_id, self::$objtype_id); usePreparedDeleteBlade('Dictionary', array('dict_key' => self::$objtype_id)); // remove sample tags usePreparedExecuteBlade('DELETE FROM TagTree WHERE id BETWEEN ? AND ?', array(self::$first_tag_id, self::$last_tag_id)); }
function addObjectlog() { assertStringArg('logentry'); global $remote_username, $sic; if (isset($sic['object_id'])) { $object_id = $sic['object_id']; } elseif (isset($sic['location_id'])) { $object_id = $sic['location_id']; } else { $object_id = $sic['rack_id']; } usePreparedExecuteBlade('INSERT INTO ObjectLog SET object_id=?, user=?, date=NOW(), content=?', array($object_id, $remote_username, $sic['logentry'])); showSuccess('Log entry added'); }
function touchVLANSwitch($switch_id) { usePreparedExecuteBlade('UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?', array($switch_id)); }
function commitUpdateRS($rsid, $rsip_bin, $rsport = 0, $inservice = 'yes', $rsconfig = '', $comment = '') { usePreparedExecuteBlade('UPDATE IPv4RS SET rsip=?, rsport=?, inservice=?, rsconfig=?, comment=? WHERE id=?', array($rsip_bin, (!strlen($rsport) or $rsport === 0) ? NULL : $rsport, $inservice, !strlen($rsconfig) ? NULL : $rsconfig, !strlen($comment) ? NULL : $comment, $rsid)); }
} print_message_line("Failed to lock {$filename}, already locked by PID " . trim(fgets($fp, 10))); exit(1); } ftruncate($fp, 0); fwrite($fp, getmypid() . "\n"); // don't close $fp yet: we need to keep an flock } // fetch all the needed data from DB (preparing for DB connection loss) $switch_queue = array(); foreach ($switch_list as $object_id) { $cell = spotEntity('object', $object_id); $new_disabled = !considerConfiguredConstraint($cell, 'SYNC_802Q_LISTSRC'); $queue = detectVLANSwitchQueue(getVLANSwitchInfo($object_id)); if ($queue == 'disabled' xor $new_disabled) { usePreparedExecuteBlade('UPDATE VLANSwitch SET out_of_sync="yes", last_error_ts=NOW(), last_errno=? WHERE object_id=?', array($new_disabled ? E_8021Q_SYNC_DISABLED : E_8021Q_NOERROR, $object_id)); } elseif (in_array($queue, $todo[$options['mode']])) { $switch_queue[] = $cell; } } // YOU SHOULD NOT USE DB FUNCTIONS BELOW IN THE PARENT PROCESS // THE PARENT'S DB CONNECTION IS LOST DUE TO RECONNECTING IN THE CHILD $fork_slots = getConfigVar('SYNCDOMAIN_MAX_PROCESSES'); $do_fork = $fork_slots > 1 and extension_loaded('pcntl'); if ($fork_slots > 1 and !$do_fork) { throw new RackTablesError('PHP extension \'pcntl\' not found, can not use childs', RackTablesError::MISCONFIGURED); } $switches_working = 0; $switchesdone = 0; foreach ($switch_queue as $object) { if ($do_fork) {
public function tearDown() { // delete any links created during the test usePreparedExecuteBlade('DELETE FROM Link WHERE porta IN (?,?,?) OR portb IN (?,?,?)', array(self::$porta, self::$portb, self::$portc, self::$porta, self::$portb, self::$portc)); }
function dispatchMiniRackThumbRequest($rack_id) { if (NULL !== ($thumbcache = loadThumbCache($rack_id))) { header('Content-type: image/png'); echo $thumbcache; return; } ob_start(); printRackThumbImage($rack_id); $capture = ob_get_clean(); header('Content-type: image/png'); echo $capture; usePreparedExecuteBlade('REPLACE INTO RackThumbnail SET rack_id=?, thumb_data=?', array($rack_id, base64_encode($capture))); }
function commitDeleteConfig($conf_id) { return usePreparedExecuteBlade("DELETE FROM ObjectConfigs WHERE id = ?", array($conf_id)); }
function renderRackThumb($rack_id = 0) { // Don't call DB extra times, hence we are most probably not the // only script wishing to access the same data now. if (NULL !== ($thumbcache = loadThumbCache($rack_id))) { header("Content-type: image/png"); echo $thumbcache; return; } ob_start(); if (FALSE !== generateMiniRack($rack_id)) { $capture = ob_get_clean(); header("Content-type: image/png"); echo $capture; usePreparedExecuteBlade('REPLACE INTO RackThumbnail SET rack_id=?, thumb_data=?', array($rack_id, base64_encode($capture))); return; } // error text in the buffer ob_end_flush(); }
function linkmgmt_linkPorts($porta, $portb, $linktype, $cable = NULL) { if ($porta == $portb) { throw new InvalidArgException('porta/portb', $porta, "Ports can't be the same"); } if ($linktype == 'back') { $table = 'LinkBackend'; $multilink = LM_MULTILINK; } else { $table = 'Link'; $multilink = false; } global $dbxlink; $dbxlink->exec('LOCK TABLES ' . $table . ' WRITE'); if (!$multilink) { $result = usePreparedSelectBlade('SELECT COUNT(*) FROM ' . $table . ' WHERE porta IN (?,?) OR portb IN (?,?)', array($porta, $portb, $porta, $portb)); if ($result->fetchColumn() != 0) { $dbxlink->exec('UNLOCK TABLES'); return "{$linktype} Port {$porta} or {$portb} is already linked"; } $result->closeCursor(); } if ($porta > $portb) { $tmp = $porta; $porta = $portb; $portb = $tmp; } $ret = FALSE !== usePreparedInsertBlade($table, array('porta' => $porta, 'portb' => $portb, 'cable' => mb_strlen($cable) ? $cable : '')); $dbxlink->exec('UNLOCK TABLES'); $ret = $ret and FALSE !== usePreparedExecuteBlade('UPDATE Port SET reservation_comment=NULL WHERE id IN(?, ?)', array($porta, $portb)); return $ret ? '' : 'query failed'; }
function exec8021QDeploy($object_id, $do_push) { global $dbxlink; $nsaved = $npushed = $nsaved_uplinks = 0; $dbxlink->beginTransaction(); if (NULL === ($vswitch = getVLANSwitchInfo($object_id, 'FOR UPDATE'))) { throw new InvalidArgException('object_id', $object_id, 'VLAN domain is not set for this object'); } $D = getStored8021QConfig($vswitch['object_id'], 'desired'); $C = getStored8021QConfig($vswitch['object_id'], 'cached'); try { $R = getRunning8021QConfig($vswitch['object_id']); } catch (RTGatewayError $e) { usePreparedExecuteBlade('UPDATE VLANSwitch SET last_errno=?, last_error_ts=NOW() WHERE object_id=?', array(E_8021Q_PULL_REMOTE_ERROR, $vswitch['object_id'])); $dbxlink->commit(); return 0; } $conflict = FALSE; $ok_to_push = array(); foreach (get8021QSyncOptions($vswitch, $D, $C, $R['portdata']) as $pn => $port) { // always update cache with new data from switch switch ($port['status']) { case 'ok_to_merge': // FIXME: this can be logged upd8021QPort('cached', $vswitch['object_id'], $pn, $port['both']); break; case 'ok_to_delete': del8021QPort($vswitch['object_id'], $pn); $nsaved++; break; case 'ok_to_add': add8021QPort($vswitch['object_id'], $pn, $port['right']); $nsaved++; break; case 'delete_conflict': case 'merge_conflict': case 'add_conflict': case 'martian_conflict': $conflict = TRUE; break; case 'ok_to_pull': // FIXME: this can be logged upd8021QPort('desired', $vswitch['object_id'], $pn, $port['right']); upd8021QPort('cached', $vswitch['object_id'], $pn, $port['right']); $nsaved++; break; case 'ok_to_push_with_merge': upd8021QPort('cached', $vswitch['object_id'], $pn, $port['right']); // fall through // fall through case 'ok_to_push': $ok_to_push[$pn] = $port['left']; break; } } // redo uplinks unconditionally $domain_vlanlist = getDomainVLANs($vswitch['domain_id']); $Dnew = apply8021QOrder($vswitch['template_id'], getStored8021QConfig($vswitch['object_id'], 'desired')); // Take new "desired" configuration and derive uplink port configuration // from it. Then cancel changes to immune VLANs and save resulting // changes (if any left). $new_uplinks = filter8021QChangeRequests($domain_vlanlist, $Dnew, produceUplinkPorts($domain_vlanlist, $Dnew, $vswitch['object_id'])); $nsaved_uplinks += replace8021QPorts('desired', $vswitch['object_id'], $Dnew, $new_uplinks); if ($nsaved + $nsaved_uplinks) { // saved configuration has changed (either "user" ports have changed, // or uplinks, or both), so bump revision number up) touchVLANSwitch($vswitch['object_id']); } if ($conflict) { usePreparedExecuteBlade('UPDATE VLANSwitch SET out_of_sync="yes", last_errno=?, last_error_ts=NOW() WHERE object_id=?', array(E_8021Q_VERSION_CONFLICT, $vswitch['object_id'])); } else { usePreparedExecuteBlade('UPDATE VLANSwitch SET last_errno=?, last_error_ts=NOW() WHERE object_id=?', array(E_8021Q_NOERROR, $vswitch['object_id'])); // Modified uplinks are very likely to differ from those in R-copy, // so don't mark device as clean, if this happened. This can cost // us an additional, empty round of sync, but at least out_of_sync // won't be mistakenly set to 'no'. // FIXME: A cleaner way of coupling pull and push operations would // be to split this function into two. if (!count($ok_to_push) and !$nsaved_uplinks) { usePreparedExecuteBlade('UPDATE VLANSwitch SET out_of_sync="no" WHERE object_id=?', array($vswitch['object_id'])); } elseif ($do_push) { usePreparedExecuteBlade('UPDATE VLANSwitch SET last_push_started=NOW() WHERE object_id=?', array($vswitch['object_id'])); try { $vlan_names = isset($R['vlannames']) ? $R['vlannames'] : array(); $npushed += exportSwitch8021QConfig($vswitch, $R['vlanlist'], $R['portdata'], $ok_to_push, $vlan_names); // update cache for ports deployed replace8021QPorts('cached', $vswitch['object_id'], $R['portdata'], $ok_to_push); usePreparedExecuteBlade('UPDATE VLANSwitch SET last_push_finished=NOW(), out_of_sync="no", last_errno=? WHERE object_id=?', array(E_8021Q_NOERROR, $vswitch['object_id'])); } catch (RTGatewayError $r) { usePreparedExecuteBlade('UPDATE VLANSwitch SET out_of_sync="yes", last_error_ts=NOW(), last_errno=? WHERE object_id=?', array(E_8021Q_PUSH_REMOTE_ERROR, $vswitch['object_id'])); callHook('pushErrorHandler', $object_id, $r); } } } $dbxlink->commit(); // start downlink work only after unlocking current object to make deadlocks less likely to happen // TODO: only process changed uplink ports if ($nsaved_uplinks) { initiateUplinksReverb($vswitch['object_id'], $new_uplinks); } return $nsaved + $npushed + $nsaved_uplinks; }