protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add networks from config file to the givel cluster (optional)
     $flag = 0;
     //write or not to stdout
     if ($options['cluster_id']) {
         $cluster_id = $options['cluster_id'];
         $flag = 1;
     } else {
         $default_cluster = EtvaClusterPeer::retrieveDefaultCluster();
         $cluster_id = $default_cluster->getId();
     }
     error_log("LOADCONFTASK[INFO] Loading config file");
     error_log($cluster_id);
     $model = Etva::getEtvaModelFile();
     $networks = isset($model['networks']) ? $model['networks'] : $model[ucfirst('networks')];
     if ($this->initialize_networks($networks, $cluster_id)) {
         if ($flag == 0) {
             echo "Done!\n";
         }
         return 1;
     } else {
         if ($flag == 0) {
             echo "Failed!\n";
         }
         return 0;
     }
 }
Example #2
0
 public function executeJsonGridNoPager($request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     $sid = $this->getRequestParameter('sid');
     if ($sid) {
         $server = EtvaServerPeer::retrieveByPK($sid);
         $cid = $server->getClusterId();
     } else {
         // get cluster id
         $cid = $this->getRequestParameter('cid');
         if (!$cid) {
             $etva_cluster = EtvaClusterPeer::retrieveDefaultCluster();
             $cid = $etva_cluster->getId();
         }
     }
     //Get networks from cluster
     $c_vlan = new Criteria();
     $c_vlan->add(EtvaVlanPeer::CLUSTER_ID, $cid);
     $etva_vlans = EtvaVlanPeer::doSelect($c_vlan);
     //get networks with server
     $c = new Criteria();
     $vlan_flag = false;
     $server_flag = false;
     $query = $this->getRequestParameter('query') ? json_decode($this->getRequestParameter('query'), true) : array();
     foreach ($query as $key => $val) {
         $column = EtvaNetworkPeer::translateFieldName(sfInflector::camelize($key), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
         if ($key == 'vlan_id') {
             $vlan_flag = true;
         }
         if ($key == 'server_id') {
             $server_flag = true;
         }
         $c->add($column, $val);
     }
     //error_log($c->toString());
     //get vlans from cluster
     if (!$vlan_flag && !$server_flag) {
         // && !$server_flag && $cid){
         //error_log('!(!$vlan_flag && !$server_flag)');
         foreach ($etva_vlans as $etva_vlan) {
             if ($this->getRequestParameter('query')) {
                 $c->addOr(EtvaNetworkPeer::VLAN_ID, $etva_vlan->getId());
             } else {
                 $c->addAnd(EtvaNetworkPeer::VLAN_ID, $etva_vlan->getId());
             }
         }
     }
     // add sort criteria to sort elements
     $this->addSortCriteria($c);
     // add server criteria
     $this->addServerCriteria($c);
     //error_log($c->toString());
     $etva_network_list = EtvaNetworkPeer::doSelectJoinEtvaServer($c);
     $elements = array();
     $i = 0;
     foreach ($etva_network_list as $item) {
         $etva_server = $item->getEtvaServer();
         $etva_vlan = $item->getEtvaVlan();
         if ($etva_server && $etva_vlan) {
             $etva_server_name = $etva_server->getName();
             $etva_server_type = $etva_server->getVmType();
             $etva_vm_state = $etva_server->getVmState();
             $etva_vlan_name = $etva_vlan->getName();
             $elements[$i] = $item->toArray();
             $elements[$i]['ServerName'] = $etva_server_name;
             $elements[$i]['VmType'] = $etva_server_type;
             $elements[$i]['Vlan'] = $etva_vlan_name;
             $elements[$i]['Vm_state'] = $etva_vm_state;
             $etva_node = $etva_server->getEtvaNode();
             if ($etva_node) {
                 $etva_node_name = $etva_node->getName();
                 $elements[$i]['NodeName'] = $etva_node_name;
                 $elements[$i]['NodeId'] = $etva_node->getId();
             }
             $i++;
         }
     }
     $final = array('total' => count($etva_network_list), 'data' => $elements);
     $result = json_encode($final);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * returns json array encoded list of vlans
  * 
  */
 public function executeJsonList(sfWebRequest $request)
 {
     $isAjax = $request->isXmlHttpRequest();
     if (!$isAjax) {
         return $this->redirect('@homepage');
     }
     $p_cluster_id = $this->getRequestParameter('id');
     $p_level = $this->getRequestParameter('level');
     if ($p_level) {
         if (!$p_cluster_id) {
             $error_msg = 'No cluster id defined.';
             $error = array('success' => false, 'error' => $error_msg, 'info' => $error_msg);
             return $error;
         }
         if ($p_level == 'node') {
             $dc_c = new Criteria();
             //convert node id in cluster id
             $dc_c->add(EtvaNodePeer::ID, $p_cluster_id);
             $node = EtvaNodePeer::doSelectOne($dc_c);
             $p_cluster_id = $node->getClusterId();
         } elseif ($p_level == 'server') {
             $dc_c = new Criteria();
             //convert server id in cluster id
             $dc_c->add(EtvaServerPeer::ID, $p_cluster_id, Criteria::EQUAL);
             $server = EtvaServerPeer::doSelectOne($dc_c);
             $p_cluster_id = $server->getClusterId();
         } elseif ($p_level == 'cluster') {
             //do nothing
         } else {
             error_log('NETWORK:[ERROR] executejsonlist invalid parameters');
         }
     } elseif (!$p_cluster_id) {
         $defaultCluster = EtvaClusterPeer::retrieveDefaultCluster();
         $p_cluster_id = $defaultCluster->getId();
     }
     $c = new Criteria();
     $c->add(EtvaVlanPeer::CLUSTER_ID, $p_cluster_id, Criteria::EQUAL);
     $vlan_nodes = EtvaVlanPeer::doSelect($c);
     $list = array();
     foreach ($vlan_nodes as $vlan) {
         $list[] = $vlan->toArray(BasePeer::TYPE_FIELDNAME);
     }
     $untagged_vlan = EtvaVlanPeer::retrieveUntagged($p_cluser_id);
     $hasUntagged = 0;
     if ($untagged_vlan) {
         $hasUntagged = 1;
     }
     $result = array('total' => count($list), 'data' => $list, 'hasUntagged' => $hasUntagged);
     $result = json_encode($result);
     if (sfConfig::get('sf_environment') == 'soap') {
         $soap_result = array(success => true, 'total' => count($list), 'response' => $list);
         return json_encode($soap_result);
     }
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }