public static function loadServicesPartials_old(EtvaServer $etva_server) { $server_services = $etva_server->getEtvaServices(); $module_agent = strtolower($etva_server->getAgentTmpl()); $directory = sfContext::getInstance()->getConfiguration()->getTemplateDir(strtolower($etva_server->getAgentTmpl()), 'viewSuccess.php'); $services_data = self::listDir($directory, '/_ETVOIP_([^_]+)\\.php/'); die; foreach ($server_services as $service) { $tmpl = $etva_server->getAgentTmpl() . '_' . $service->getNameTmpl(); $service_path = sfContext::getInstance()->getConfiguration()->getTemplateDir($module_agent, '_' . $tmpl . '.php'); if ($service_path) { include_partial($module_agent . '/' . $tmpl, array('etva_server' => $etva_server, 'etva_service' => $service)); } } }
public function getAdmissionGate(EtvaServer $server) { if ($this->getHasNodeHA()) { if ($this->getAdmissionGateType() == self::CLUSTER_ADMISSION_GATE_TYPE_N_HOSTS_TOLERATE || $this->getAdmissionGateType() == self::CLUSTER_ADMISSION_GATE_TYPE_PER_RESOURCES) { $nodes = EtvaNodeQuery::create()->leftJoin('EtvaNode.EtvaServerAssign')->leftJoin('EtvaServerAssign.EtvaServer')->addJoinCondition('EtvaServer', 'EtvaServer.VmState = ?', EtvaServer::RUNNING)->withColumn('SUM(EtvaServer.Mem)', 'sum_mem')->withColumn('SUM(EtvaServer.Vcpu)', 'sum_vcpu')->groupBy('EtvaNode.Id')->orderBy('EtvaNode.Memtotal', 'desc')->filterByClusterId($this->getId())->filterByState(EtvaNode::NODE_ACTIVE)->filterByInitialize(EtvaNode::INITIALIZE_OK)->find(); $n_hosts_tolerate = 0; if ($this->getAdmissionGateType() == self::CLUSTER_ADMISSION_GATE_TYPE_N_HOSTS_TOLERATE) { $n_hosts_tolerate = $this->getAdmissionGateValue(); } $n_hosts_tolerate_value = $n_hosts_tolerate; $sum_all_Nodes_memtotal = 0; $sum_n_biggest_Nodes_memtotal = 0; $sum_all_running_Servers_mem = 0; $sum_all_Nodes_memfree = 0; $max_cpu_Nodes = 0; $server_mem_bytes = $server->getMem() * 1024 * 1024; foreach ($nodes as $node) { if ($n_hosts_tolerate) { $sum_n_biggest_Nodes_memtotal = +$node->getMemtotal(); $n_hosts_tolerate--; // decrease } $sum_all_Nodes_memtotal += $node->getMemtotal(); $sum_all_Nodes_memfree += $node->getMemfree(); $sum_all_running_Servers_mem += $node->getSum_mem(); if (!$max_cpu_Nodes || $node->getCputotal() < $max_cpu_Nodes) { $max_cpu_Nodes = $node->getCputotal(); } } $sum_all_running_Servers_mem_bytes = $sum_all_running_Servers_mem * 1024 * 1024; error_log("getAdmissionGate getAdmissionGateType=" . $this->getAdmissionGateType() . " getAdmissionGateValue=" . $this->getAdmissionGateValue() . " sum_all_Nodes_memtotal={$sum_all_Nodes_memtotal} sum_n_biggest_Nodes_memtotal={$sum_n_biggest_Nodes_memtotal} sum_all_running_Servers_mem_bytes={$sum_all_running_Servers_mem_bytes} sum_all_Nodes_memfree={$sum_all_Nodes_memfree} max_cpu_Nodes={$max_cpu_Nodes} vcpu=" . $server->getVcpu() . " mem=" . $server->getMem() . " name=" . $server->getName()); if ($this->getAdmissionGateType() == self::CLUSTER_ADMISSION_GATE_TYPE_N_HOSTS_TOLERATE) { $sum_all_running_Servers_memfree_bytes_after = $sum_all_Nodes_memtotal - $sum_all_running_Servers_mem_bytes - $server_mem_bytes; $sum_all_Nodes_memfree_after = $sum_all_Nodes_memfree - $server_mem_bytes; error_log("getAdmissionGate TYPE_N_HOSTS_TOLERATE n_hosts_tolerate_value={$n_hosts_tolerate_value} sum_all_running_Servers_memfree_bytes_after={$sum_all_running_Servers_memfree_bytes_after} sum_all_Nodes_memfree_after={$sum_all_Nodes_memfree_after} sum_n_biggest_Nodes_memtotal={$sum_n_biggest_Nodes_memtotal} max_cpu_Nodes={$max_cpu_Nodes} vcpu=" . $server->getVcpu() . " mem=" . $server->getMem() . " name=" . $server->getName()); # the all free memory get from running server should not be less then total of sum of memory of biggest nodes if ($sum_all_running_Servers_memfree_bytes_after < $sum_n_biggest_Nodes_memtotal) { return array('success' => false, 'info' => sfContext::getInstance()->getI18N()->__('Unfulfilled policy for (%n_hosts_tolerate_value%) host(s) failures tolerate. The calc of free memory from running servers say that has %free_mem% to garantee %total_mem%.', array('%n_hosts_tolerate_value%' => $n_hosts_tolerate_value, '%free_mem%' => $sum_all_running_Servers_memfree_bytes_after, '%total_mem%' => $sum_n_biggest_Nodes_memtotal))); } # the all free memory verified on nodes should not be less then total of sum of memory of biggest nodes if ($sum_all_Nodes_memfree_after < $sum_n_biggest_Nodes_memtotal) { return array('success' => false, 'info' => sfContext::getInstance()->getI18N()->__('Unfulfilled policy for (%n_hosts_tolerate_value%) host(s) failures tolerate. The node info says that has %free_mem% free memory to garantee %total_mem%.', array('%n_hosts_tolerate_value%' => $n_hosts_tolerate_value, '%free_mem%' => $sum_all_Nodes_memfree_after, '%total_mem%' => $sum_n_biggest_Nodes_memtotal))); } if ($server->getVcpu() > $max_cpu_Nodes) { return array('success' => false, 'info' => sfContext::getInstance()->getI18N()->__('Number max. of cpus (%max_cpu_Nodes%) exceeded.', array('%max_cpu_Nodes%' => $max_cpu_Nodes))); } } if ($this->getAdmissionGateType() == self::CLUSTER_ADMISSION_GATE_TYPE_PER_RESOURCES) { $per_resources_value = $this->getAdmissionGateValue(); $per_resources = $per_resources_value / 100; $sum_all_running_Servers_memfree_bytes_after = $sum_all_Nodes_memtotal - $sum_all_running_Servers_mem_bytes - $server_mem_bytes; $sum_all_Nodes_memfree_after = $sum_all_Nodes_memfree - $server_mem_bytes; $all_Node_memtotal_threshold = $sum_all_Nodes_memtotal * $per_resources; error_log("getAdmissionGate TYPE_PER_RESOURCES sum_all_running_Servers_memfree_bytes_after={$sum_all_running_Servers_memfree_bytes_after} sum_all_Nodes_memfree_after={$sum_all_Nodes_memfree_after} all_Node_memtotal_threshold={$all_Node_memtotal_threshold} max_cpu_Nodes={$max_cpu_Nodes} vcpu=" . $server->getVcpu() . " mem=" . $server->getMem() . " name=" . $server->getName()); # the all free memory get from running server should not be less then percentage of memory of nodes if ($sum_all_running_Servers_memfree_bytes_after < $all_Node_memtotal_threshold) { return array('success' => false, 'info' => sfContext::getInstance()->getI18N()->__('Unfulfilled policy for (%per_resources_value%) percentage of resources reserved to failover. The calc of free memory from running servers say that has %free_mem% to garantee %total_mem%.', array('%per_resources_value%' => $per_resources_value, '%free_mem%' => $sum_all_running_Servers_memfree_bytes_after, '%total_mem%' => $all_Node_memtotal_threshold))); } # the all free memory verified on nodes should not be less then percentage of memory of nodes if ($sum_all_Nodes_memfree_after < $all_Node_memtotal_threshold) { return array('success' => false, 'info' => sfContext::getInstance()->getI18N()->__('Unfulfilled policy for (%per_resources_value%) percentage of resources reserved to failover. The node info says that has %free_mem% free memory to garantee %total_mem%.', array('%per_resources_value%' => $per_resources_value, '%free_mem%' => $sum_all_Nodes_memfree_after, '%total_mem%.' => $all_Node_memtotal_threshold))); } if ($server->getVcpu() > $max_cpu_Nodes) { return array('success' => false, 'info' => sfContext::getInstance()->getI18N()->__('Number max. of cpus (%max_cpu_Nodes%) exceeded.', array('%max_cpu_Nodes%' => $max_cpu_Nodes))); } } } } return array('success' => true); }
public function ETFW_main(EtvaServer $etva_server, $method, $params, $mode) { // prepare soap info.... $initial_params = array('dispatcher' => 'ETFW'); $call_params = array_merge($initial_params, $params); // send soap request $response = $etva_server->soapSend($method, $call_params); // if soap response is ok if ($response['success']) { $response_decoded = (array) $response['response']; if ($mode) { $method = $mode; } switch ($method) { case 'etfw_save': $return = $response; break; default: $return = array('success' => false, 'error' => 'No action \'' . $method . '\' defined yet', 'info' => 'No action \'' . $method . '\' implemented yet'); } return $return; } else { $error_details = $response['info']; $error_details = nl2br($error_details); $error = $response['error']; $result = array('success' => false, 'error' => $error, 'info' => $error_details, 'faultcode' => $response['faultcode']); return $result; } }
public function ETMS_mailbox(EtvaServer $etva_server, $method, $params, $mode) { $response = $etva_server->soapSend($method, $params); // if soap response is ok if ($response['success']) { $response_decoded = (array) $response['response']; if ($mode) { $method = $mode; } switch ($method) { case 'get_users': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = (array) $data; } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; case 'select_alias': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; case 'edit_user': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; case 'create_user': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; case 'delete_user': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; case 'select_domain': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[$dataType] = $data; } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; case 'users_occupied_space': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[$dataType] = $data; } $return = array('success' => true, 'value' => $elements, 'agent' => $response['agent']); break; default: $return = array('success' => true, 'value' => $response_decoded, 'agent' => $response['agent']); break; } return $return; } else { $error_details = $response['info']; $error_details = nl2br($error_details); $error = $response['error']; $result = array('success' => false, 'agent' => $response['agent'], 'error' => $error, 'info' => $error_details, 'faultcode' => $response['faultcode']); return $result; } }
public function canAssignServer(EtvaServer $server) { $server_mem = Etva::MB_to_Byteconvert($server->getMem()); if ($this->getCputotal() >= $server->getVcpu() && $this->getMaxMem() > $server_mem && !$server->getDevices_VA() && !$server->getHasSnapshots()) { if ($server->getVmState() !== EtvaServer::RUNNING || $this->getMemfree() > $server_mem) { error_log("canAssignServer OK node=" . $this->getName() . " server=" . $server->getName() . " vmstate=" . $server->getVmState() . " maxmem=" . $this->getMaxMem() . " memfree=" . $this->getMemfree() . " server_mem=" . $server_mem); return true; } } error_log("canAssignServer NOK node=" . $this->getName() . " server=" . $server->getName() . " vmstate=" . $server->getVmState() . " maxmem=" . $this->getMaxMem() . " memfree=" . $this->getMemfree() . " server_mem=" . $server_mem); return false; }
public function ETFS_main(EtvaServer $etva_server, $r_method, $params, $mode, $service_id) { $method = str_replace(array("_cbx", "_tree", "_grid", "_filterBy", "_only"), "", $r_method); // prepare soap info.... $initial_params = array(); $call_params = array_merge($initial_params, $params); // send soap request $response = $etva_server->soapSend($method, $call_params); // if soap response is ok if ($response['success']) { $response_decoded = (array) $response['response']; if ($mode) { $method = $mode; } switch ($r_method) { case 'list_shares_filterBy': $share_name = $params['name']; $error_i18n = $this->getContext()->getI18N()->__('Share \'%name%\' not found.', array('%name%' => $share_name)); $info_i18n = $this->getContext()->getI18N()->__('Share \'%name%\' not found.', array('%name%' => $share_name)); $return = array('success' => false, 'error' => $error_i18n, 'info' => $info_i18n); $shares_data = (array) $response_decoded; foreach ($shares_data as $sObj) { $share = (array) $sObj; if ($share['name'] == $share_name) { $return = array('success' => true, 'data' => $share); break; } } break; case 'list_shares_only': $shares_data = (array) $response_decoded; $return_data = array(); foreach ($shares_data as $sObj) { $share = (array) $sObj; if ($share['name'] !== 'global') { array_push($return_data, $share); } } $return = array('success' => true, 'data' => $return_data); break; case 'list_groups': case 'list_smb_users': case 'list_users': case 'list_shares': case 'get_samba_status': case 'get_samba_status_raw': case 'get_global_configuration': case 'status_service': $return_data = (array) $response_decoded; $return = array('success' => true, 'data' => $return_data); break; /*case 'get_samba_status_raw': $return_data = (array)$response_decoded; error_log(print_r($return_data,true)); $return_data['status'] = str_replace("\\n","<br/>",$return_data['status']); error_log(print_r($return_data,true)); $return = array( 'success'=>true, 'data'=>$return_data ); break;*/ /*case 'get_samba_status_raw': $return_data = (array)$response_decoded; error_log(print_r($return_data,true)); $return_data['status'] = str_replace("\\n","<br/>",$return_data['status']); error_log(print_r($return_data,true)); $return = array( 'success'=>true, 'data'=>$return_data ); break;*/ case 'create_share': case 'update_share': case 'delete_share': case 'create_user': case 'update_user': case 'delete_user': case 'start_service': case 'restart_service': case 'stop_service': case 'set_global_configuration': case 'join_to_domain': $okmsg_i18n = $this->getContext()->getI18N()->__($response_decoded['_okmsg_'], array()); $return = array('success' => true, 'data' => $data, 'response' => $okmsg_i18n); break; default: $error_i18n = $this->getContext()->getI18N()->__('No action \'%method%\' defined yet.', array('%method%' => $method)); $info_i18n = $this->getContext()->getI18N()->__('No action \'%method%\' implemented yet', array('%method%' => $method)); $return = array('success' => false, 'error' => $error_i18n, 'info' => $info_i18n); } return $return; } else { $error_details = $response['info']; $error_details = nl2br($error_details); $error_details_i18n = $this->getContext()->getI18N()->__($error_details); $error = $response['error']; $result = array('success' => false, 'error' => $error, 'info' => $error_details_i18n, 'faultcode' => $response['faultcode']); return $result; } }
public function executeJsonImport(sfWebRequest $request) { $nid = $request->getParameter('nid'); $import_data = json_decode($request->getParameter('import'), true); $server = $import_data; $vnc_keymap = EtvaSettingPeer::retrieveByPk('vnc_keymap'); $server['vnc_keymap'] = $vnc_keymap->getValue(); $server['uuid'] = EtvaServerPeer::generateUUID(); $server['name'] = $import_data['name']; $server['vm_type'] = $import_data['vm_type']; $server['ip'] = '000.000.000.000'; $server['boot'] = 'filesystem'; $import_data['uuid'] = $server['uuid']; $import_data['vnc_keymap'] = $server['vnc_keymap']; // import validation check $result = $this->jsonImportCheck($request); if (!$result['success']) { // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($result); } // if is browser request return text renderer $error = $this->setJsonError($result); return $this->renderText($error); } if (!($etva_node = EtvaNodePeer::retrieveByPK($nid))) { $msg_i18n = $this->getContext()->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $nid)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); //notify event log $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_); $message = Etva::getLogMessage(array('info' => $node_log), OvfEnvelope_VA::_ERR_IMPORT_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } $disks = $import_data['disks']; $collVgs = array(); foreach ($disks as $id => $info) { $vg = $info['vg']; $lv = $info['lv']; if ($etva_lv = $etva_node->retrieveLogicalvolumeByLv($lv)) { $msg_type = $is_DiskFile ? EtvaLogicalvolumePeer::_ERR_DISK_EXIST_ : EtvaLogicalvolumePeer::_ERR_LV_EXIST_; $msg = Etva::getLogMessage(array('name' => $lv), $msg_type); $msg_i18n = $this->getContext()->getI18N()->__($msg_type, array('%name%' => $lv)); $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n); //notify system log $message = Etva::getLogMessage(array('name' => $lv, 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_); $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } if (!($etva_vg = $etva_node->retrieveVolumegroupByVg($vg))) { $msg = Etva::getLogMessage(array('name' => $vg), EtvaVolumegroupPeer::_ERR_NOTFOUND_); $msg_i18n = $this->getContext()->getI18N()->__(EtvaVolumegroupPeer::_ERR_NOTFOUND_, array('%name%' => $vg)); $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n); //notify system log $message = Etva::getLogMessage(array('name' => $lv, 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_); $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } // fix lv path $is_DiskFile = $vg == sfConfig::get('app_volgroup_disk_flag') ? 1 : 0; $import_data['disks'][$id]['lv'] = $is_DiskFile ? $etva_node->getStoragedir() . '/' . $lv : $lv; $collVgs[$vg] = $etva_vg; } $networks = $import_data['networks']; $networks_va = $import_data['networks']; $collNetworks = array(); $i = 0; // check if networks are available foreach ($networks as $network) { if ($etva_vlan = EtvaVlanPeer::retrieveByPk($network['vlan_id'])) { $import_data['networks'][$i]['network'] = $etva_vlan->getName(); $import_data['networks'][$i]['macaddr'] = $network['mac']; } $etva_mac = EtvaMacPeer::retrieveByMac($network['mac']); /* * TODO improve this to add Mac Address to the pool */ if (!$etva_mac || !$etva_vlan) { $msg = Etva::getLogMessage(array(), EtvaNetworkPeer::_ERR_); $msg_i18n = $this->getContext()->getI18N()->__(EtvaNetworkPeer::_ERR_, array()); if (!$etva_mac) { $msg = Etva::getLogMessage(array('%mac%' => $network['mac']), EtvaMacPeer::_ERR_INVALID_MAC_); $msg_i18n = $this->getContext()->getI18N()->__(EtvaMacPeer::_ERR_INVALID_MAC_, array('%mac%' => $network['mac'])); } $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n); //notify event log $message = Etva::getLogMessage(array('name' => $server['name'], 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_); $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } if ($etva_mac->getInUse()) { $msg = Etva::getLogMessage(array('%name%' => $etva_mac->getMac()), EtvaMacPeer::_ERR_ASSIGNED_); $msg_i18n = $this->getContext()->getI18N()->__(EtvaMacPeer::_ERR_ASSIGNED_, array('%name%' => $etva_mac->getMac())); $error = array('success' => false, 'agent' => $etva_node->getName(), 'info' => $msg_i18n, 'error' => $msg_i18n); //notify event log $message = Etva::getLogMessage(array('name' => $server['name'], 'info' => $msg), OvfEnvelope_VA::_ERR_IMPORT_); $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); // if is a CLI soap request return json encoded data if (sfConfig::get('sf_environment') == 'soap') { return json_encode($error); } // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } $etva_network = new EtvaNetwork(); $etva_network->fromArray($network, BasePeer::TYPE_FIELDNAME); $collNetworks[] = $etva_network; $i++; } $env = new OvfEnvelope_VA(); $env->fromArray($import_data); /* get server copy VA server representation */ $params = $env->_VA(); $method = 'vm_ovf_import_may_fork'; $response = $etva_node->soapSend($method, $params); if (!$response['success']) { $error_decoded = $response['error']; $result = $response; $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_CREATE_, array('%name%' => $server['name'], '%info%' => $error_decoded)); $result['error'] = $msg_i18n; //notify event log $message = Etva::getLogMessage(array('name' => $server['name'], 'info' => $response['info']), EtvaServerPeer::_ERR_CREATE_); $this->dispatcher->notify(new sfEvent($response['agent'], 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); if (sfConfig::get('sf_environment') == 'soap') { return json_encode($result); } $return = $this->setJsonError($result); return $this->renderText($return); } $response_decoded = (array) $response['response']; $returned_object = (array) $response_decoded['_obj_']; $returned_lvs = (array) $returned_object['LVS']; $collLvs = array(); foreach ($returned_lvs as $disk) { $disk_array = (array) $disk; $vg_info = (array) $disk_array[EtvaLogicalvolume::VOLUMEGROUP_MAP]; $vg = $vg_info[EtvaVolumegroup::VG_MAP]; $fake_lv_response = array('success' => true, 'response' => array('_obj_' => $disk_array)); // create logical volume $etva_lv = new EtvaLogicalvolume(); $etva_lv->setEtvaVolumegroup($collVgs[$vg]); $lv_va = new EtvaLogicalvolume_VA($etva_lv); $lv_response = $lv_va->processResponse($etva_node, $fake_lv_response, 'lvcreate'); if (!$lv_response['success']) { $return = $this->setJsonError($lv_response); return $this->renderText($return); } $collLvs[] = $etva_lv; } $etva_server = new EtvaServer(); $etva_server->fromArray($server, BasePeer::TYPE_FIELDNAME); $user_groups = $this->getUser()->getGroups(); $server_sfgroup = array_shift($user_groups); //if user has group then put one of them otherwise put DEFAULT GROUP ID if ($server_sfgroup) { $etva_server->setsfGuardGroup($server_sfgroup); } else { $etva_server->setsfGuardGroup(sfGuardGroupPeer::getDefaultGroup()); } foreach ($collNetworks as $coll) { $etva_server->addEtvaNetwork($coll); } $i = 0; foreach ($collLvs as $coll) { $server_disk = new EtvaServerLogical(); $server_disk->setEtvaLogicalvolume($coll); $server_disk->setBootDisk($i); $etva_server->addEtvaServerLogical($server_disk); $i++; } //update some data from agent response $vm = (array) $returned_object['VM']; $etva_server->initData($vm); //$etva_server->setEtvaNode($etva_node); $etva_server->setEtvaCluster($etva_node->getEtvaCluster()); try { $etva_server->save(); } catch (Exception $e) { $msg = $e->getMessage(); $result = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg, 'info' => $msg); $return = $this->setJsonError($result); return $this->renderText($return); } // assign To etva_node $etva_server->assignTo($etva_node); $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_OK_CREATE_, array('%name%' => $server['name'])); $message = Etva::getLogMessage(array('name' => $server['name']), EtvaServerPeer::_OK_CREATE_); $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message))); $result = array('success' => true, 'agent' => $response['agent'], 'insert_id' => $etva_server->getId(), 'response' => $msg_i18n); $return = json_encode($result); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); // if is browser request return text renderer return $this->renderText($return); }
public function Primavera_main(EtvaServer $etva_server, $r_method, $params, $mode, $service_id) { $method = str_replace(array("_cbx", "_tree", "_grid"), "", $r_method); // prepare soap info.... $initial_params = array(); $call_params = array_merge($initial_params, $params); // send soap request $response = $etva_server->soapSend($method, $call_params); // if soap response is ok if ($response['success']) { $response_decoded = (array) $response['response']; if ($mode) { $method = $mode; } switch ($r_method) { case 'primavera_info': $data = array('id' => $service_id); $disk_data = (array) $response_decoded['_disk_']; $totalfreebytes = $disk_data['TotalNumberOfFreeBytes']; $totalbytes = $disk_data['TotalNumberOfBytes']; $totalfree_mb = round($totalfreebytes / 1024 / 1024, 2); $total_mb = round($totalbytes / 1024 / 1024, 2); $totalfree_per = round(100 * $totalfreebytes / $totalbytes, 2); $data['totalfreeper'] = $totalfree_per; $data['totalfreemb'] = $totalfree_mb; $data['totalmb'] = $total_mb; // format date /*$backup_data = (array)$response_decoded['_backups_']; $data['lastbackupdate'] = strftime('%Y-%m-%d %H:%M:%S', (int)$backup_data['changed']);*/ // translation of yes or no $b_yes = $this->getContext()->getI18N()->__('Yes'); $b_no = $this->getContext()->getI18N()->__('No'); $services_data = (array) $response_decoded['_services_']; foreach ($services_data as $s => $v) { $sk = "{$s}" . "runservice"; $status = (array) $v; $data["{$sk}"] = $status['state'] == 'SERVICE_RUNNING' ? $b_yes : $b_no; } $primavera_data = (array) $response_decoded['_primavera_']; $data['segurancaactiva'] = $primavera_data['Seguranca_Activa'] == 0 ? $b_no : $b_yes; $data['license'] = $primavera_data['License'] == 0 ? $b_no : $b_yes; $data['segurancaproempactiva'] = $primavera_data['Seguranca_Pro_Emp_Activa'] == 0 ? $b_no : $b_yes; $data['modoseguranca'] = $primavera_data['Modo_Seguranca'] == 0 ? $b_no : $b_yes; $data['nempresas'] = $primavera_data['N_Empresas']; $data['nutilizadores'] = $primavera_data['N_Utilizadores']; $data['npostos'] = $primavera_data['N_Postos']; $data['language'] = $primavera_data['Language']; $network_data = (array) $response_decoded['_network_']; $data['ipaddr'] = $network_data['ipaddr']; $data['netmask'] = $network_data['netmask']; $data['gateway'] = $network_data['gateway']; $data['dhcp'] = $network_data['dhcp']; $return = array('success' => true, 'data' => $data); break; case 'primavera_backupinfo': $data = array('id' => $service_id); $empresas_data = (array) $response_decoded; $empresas = array(); foreach ($empresas_data as $eObj) { $e = (array) $eObj; $db = (array) $e['DATABASE']; $bkps = (array) $e['BACKUPS']; //array_push($empresas,array( $db['name'], $e['name'] )); array_push($empresas, array('name' => $e['name'], 'db' => $db['name'], 'bkps' => $bkps)); } $data['empresas'] = $empresas; $return = array('success' => true, 'data' => $data); break; case 'windows_listusers': $users_data = (array) $response_decoded; $husers = array(); foreach ($users_data as $eObj) { $e = (array) $eObj; $uname = $e['username']; if (!$this->ignoreWindowsUser($uname)) { if (!$husers["{$uname}"]) { $husers["{$uname}"] = array('username' => "{$uname}", 'groups' => array()); } array_push($husers["{$uname}"]['groups'], $e['group']); } } $wusers = array_values($husers); $return = array('success' => true, 'data' => $wusers); break; case 'primavera_listbackupplans': $bp_data = (array) $response_decoded; $backupplans = array(); foreach ($bp_data as $bpObj) { $b = (array) $bpObj; $str_companies = ''; $str_schedule = 'Daily'; if (isset($b['schedule'])) { $schedule = (array) $b['schedule']; if (isset($schedule[0])) { $sc_0 = (array) $schedule[0]; if (preg_match("/semanal/i", $sc_0['periodo'])) { $str_schedule = 'Weekly'; } else { if (preg_match("/mensal/i", $sc_0['periodo'])) { $str_schedule = 'Monthly'; } } } } if (isset($b['companies'])) { $companies = (array) $b['companies']; foreach ($companies as $cObj) { $company = (array) $cObj; if ($str_companies != '') { $str_companies .= ';'; } $str_companies .= $company['key'] . ',' . $company['name']; } } $bplan = array('id' => $b['id'], 'name' => $b['name'], 'date' => $b['date'], 'lastExecution' => $b['lastExecution'], 'nextExecution' => $b['nextExecution'], 'schedule' => $str_schedule, 'companies' => $str_companies); $bplan['verify'] = $b['verify'] ? 'Yes' : 'No'; $bplan['overwrite'] = $b['overwrite'] ? 'Yes' : 'No'; $bplan['incremental'] = $b['incremental'] ? 'Yes' : 'No'; array_push($backupplans, $bplan); } $return = array('success' => true, 'data' => $backupplans); break; /*case 'primavera_listdatabases': $data = array( 'id'=>$service_id ); $db_data = (array)$response_decoded; $databases = array(); foreach($db_data as $dbObj){ $db = (array)$dbObj; if( preg_match("/^PRI/",$db['name']) ){ $db_name = $db['name']; $e_name = str_replace($db_name,'PRI',''); $dbase = array('db'=>$db_name,'name'=>$e_name); array_push($databases,$dbase); } } $data['databases'] = $databases; $return = array( 'success'=>true, 'data'=>$data ); break;*/ /*case 'primavera_listdatabases': $data = array( 'id'=>$service_id ); $db_data = (array)$response_decoded; $databases = array(); foreach($db_data as $dbObj){ $db = (array)$dbObj; if( preg_match("/^PRI/",$db['name']) ){ $db_name = $db['name']; $e_name = str_replace($db_name,'PRI',''); $dbase = array('db'=>$db_name,'name'=>$e_name); array_push($databases,$dbase); } } $data['databases'] = $databases; $return = array( 'success'=>true, 'data'=>$data ); break;*/ case 'windows_createuser': case 'primavera_backup': case 'primavera_fullbackup': case 'primavera_insertbackupplan': case 'primavera_removebackupplan': case 'primavera_restore': case 'primavera_fullrestore': case 'primavera_start': case 'primavera_stop': case 'primavera_insertuser': case 'primavera_updateuser': case 'primavera_deleteuser': case 'primavera_updateuser_aplicacoes': case 'primavera_updateuser_permissoes': case 'change_ip': $data = array(); $okmsg_i18n = $this->getContext()->getI18N()->__($response_decoded['_okmsg_'], array()); $return = array('success' => true, 'data' => $data, 'response' => $okmsg_i18n); break; case 'primavera_listempresas_cbx': $empresas_data = (array) $response_decoded; $return_empresas = array(array('name' => $this->getContext()->getI18N()->__('All'), 'cod' => '***')); foreach ($empresas_data as $eObj) { $empresa = (array) $eObj; array_push($return_empresas, array('name' => $this->getContext()->getI18N()->__($empresa['name']), 'cod' => $empresa['name'])); } $return = array('success' => true, 'data' => $return_empresas); break; case 'primavera_listperfis': case 'primavera_listusers': case 'primavera_listempresas': case 'primavera_list_user_aplicacoes_join': case 'primavera_list_user_permissoes_join': case 'primavera_listaplicacoes': case 'primavera_viewuser': $return_data = (array) $response_decoded; $return = array('success' => true, 'data' => $return_data); break; default: $error_i18n = $this->getContext()->getI18N()->__('No action \'%method%\' defined yet.', array('%method%' => $method)); $info_i18n = $this->getContext()->getI18N()->__('No action \'%method%\' implemented yet', array('%method%' => $method)); $return = array('success' => false, 'error' => $error_i18n, 'info' => $info_i18n); } return $return; } else { $error_details = $response['info']; $error_details = nl2br($error_details); $error_details_i18n = $this->getContext()->getI18N()->__($error_details); $error = $response['error']; $result = array('success' => false, 'error' => $error, 'info' => $error_details_i18n, 'faultcode' => $response['faultcode']); return $result; } }
/** * checks server state * send soap request and update DB state * returns response from agent */ private function checkState(EtvaServer $etva_server, $dispatcher) { $method = 'getstate'; $response = $etva_server->soapSend($method, $dispatcher); $success = $response['success']; if (!$success) { $etva_server->setState(0); $etva_server->save(); //notify system log $message = Etva::getLogMessage(array('name' => $etva_server->getName(), 'info' => $response['info']), EtvaServerPeer::_ERR_SOAPSTATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); } else { $etva_server->setState(1); $etva_server->save(); //notify system log $message = Etva::getLogMessage(array('name' => $etva_server->getName()), EtvaServerPeer::_OK_SOAPSTATE_); $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message))); } return $response; }
public function ETASP_etasp_api(EtvaServer $etva_server, $method, $params, $mode) { error_log("ETASP_etasp_api called"); if ($method == 'allinfo') { $elements = new stdClass(); $methods = array('getResourceUsage', 'getDatabaseInfo', 'getInstanceMetadata'); error_log('allinfo'); // make the calls foreach ($methods as $method) { error_log($method); $response = $etva_server->soapSend($method, $params); if ($response['success']) { $obj = $response['response']; $elements = (object) array_merge((array) $obj->msg, (array) $elements); } else { #todo implement error handling error_log("error"); } } error_log(print_r($elements, true)); $method = 'allinfo'; $return = array('success' => true, 'data' => $elements, 'total' => 1); return $return; } else { // send soap request $response = $etva_server->soapSend($method, $params); } // if soap response is ok if ($response['success'] && $method != 'allinfo') { $response_decoded = (array) $response['response']; if ($mode) { $method = $mode; } switch ($method) { case 'pack': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = (array) $data; } $obj = new stdClass(); $obj->success = 'ok'; $obj->msg->pack = $elements[0]; $return = array('success' => true, 'data' => $obj); break; case 'getInstanceMetadata': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements); break; case 'getDatabaseInfo': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements); break; case 'getResourceUsage': $elements = array(); foreach ($response_decoded as $dataType => $data) { $elements[] = array('alias' => $data); } $return = array('success' => true, 'value' => $elements); break; } return $return; } else { $error_details = $response['info']; $error_details = nl2br($error_details); $error = $response['error']; $result = array('success' => false, 'error' => $error, 'info' => $error_details, 'faultcode' => $response['faultcode']); return $result; } }