public function configure() { // get last datacenter id $c = new Criteria(); $c->addDescendingOrderByColumn(EtvaClusterPeer::ID); $cluster = EtvaClusterPeer::doSelectOne($c); error_log("VLANFORM[INFO] Last cluster id: " . $cluster->getId()); $this->setValidators(array('cluster_id' => new sfValidatorInteger(array('min' => 1, 'max' => $cluster->getId(), 'required' => true)), 'name' => new sfValidatorString(array('min_length' => 3, 'max_length' => 10)), 'vlanid' => new sfValidatorInteger(array('min' => 1, 'max' => 4094, 'required' => false)), 'tagged' => new sfValidatorChoice(array('choices' => array(0, 1))))); }
private function check_pvs(EtvaNode $etva_node) { $node_response = $etva_node->soapSend('getpvs_arr', array('force' => 1)); if (!$node_response['success']) { $errors = $node_response['error']; Etva::getLogMessage(array('info' => ''), EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_); //$etva_node->setErrorMessage(EtvaPhysicalvolume_VA::LVINIT); $message = $this->getContext()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_SOAPUPDATE_, array('%info%' => $node_response['info'])); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $response = array('success' => false, 'error' => $message, 'agent' => $etva_node->getName()); $return = $this->setJsonError($response); return $this->renderText($return); } //verify if cluster has any logical volume that belongs to another cluster... $cluster_id = $etva_node->getClusterId(); $my_pvs = $node_response['response']; $my_pvs = (array) $my_pvs; foreach ($my_pvs as $my_pv) { $pv_info = (array) $my_pv; if ($pv_info['type'] == EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) { continue; } $c_uuid = new criteria(); $c_uuid->add(EtvaPhysicalvolumePeer::UUID, $pv_info['uuid']); $c_uuid->addAnd(EtvaPhysicalvolumePeer::CLUSTER_ID, $cluster_id, Criteria::NOT_EQUAL); $e_pv = EtvaPhysicalvolumePeer::doSelectOne($c_uuid); if ($e_pv) { $c_c = new Criteria(); $c_c->add(EtvaClusterPeer::ID, $e_pv->getClusterId()); $etva_cluster = EtvaClusterPeer::doSelectOne($c_c); $msg_i18n = $this->getContext()->getI18N()->__(EtvaPhysicalvolumePeer::_ERR_INIT_OTHER_CLUSTER_, array('%name%' => $etva_cluster->getName())); $response = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); $return = $this->setJsonError($response); return $this->renderText($return); } } }
public function executeJsonName(sfWebRequest $request) { $id = $request->getParameter('id'); $method = $request->getParameter('method'); $name = $request->getParameter('name'); if ($etva_cluster = EtvaClusterPeer::retrieveByPK($id)) { $count = 1; } else { $msg_i18n = $this->getContext()->getI18N()->__(EtvaClusterPeer::_ERR_CLUSTER_, array('%id%' => $id)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } switch ($method) { case 'update': try { //check if name is available $cname = new Criteria(); $cname->add(EtvaClusterPeer::NAME, $name); if (EtvaClusterPeer::doSelectOne($cname)) { $msg = 'Cluster with the same name already exists'; $msg_i18n = $this->getContext()->getI18N()->__($msg); $result = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'info' => $msg_i18n); $return = json_encode($result); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); } $c = new Criteria(); $c->add(EtvaClusterPeer::ID, $id, Criteria::EQUAL); $cluster_obj = EtvaClusterPeer::doSelectOne($c); $cluster_obj->setName($name); $cluster_obj->save(); } catch (Exception $e) { $result = array('success' => false, 'error' => 'Could not perform operation', 'agent' => sfConfig::get('config_acronym'), 'info' => 'Could not perform operation'); $return = json_encode($result); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); } $msg = 'Cluster name changed successfully'; $msg_i18n = $this->getContext()->getI18N()->__($msg); $result = array('success' => true, 'total' => 1, 'data' => array('id' => $cluster_obj->getId(), 'name' => $cluster_obj->getName()), 'agent' => sfConfig::get('config_acronym'), 'info' => $msg_i18n); $return = json_encode($result); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($return); // // if the request is made throught soap request... // if(sfConfig::get('sf_environment') == 'soap') return $return; // // // if is browser request return text renderer // $this->getResponse()->setHttpHeader('Content-type', 'application/json'); // return $this->renderText($return); break; default: $return = array('success' => true, 'total' => $count, 'data' => array('id' => $etva_cluster->getId(), 'name' => $etva_cluster->getName())); $result = json_encode($return); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); } }