public function executeSoapInit(sfWebRequest $request) { if (sfConfig::get('sf_environment') == 'soap') { $agent_tmpl = $request->getParameter('name'); $ip = $request->getParameter('ip'); $port = $request->getParameter('port'); $services = $request->getParameter('services'); $macaddr = $request->getParameter('macaddr'); $c = new Criteria(); $c->add(EtvaNetworkPeer::MAC, $macaddr); $etva_network = EtvaNetworkPeer::doSelectOne($c); if (!$etva_network) { $error_msg = sprintf('Object etva_network does not exist (%s).', $macaddr); $error = array('success' => false, 'error' => $error_msg); return $error; } // print_r($agent_tmpl); $etva_server = $etva_network->getEtvaServer(); $etva_server->setIp($ip); $etva_server->setAgentTmpl($agent_tmpl); $etva_server->setAgentPort($port); $etva_server->setState(1); $etva_server->save(); if ($services) { foreach ($services as $service) { $c = new Criteria(); $c->add(EtvaServicePeer::NAME_TMPL, $service->name); $c->add(EtvaServicePeer::SERVER_ID, $etva_server->getId()); $etva_service = EtvaServicePeer::doSelectOne($c); if (!$etva_service) { $etva_service = new EtvaService(); $etva_service->setNameTmpl($service->name); $etva_service->setEtvaServer($etva_server); } if (isset($service->description)) { $etva_service->setDescription($service->description); } if (isset($service->params)) { $params = $service->params; $encoded_json = json_encode($params); $etva_service->setParams($encoded_json); } $etva_service->save(); } } /* * * check if has restore to perform.... */ $apli = new Appliance(); $backup_url = $apli->get_backupconf_url(Appliance::MA_ARCHIVE_FILE, $etva_server->getUuid(), $etva_server->getAgentTmpl()); $result = array('success' => true); if ($backup_url) { $result['reset'] = 1; $result['backup_url'] = $backup_url; } return $result; } }
/** * Removes vlan * * Issues soap request to all nodes * * @return json array string * */ public function executeJsonRemove(sfWebRequest $request) { // vlan name and cluster id... $netname = $request->getParameter('name'); $clusterid = $request->getParameter('cluster_id'); if (!$clusterid) { $defaultCluster = EtvaClusterPeer::retrieveDefaultCluster(); $clusterid = $defaultCluster->getId(); } $nodes_criteria = new Criteria(); $nodes_criteria->add(EtvaNodePeer::CLUSTER_ID, $clusterid); $etva_nodes = EtvaNodePeer::doSelect($nodes_criteria); // $etva_nodes = EtvaNodePeer::doSelect(new Criteria()); $oks = array(); $errors = array(); $method = 'destroy_network'; $params = array('name' => $netname); error_log("VLANREMOVE[INFO] Getting vlan " . $netname . " of cluster " . $clusterid); if (!($etva_vlan = EtvaVlanPeer::retrieveByClusterAndName($netname, $clusterid))) { $msg = "Network {$netname} not found!"; $msg_i18n = $this->getContext()->getI18N()->__('Network %1% not found!', array('%1%' => $netname)); $error = array('success' => false, 'ok' => $oks, 'error' => array($msg_i18n)); //notify system log $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $netname, 'info' => $msg), EtvaVlanPeer::_ERR_REMOVE_), 'priority' => EtvaEventLogger::CRIT))); // 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); } // check if is in use.... $c = new Criteria(); $c->add(EtvaNetworkPeer::VLAN_ID, $etva_vlan->getId()); if ($etva_network = EtvaNetworkPeer::doSelectOne($c)) { $msg = "Network {$netname} in use!"; $msg_i18n = $this->getContext()->getI18N()->__('Network %1% in use!', array('%1%' => $netname)); $msg_array = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'ok' => $oks, 'error' => array($msg_array)); //notify system log $this->dispatcher->notify(new sfEvent($error['agent'], 'event.log', array('message' => Etva::getLogMessage(array('name' => $netname, 'info' => $msg), EtvaVlanPeer::_ERR_REMOVE_), '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); } // error_log(print_r($etva_vlan,true)); $etva_vlan->delete(); //notify system log $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => Etva::getLogMessage(array('name' => $netname), EtvaVlanPeer::_OK_REMOVE_)))); // send soap request to all nodes (agents) foreach ($etva_nodes as $etva_node) { // send soap request $response = $etva_node->soapSend($method, $params); if ($response['success']) { $msg_i18n = $this->getContext()->getI18N()->__(EtvaVlanPeer::_OK_REMOVE_, array('%name%' => $netname)); $response['info'] = $msg_i18n; $oks[] = $response; //notify system log $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => Etva::getLogMessage(array('name' => $netname), EtvaVlanPeer::_OK_REMOVE_)))); } else { $info = $response['info']; $info_i18n = $this->getContext()->getI18N()->__($info); $response['info'] = $info_i18n; $errors[] = $response; //notify system log $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => Etva::getLogMessage(array('name' => $netname, 'info' => $info), EtvaVlanPeer::_ERR_REMOVE_), 'priority' => EtvaEventLogger::ERR))); } } if (!empty($errors)) { $result = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'ok' => $oks, 'error' => $errors); if (sfConfig::get('sf_environment') == 'soap') { return json_encode($result); } $return = $this->setJsonError($result); return $this->renderText($return); } $result = array('success' => true, 'agent' => sfConfig::get('config_acronym'), 'response' => $oks); $return = json_encode($result); // 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); }