public function hasDatacenterCredential($credential, $useAnd = true) { if ($this->isSuperAdmin()) { return true; } $p_permtype = $credential[0]; $p_user_id = $this->getId(); //$p_cluster_id = $credential[1]; if (is_array($credential[1])) { $p_type_credential = (array) $credential[1]; if ($p_type_credential['node']) { error_log("MYUSER:[INFO]Node id: " . $p_type_credential['node']); $dc_c = new Criteria(); $dc_c->add(EtvaNodePeer::ID, $p_type_credential['node']); $node = EtvaNodePeer::doSelectOne($dc_c); $p_cluster_id = $node->getClusterId(); } elseif ($p_type_credential['server']) { error_log("MYUSER:[INFO]Server id: " . $p_type_credential['server']); $dc_c = new Criteria(); $dc_c->add(EtvaServerPeer::ID, (int) $p_type_credential['server'], Criteria::EQUAL); $server = EtvaServerPeer::doSelectOne($dc_c); $p_cluster_id = $server->getClusterId(); } elseif ($p_type_credential['cluster']) { error_log("MYUSER:[INFO]Cluster id: " . $p_type_credential['cluster']); $p_cluster_id = (int) $p_type_credential['cluster']; } else { error_log('MYUSER:[ERROR] hasDatacenterCredential invalid parameters'); return false; } } else { $p_cluster_id = $credential[1]; } // Check if user has permission $c = new Criteria(); $c->add(EtvaPermissionUserPeer::USER_ID, $p_user_id, Criteria::EQUAL); $c->addJoin(EtvaPermissionUserPeer::ETVAPERM_ID, EtvaPermissionPeer::ID); $c->add(EtvaPermissionPeer::PERM_TYPE, $p_permtype, Criteria::EQUAL); $c->addJoin(EtvaPermissionPeer::ID, EtvaPermissionClusterPeer::ETVAPERM_ID); $c->add(EtvaPermissionClusterPeer::CLUSTER_ID, $p_cluster_id); //error_log($c->toString()); $permission = EtvaPermissionUserPeer::doSelect($c); if ($permission) { return true; } // Check if user groups have permission $grps = $this->getGroups(); foreach ($grps as $value) { foreach ($value->getEtvaPermissionGroups() as $relObj) { $perm = $relObj->getEtvaPermission(); // validates the permission type if ($perm->getPermType() == $p_permtype) { // check if user has permission on the cluster foreach ($perm->getEtvaPermissionClusters() as $clusters) { if ($clusters->getClusterId() == $p_cluster_id) { error_log("Permission: " . $clusters->getClusterId()); return true; } } } } } // Permission not found return false; }
/** * Used to process soap requests => updateVirtAgentLvs * * Updates logical volume info sent by virt Agent * * Replies with succcess * * $request may contain the following keys: * - uid: uid (virtAgent sending request uid) * - lvs (object containing logical volumes info) * @return array array(success=>true) */ public function executeSoapUpdate(sfWebRequest $request) { /* * Check if the request is made via soapapi.php interface */ if (sfConfig::get('sf_environment') == 'soap') { $lvs = $request->getParameter('lvs'); $dtable = $request->getParameter('devicetable'); // check node ID correspondig to the uid given $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $request->getParameter('uuid')); if (!($etva_node = EtvaNodePeer::doSelectOne($c))) { $error_msg = sprintf('Object etva_node does not exist (%s).', $request->getParameter('uuid')); $error = array('success' => false, 'error' => $error_msg); //notify system log $node_message = Etva::getLogMessage(array('name' => $request->getParameter('uuid')), EtvaNodePeer::_ERR_NOTFOUND_UUID_); $message = Etva::getLogMessage(array('info' => $node_message), EtvaLogicalvolumePeer::_ERR_SOAPUPDATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $node_initialize = $etva_node->getInitialize(); if ($node_initialize != EtvaNode_VA::INITIALIZE_OK) { $error_msg = sprintf('Etva node initialize status: %s', $node_initialize); $error = array('success' => false, 'error' => $error_msg); return $error; } /* * check node cluster ID */ if (!($etva_cluster = $etva_node->getEtvaCluster())) { $error_msg = sprintf('Object etva_cluster does not exist for node %s', $etva_node->getName()); $error = array('success' => false, 'error' => $error_msg); //notify system log $cluster_message = Etva::getLogMessage(array('info' => $error_msg), EtvaClusterPeer::_ERR_CLUSTER_); $message = Etva::getLogMessage(array('info' => $cluster_message), EtvaLogicalvolumePeer::_ERR_SOAPUPDATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } # bulk device table with timeout $bulk_response_dtable = $etva_cluster->soapSend('device_table', array(), $etva_node, false, 120); /* * send logical volume to VA */ $lv_va = new EtvaLogicalvolume_VA(); $response = $lv_va->initialize($etva_node, $lvs, $dtable, $bulk_response_dtable); return $response; } // end soap request }
public static function getFirstActiveNode(EtvaCluster $cluster) { $c = new Criteria(); $c->add(EtvaNodePeer::CLUSTER_ID, $cluster->getId(), Criteria::EQUAL); $c->addAnd(EtvaNodePeer::STATE, EtvaNode::NODE_ACTIVE, Criteria::EQUAL); $c->addDescendingOrderByColumn(EtvaNodePeer::ID); $c->setLimit(1); $etva_node = EtvaNodePeer::doSelectOne($c); return $etva_node; }
public function executeSoapUpdate(sfWebRequest $request) { $data = $request->getParameter('data'); $success = false; if (sfConfig::get('sf_environment') == 'soap') { $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $request->getParameter('uuid')); if (!($etva_node = EtvaNodePeer::doSelectOne($c))) { $error_msg = sprintf('Object etva_node does not exist (%s).', $request->getParameter('uuid')); $error = array('success' => false, 'error' => $error_msg); //notify system log $node_message = Etva::getLogMessage(array('name' => $request->getParameter('uuid')), EtvaNodePeer::_ERR_NOTFOUND_UUID_); $message = Etva::getLogMessage(array('name' => 'data', 'info' => $node_message), EtvaNodePeer::_ERR_SOAPUPDATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $node_name = $etva_node->getName(); /* * on node soapupdate check if field is state and update keepalive date */ if (isset($data['state'])) { $etva_node->setLastKeepalive('NOW'); if ($etva_node->getState() < EtvaNode::NODE_INACTIVE) { // dont touch //$data['state'] = $etva_node->getState(); $data['state'] = EtvaNode_VA::calcState($etva_node); } } $check_mdstat = $request->getParameter('checkmdstat'); if ($check_mdstat) { $node_va = new EtvaNode_VA($etva_node); $node_va->updateLastMessage($check_mdstat); } $etva_node->fromArray($data, BasePeer::TYPE_FIELDNAME); try { $etva_node->save(); $priority = EtvaEventLogger::INFO; $success = true; $message = ''; #$message = Etva::getLogMessage(array('name'=>$etva_node->getName()), EtvaNodePeer::_OK_SOAPUPDATE_); } catch (Exception $e) { $priority = EtvaEventLogger::ERR; $message = Etva::getLogMessage(array('name' => $etva_node->getName(), 'info' => 'Could not save data'), EtvaNodePeer::_ERR_SOAPUPDATE_); } if ($message != '') { //notify system log $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => $priority))); } $result = array('success' => $success, 'response' => $message); return $result; } }
public function restore($backup_id) { //clear stage cache $this->delStage(self::RESTORE_STAGE); chdir(sfConfig::get('sf_root_dir')); /* * TELL VA to reset stuff */ $node_list = EtvaNodePeer::doSelect(new Criteria()); $node_num = count($node_list); if ($node_num != 1) { /* * ERROR should be only one element (standard ETVA release only) */ $msg = "Sould only be one Virtualization Agent! {$node_num} found!"; $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => $msg, 'error' => $msg); return $data; } $node = $node_list[0]; /* * check node state ok to comm with agent */ if (!$node->getState()) { $node_name = $node->getName(); $msg = sfContext::getInstance()->getI18N()->__(EtvaNodePeer::_STATE_DOWN_, array('%name%' => $node_name)); $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => 'check_nodes', 'info' => $msg, 'error' => $msg); return $data; } $this->disable(); /* * * FIRST THING....CLEANUP DESTINATION FOLDER AND GET RESTORE ARCHIVE * */ IOFile::unlinkRecursive($this->archive_base_dir, false); $full_path = $this->archive_base_dir . '/' . self::ARCHIVE_FILE; $this->setStage(self::RESTORE_STAGE, self::GET_RESTORE); $response = $this->getApplianceBackup($backup_id, $full_path); /* * * DECOMPRESS BACKUP ARCHIVE * */ $this->setStage(self::RESTORE_STAGE, self::ARCHIVE_RESTORE); $create_gz = new gzip_file($full_path); $base_dir = $this->archive_base_dir; $create_gz->set_options(array('basedir' => $base_dir, 'overwrite' => 1)); $create_gz->extract_files(); /* * get DB file and put in tmp_db_filename */ $db_filename = $base_dir . '/' . self::DB_FILE; if (!file_exists($db_filename)) { return array('success' => false, 'error' => 'no file'); } // move DB backup to correct folder... rename($db_filename, $this->tmp_db_filename); /* * * CLEAN DB ???? * */ /* * delete tables and build again.... */ $command = "symfony propel:insert-sql --no-confirmation"; $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils"; ob_start(); passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $return); $result = ob_get_contents(); ob_end_clean(); if ($result != 0 || $return != 0) { $msg = 'An error occurred while deleting DB. Aborted!' . $status; $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => self::DB_RESTORE, 'info' => $msg, 'error' => $msg); return $data; } /* * * RESTORE CENTRAL MANAGEMENT BACKUP (DB) * * */ $this->setStage(self::RESTORE_STAGE, self::DB_RESTORE); /* * load data to DB */ //sfContext::getInstance()->getStorage()->regenerate(true); exec("symfony propel:data-load " . $this->tmp_db_filename, $output, $status); if ($status != 0) { // aconteceu erro $msg = 'An error occurred while generating DB dump. Aborted!' . $status; $data = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'action' => self::DB_RESTORE, 'info' => $msg, 'error' => $msg); return $data; } /* * * generate session to stay logged in... * */ sfContext::getInstance()->getStorage()->regenerate(); $this->setStage(self::RESTORE_STAGE, self::VA_RESET); $node_va = new EtvaNode_VA($node); /* * get new uuid from DB */ $backup_node = EtvaNodePeer::doSelectOne(new Criteria()); $uuid = $backup_node->getUuid(); $response = $node_va->send_change_uuid($uuid); if (!$response['success']) { return $response; } $response = array('success' => true); return $response; }
/** * Used to process soap requests => updateVirtAgentVgs * * Updates volume group info sent by virt Agent * The request should be made throught soapapi * * Replies with succcess * * $request may contain the following keys: * - uid: uid (virtAgent sending request uid) * - vgs (object containing volumes info) * @return array array(success=>true) */ public function executeSoapUpdate(sfWebRequest $request) { if (sfConfig::get('sf_environment') == 'soap') { $vgs = $request->getParameter('vgs'); // check node ID correspondig to the uid given $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $request->getParameter('uuid')); if (!($etva_node = EtvaNodePeer::doSelectOne($c))) { $error_msg = sprintf('Object etva_node does not exist (%s).', $request->getParameter('uuid')); $error = array('success' => false, 'error' => $error_msg); //notify event log $node_message = Etva::getLogMessage(array('name' => $request->getParameter('uuid')), EtvaNodePeer::_ERR_NOTFOUND_UUID_); $message = Etva::getLogMessage(array('info' => $node_message), EtvaVolumegroupPeer::_ERR_SOAPUPDATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $node_initialize = $etva_node->getInitialize(); if ($node_initialize != EtvaNode_VA::INITIALIZE_OK) { $error_msg = sprintf('Etva node initialize status: %s', $node_initialize); $error = array('success' => false, 'error' => $error_msg); return $error; } /* * check node cluster ID */ if (!($etva_cluster = $etva_node->getEtvaCluster())) { $error_msg = sprintf('Object etva_cluster does not exist for node %s', $etva_node->getName()); $error = array('success' => false, 'error' => $error_msg); //notify event log $cluster_message = Etva::getLogMessage(array('info' => $error_msg), EtvaClusterPeer::_ERR_CLUSTER_); $message = Etva::getLogMessage(array('info' => $cluster_message), EtvaVolumegroupPeer::_ERR_SOAPUPDATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $etva_data = Etva::getEtvaModelFile(); $etvamodel = $etva_data['model']; $force_regist = false; // for model standard, if vgs initialize then force registration if ($etvamodel == 'standard' && !$etva_node->hasVgs()) { $force_regist = true; } error_log("EtvaVolumegroup soapUpdate force_regist=" . $force_regist . " etvamodel=" . $etvamodel . " hasVgs=" . $etva_node->hasVgs()); //error_log(print_r($vgs,true)); /* * send volume group to VA */ $vg_va = new EtvaVolumegroup_VA(); $response = $vg_va->initialize($etva_node, $vgs, $force_regist); return $response; } }
public function initialize($data) { $uuid = $data['uuid']; $etva_data = Etva::getEtvaModelFile(); if (!$etva_data) { $error_msg = 'Could not process etva-model.conf'; $error = array('success' => false, 'error' => $error_msg); //notify system log $message = Etva::getLogMessage(array('name' => $data['name'], 'info' => $error_msg), EtvaNodePeer::_ERR_SOAPINIT_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $etvamodel = $etva_data['model']; $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $uuid); $etva_node = EtvaNodePeer::doSelectOne($c); if ($etva_node) { if ($etva_node->getState() < EtvaNode::NODE_INACTIVE) { // dont touch //$data['state'] = $etva_node->getState(); $data['state'] = $this->calcState($etva_node, EtvaNode::NODE_ACTIVE); } if (!isset($data['isSpareNode'])) { $data['isSpareNode'] = $etva_node->getIssparenode() ? 1 : 0; } if (!isset($data['fencingconf'])) { $data['fencingconf'] = $etva_node->getFencingconf(); } $data['cluster_id'] = $etva_node->getClusterId(); $node_initialize = $etva_node->getInitialize(); $data['initialize'] = $node_initialize; if (empty($node_initialize)) { $data['initialize'] = self::INITIALIZE_PENDING; } if ($etvamodel == 'standard') { $data['initialize'] = self::INITIALIZE_OK; } else { if ($node_initialize != self::INITIALIZE_OK) { return array('success' => true); } } $data['id'] = $etva_node->getId(); /* * calculate free mem */ $etva_node->setMemtotal($data['memtotal']); $etva_node->updateMemFree(); $data['memfree'] = $etva_node->getMemfree(); $uuid = $etva_node->getUuid(); $form = new EtvaNodeForm($etva_node); } else { /* * add default cluster ID to node */ if (!($default_cluster = EtvaClusterPeer::retrieveDefaultCluster())) { $error_msg = sprintf('Default Object etva_cluster does not exist '); $error = array('success' => false, 'error' => $error_msg); //notify system log $cluster_message = Etva::getLogMessage(array('info' => $error_msg), EtvaClusterPeer::_ERR_DEFAULT_CLUSTER_); $message = Etva::getLogMessage(array('name' => $data['name'], 'info' => $cluster_message), EtvaNodePeer::_ERR_SOAPINIT_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $data['cluster_id'] = $default_cluster->getId(); $form = new EtvaNodeForm(); $uuid = EtvaNodePeer::generateUUID(); $data['initialize'] = self::INITIALIZE_PENDING; if ($etvamodel == 'standard') { $data['initialize'] = self::INITIALIZE_OK; } /* * calculate free mem */ $etva_node = new EtvaNode(); $etva_node->setMemtotal($data['memtotal']); $etva_node->updateMemFree(); $etva_node->setClusterId($default_cluster->getId()); $data['memfree'] = $etva_node->getMemfree(); $data['uuid'] = $uuid; } $this->clearLastMessage(); $result = $this->processNodeForm($data, $form); if (!$result['success']) { return $result; } // reset guest agent info $this->reset_gas_info($etva_node); /* * * check if has restore to perform.... */ $apli = new Appliance(); $action = $apli->getStage(Appliance::RESTORE_STAGE); if ($action) { $backup_url = $apli->get_backupconf_url(Appliance::VA_ARCHIVE_FILE, $uuid, 'VA'); if ($backup_url) { $result['reset'] = 1; $result['backup_url'] = $backup_url; /* * send pvs, vgs, lvs */ $node_devs = $etva_node->getEtvaNodePhysicalvolumesJoinEtvaPhysicalvolume(); $devs_va = array(); foreach ($node_devs as $data) { $dev = $data->getEtvaPhysicalvolume(); $devs_va[] = $dev->_VA(); } $result['pvs'] = $devs_va; $node_vgs = $etva_node->getEtvaNodeVolumegroupsJoinEtvaVolumegroup(); $vgs_va = array(); foreach ($node_vgs as $data) { $vg = $data->getEtvaVolumegroup(); $vgs_va[] = $vg->_VA(); } $result['vgs'] = $vgs_va; $node_lvs = $etva_node->getEtvaNodeLogicalvolumesJoinEtvaLogicalvolume(); $lvs_va = array(); foreach ($node_lvs as $data) { $lv = $data->getEtvaLogicalvolume(); $lvs_va[] = $lv->_VA(); } $result['lvs'] = $lvs_va; } $apli->setStage(Appliance::RESTORE_STAGE, Appliance::VA_INIT); } return $result; }
/** * Moves an unaccepted node to the given cluster * @param sfWebRequest $request * json, cluster id (target) and node id * @return json, success */ public function executeJsonMoveNode(sfWebRequest $request) { $cluster_id = $request->getParameter('to_cluster_id'); $node_id = $request->getParameter('node_id'); try { $c = new Criteria(); $c->add(EtvaNodePeer::ID, $node_id, Criteria::EQUAL); if (EtvaNodePeer::doCount($c) == 1) { $etva_node = EtvaNodePeer::doSelectOne($c); $etva_node->setClusterId($cluster_id); $etva_node->save(); } else { $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $node_id)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); // if is browser request return text renderer $error = json_encode($error); return $this->renderText($error); } } catch (Exception $e) { error_log("CLUSTER[ERROR] Move of node " . $node_id . " into cluster " . $cluster_id . " failed!"); $error = array('success' => false, 'error' => array('cluster' => $e->getMessage())); $error = json_encode($error); return $this->renderText($error); } $msg_i18n = $this->getContext()->getI18N()->__('Node %name% moved successfully', array('%name%' => $etva_node->getName())); // EtvaServerPeer::_ERR_NOTFOUND_ID_,array('%id%'=>$sid)); $return = array('agent' => sfConfig::get('config_acronym'), 'success' => true, 'info' => $msg_i18n); $result = json_encode($return); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }
/** * process soap update requests of virtual machines * * $request['uuid'] //node uuid * $request['action'] // domains_stats (updates vms state) or domains_init (initializes agent servers) * $request['vms'] //list of virtual machines sent by VA * * @return array servers array on CM DB * */ public function executeSoapUpdate(sfWebRequest $request) { if (sfConfig::get('sf_environment') == 'soap') { $action = $request->getParameter('action'); $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $request->getParameter('uuid')); if (!($etva_node = EtvaNodePeer::doSelectOne($c))) { $error_msg = sprintf('Object etva_node does not exist (%s).', $request->getParameter('uuid')); $error = array('success' => false, 'error' => $error_msg); //notify event log $node_message = Etva::getLogMessage(array('name' => $request->getParameter('uuid')), EtvaNodePeer::_ERR_NOTFOUND_UUID_); $message = Etva::getLogMessage(array('info' => $node_message), EtvaServerPeer::_ERR_SOAPUPDATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return $error; } $node_initialize = $etva_node->getInitialize(); if ($node_initialize != EtvaNode_VA::INITIALIZE_OK) { $error_msg = sprintf('Etva node initialize status: %s', $node_initialize); $error = array('success' => false, 'error' => $error_msg); return $error; } $querysrvs = EtvaServerQuery::create(); $querysrvs->orderByPriorityHa('desc'); $node_servers = $etva_node->getEtvaServers($querysrvs); switch ($action) { case 'domains_stats': $vms = (array) $request->getParameter('vms'); $vms_uuids = array(); $vms = !empty($vms) ? (array) $vms : array(); $not_affected = 0; foreach ($vms as $vm) { $vms_uuids[$vm->uuid] = (array) $vm; } foreach ($node_servers as $node_server) { //error_log(sprintf('node_servers id=%s name=%s priority_ha=%s',$node_server->getId(),$node_server->getName(),$node_server->getPriorityHa())); $server_uuid = $node_server->getUuid(); if (!$node_server->getUnassigned()) { // assigned only // and is not migrating if ($node_server->getVmState() !== EtvaServer::STATE_MIGRATING) { if (isset($vms_uuids[$server_uuid])) { $node_server->setVmState($vms_uuids[$server_uuid]['state']); if (isset($vms_uuids[$server_uuid]['has_snapshots'])) { // set snapshots flags $node_server->setHassnapshots($vms_uuids[$server_uuid]['has_snapshots']); } $node_server->save(); } else { $message_s = sprintf('Node %s could not check state for virtual machine %s(%s)', $etva_node->getName(), $node_server->getName(), $server_uuid); $not_affected++; $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message_s, 'priority' => EtvaEventLogger::ERR))); error_log($message_s); } } else { $message_s = sprintf('Node %s could not check state for virtual machine %s(%s) beacuse is migrating', $etva_node->getName(), $node_server->getName(), $server_uuid); error_log($message_s); } } } // update free memory $etva_node->updateMemFree(); $etva_node->save(); //notify system log if ($not_affected > 0) { $message = sprintf('Node %s could not check for %d virtual machine(s) state', $etva_node->getName(), $not_affected); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); return array('success' => false, 'reason' => '_servers_inconsistency_'); } return array('success' => true); break; case 'domains_gainfo': $vms = (array) $request->getParameter('vms'); $vms_uuids = array(); $vms = !empty($vms) ? (array) $vms : array(); foreach ($vms as $vm) { $vms_uuids[$vm->uuid] = (array) $vm; } foreach ($node_servers as $node_server) { $server_uuid = $node_server->getUuid(); if (!$node_server->getUnassigned()) { // assigned only if (isset($vms_uuids[$server_uuid])) { //$str = json_encode($vms_uuids[$server_uuid]['msg']); $str = $vms_uuids[$server_uuid]['msg']; $obj = json_decode($str); $node_server->mergeGaInfo($str); // merge GA info $node_server->resetHeartbeat(EtvaServerPeer::_GA_RUNNING_); $node_server->setHbnrestarts(0); // reset num of restarts $node_server->save(); $message = sprintf('domains_gainfo guest agent info updated (id=%s name=%s type=%s hb=%s)', $node_server->getId(), $node_server->getName(), $obj->__name__, $node_server->getHeartbeat()); error_log($message); /*$this->dispatcher->notify( new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message,'priority'=>EtvaEventLogger::INFO)));*/ } } } return array('success' => true); break; case 'domains_sync': $new_servers = array(); $vms = (array) $request->getParameter('vms'); $vms_uuids = array(); $vms = !empty($vms) ? (array) $vms : array(); $not_affected = 0; foreach ($vms as $vm) { if ($vm) { $vms_uuids[$vm->uuid] = (array) $vm; } } foreach ($node_servers as $node_server) { error_log(sprintf('domains_sync server id=%s name=%s priority_ha=%s', $node_server->getId(), $node_server->getName(), $node_server->getPriorityHa())); if (!$node_server->getUnassigned()) { // ignore unassigned servers $server_name = $node_server->getName(); $new_servers[$server_name] = $node_server->_VA(); $server_uuid = $node_server->getUuid(); if (isset($vms_uuids[$server_uuid])) { if ($vms_uuids[$server_uuid]['state'] != EtvaServer::RUNNING && ($node_server->getVmState() == EtvaServer::RUNNING || $node_server->getAutostart())) { error_log(sprintf('domains_sync server id=%s name=%s should be running', $node_server->getId(), $node_server->getName())); $node_server->setHblaststart('NOW'); // update hb last start $node_server->save(); } unset($vms_uuids[$server_uuid]); } } } $servers_names = array_keys($new_servers); $servers = implode(', ', $servers_names); /* * check if is an appliance restore operation... */ $apli = new Appliance(); $action = $apli->getStage(Appliance::RESTORE_STAGE); if ($action) { $apli->setStage(Appliance::RESTORE_STAGE, Appliance::VA_UPDATE_VMS); } //notify system log if ($new_servers) { $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_node->getName(), 'info' => $servers), EtvaServerPeer::_OK_SOAPUPDATE_), 'priority' => EtvaEventLogger::INFO))); } $load_servers = count($new_servers) ? array_values($new_servers) : array(); $destroy_servers = count($vms_uuids) ? array_values($vms_uuids) : array(); $return = array('success' => true, 'load_servers' => $load_servers, 'destroy_servers' => $destroy_servers); return $return; break; default: $new_servers = array(); foreach ($node_servers as $node_server) { if (!$node_server->getUnassigned()) { // ignore unassigned servers $server_name = $node_server->getName(); $new_servers[$server_name] = $node_server->_VA(); } } $servers_names = array_keys($new_servers); $servers = implode(', ', $servers_names); /* * check if is an appliance restore operation... */ $apli = new Appliance(); $action = $apli->getStage(Appliance::RESTORE_STAGE); if ($action) { $apli->setStage(Appliance::RESTORE_STAGE, Appliance::VA_UPDATE_VMS); } //notify system log if ($new_servers) { $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_node->getName(), 'info' => $servers), EtvaServerPeer::_OK_SOAPUPDATE_), 'priority' => EtvaEventLogger::INFO))); } return $new_servers; } } }
public function executeJsonPermsWithGroupsUsers($request) { $isAjax = $request->isXmlHttpRequest(); // if(!$isAjax) return $this->redirect('@homepage'); $level = $request->getParameter('level'); $id = $request->getParameter('id'); $p_permtype = $request->getParameter('permtype'); $u = new Criteria(); $g = new Criteria(); $elements = array(); $elements['id'] = 1; // if has node level, find clusterid if ($level == 'node') { $c = new Criteria(); $c->add(EtvaNodePeer::ID, $id); $node = EtvaNodePeer::doSelectOne($c); $id = $node->getClusterId(); $level = 'cluster'; } if ($level == 'server') { $users = EtvaPermissionUserQuery::create()->useEtvaPermissionQuery()->filterByPermType($p_permtype)->useEtvaPermissionServerQuery()->filterByServerId($id)->endUse()->endUse()->find(); foreach ($users as $user) { $elements['etva_permission_user_list'][] = $user->getUserId(); } $groups = EtvaPermissionGroupQuery::create()->useEtvaPermissionQuery()->filterByPermType($p_permtype)->useEtvaPermissionServerQuery()->filterByServerId($id)->endUse()->endUse()->find(); foreach ($groups as $group) { $elements['etva_permission_group_list'][] = $group->getGroupId(); } } elseif ($level == 'cluster') { $users = EtvaPermissionUserQuery::create()->useEtvaPermissionQuery()->filterByPermType($p_permtype)->useEtvaPermissionClusterQuery()->filterByClusterId($id)->endUse()->endUse()->find(); foreach ($users as $user) { $elements['etva_permission_user_list'][] = $user->getUserId(); } $groups = EtvaPermissionGroupQuery::create()->useEtvaPermissionQuery()->filterByPermType($p_permtype)->useEtvaPermissionClusterQuery()->filterByClusterId($id)->endUse()->endUse()->find(); foreach ($groups as $group) { $elements['etva_permission_group_list'][] = $group->getGroupId(); } } else { $info = array('success' => false, 'error' => 'Wrong parameters'); $error = $this->setJsonError($info); return $this->renderText($error); } $final = array('total' => 1, 'data' => $elements); $result = json_encode($final); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }
function updateVirtAgentLogs($node_uuid, $data) { $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $node_uuid); $return = 0; $etva_node = EtvaNodePeer::doSelectOne($c); if (!($etva_node = EtvaNodePeer::doSelectOne($c))) { $error_msg = sprintf('Object etva_node does not exist (%s).', $node_uuid); $error = array('success' => false, 'error' => $error_msg); return $error; } $node_initialize = $etva_node->getInitialize(); if ($node_initialize != EtvaNode_VA::INITIALIZE_OK) { $error_msg = sprintf('Etva node initialize status: %s', $node_initialize); $error = array('success' => false, 'error' => $error_msg); return $error; } $node_uuid = $etva_node->getUuid(); $cpu_load = $data->load; $cpu_load_sort = array($cpu_load->onemin, $cpu_load->fivemin, $cpu_load->fifteenmin); $cpu_load = new NodeLoadRRA($node_uuid); $cpu_load->update($cpu_load_sort); $virtServers = $data->virtualmachines; if ($virtServers) { foreach ($virtServers as $server_name => $server_data) { if ($etva_server = $etva_node->retrieveServerByName($server_name)) { if (isset($server_data->network)) { /* * store network info in RRA file */ $server_network_data = $server_data->network; /* * create file per network device */ foreach ($server_network_data as $intfname => $intfdata) { $macaddr = $intfdata->macaddr; $etva_network = $etva_server->retrieveByMac($macaddr); if ($etva_network) { $target = $etva_network->getTarget(); // if target not in network table of the DB if ($target != $intfname) { $etva_network->updateTarget($intfname); } $tx = $intfdata->tx_bytes; $rx = $intfdata->rx_bytes; $intf_sort = array($rx, $tx); $mac_strip = str_replace(':', '', $macaddr); // create log file $server_network_rra = new ServerNetworkRRA($node_uuid, $etva_server->getUuid(), $mac_strip); //send/update file information $return = $server_network_rra->update($intf_sort); } } } // end server networks /* * disk stuff */ if (isset($server_data->disk)) { $server_disk_data = $server_data->disk; foreach ($server_disk_data as $disk => $diskdata) { $diskname = $diskdata->name; $read_b = $diskdata->rd_bytes; $write_b = $diskdata->wr_bytes; $disk_sort = array($read_b, $write_b); // create log file $server_disk_rw_log = new ServerDisk_rwRRA($node_uuid, $etva_server->getUuid(), $diskname); //send/update file information $return = $server_disk_rw_log->update($disk_sort); /* * DISK SPACE RRA NOT USED ANYMORE */ //$size = $diskdata->size; //$freesize = $diskdata->freesize; //$disk_space = array($size,$freesize); //$server_disk_spaceRRA = new ServerDiskSpaceRRA($node_uuid,$etva_server->getUuid(),$diskname); //$return = $server_disk_spaceRRA->update($disk_space); } // end server disk } // store cpu utilization $server_cpu_data = $server_data->cpu; $server_cpu_per = array($server_cpu_data->cpu_per); // $logger->log("cpu ".$server_cpu_data->cpu_per); // create log file $server_cpu_per_rra = new ServerCpuUsageRRA($node_uuid, $etva_server->getUuid()); //send/update file information $return = $server_cpu_per_rra->update($server_cpu_per); /* * store memory info */ // store memory utilization $server_memory_data = $server_data->memory; $server_memory_per = array($server_memory_data->mem_per); // create log file $server_memory_per_rra = new ServerMemoryUsageRRA($node_uuid, $etva_server->getUuid()); //send/update file information $return = $server_memory_per_rra->update($server_memory_per); $server_memory_sort = array($server_memory_data->mem_m, $server_memory_data->mem_v); $server_memory = new ServerMemoryRRA($node_uuid, $etva_server->getUuid()); $server_memory->update($server_memory_sort); } // end virtualmachine stuff } } // $this->updateVirtAgentLogs_($node_uuid,$data); $all_params = array('request' => array('uuid' => $etva_node->getUuid(), 'data' => $data, 'method' => 'updateVirtAgentLogs'), 'response' => $return); // log function called $dispatcher = sfContext::getInstance()->getEventDispatcher(); $dispatcher->notify(new sfEvent($this, sfConfig::get('app_virtsoap_log'), $all_params)); return $return; }
/** * Used to process soap requests => updateVirtAgentVlans * * Updates vlan info sent by virt Agent * * Replies with succcess * * $request may contain the following keys: * - uid: uid (virtAgent sending request uid) * - vlans (object containing vlans info) * @return array array(new vlans) */ public function executeSoapUpdate(sfWebRequest $request) { if (sfConfig::get('sf_environment') == 'soap') { //get config data file $etva_data = Etva::getEtvaModelFile(); //check etva model type $etvamodel = $etva_data['model']; $vlans = $request->getParameter('vlans'); $vlans_names = array(); foreach ($vlans as $vlanInfo) { $vlan_data = (array) $vlanInfo; $vlans_names[] = $vlan_data['name']; } $c = new Criteria(); $c->add(EtvaNodePeer::UUID, $request->getParameter('uuid')); if (!($etva_node = EtvaNodePeer::doSelectOne($c))) { $error_msg = sprintf('Object etva_node does not exist (%s).', $request->getParameter('uuid')); $node_log = Etva::getLogMessage(array('name' => $request->getParameter('uuid')), EtvaNodePeer::_ERR_NOTFOUND_UUID_); //notify system log $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('info' => $node_log), EtvaVlanPeer::_ERR_SOAPUPDATE_), 'priority' => EtvaEventLogger::ERR))); $error = array('success' => false, 'error' => $error_msg); return $error; } $node_initialize = $etva_node->getInitialize(); if ($node_initialize != EtvaNode_VA::INITIALIZE_OK) { $error_msg = sprintf('Etva node initialize status: %s', $node_initialize); $error = array('success' => false, 'error' => $error_msg); return $error; } /* * checks if CM vlans exists on node info Vlans * return vlans to be created on node * */ // filter results by cluster $vlan_criteria = new Criteria(); $vlan_criteria->add(EtvaVlanPeer::CLUSTER_ID, $etva_node->getClusterId()); $etva_vlans = EtvaVlanPeer::doSelect($vlan_criteria); $new_vlans = array(); foreach ($etva_vlans as $etva_vlan) { if (!in_array($etva_vlan->getName(), $vlans_names)) { $data = array('name' => $etva_vlan->getName(), 'ifout' => $etva_vlan->getIntf()); /* * if model type == enterprise send vlan ID and untagged/tagged option */ if (strtolower($etvamodel) != 'standard') { $data['vlanid'] = $etva_vlan->getVlanId(); $tagged = $etva_vlan->getTagged(); if ($tagged) { $data['vlan_tagged'] = 1; } else { $data['vlan_untagged'] = 1; } } $new_vlans[$etva_vlan->getName()] = $data; } } $vlans_names = array_keys($new_vlans); $vlans = implode(', ', $vlans_names); //notify system log $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $etva_node->getName(), 'info' => $vlans), EtvaVlanPeer::_OK_SOAPUPDATE_), 'priority' => EtvaEventLogger::INFO))); return $new_vlans; } // end soap request }