示例#1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeView(sfWebRequest $request)
 {
     $dispatcher_id = $request->getParameter('dispatcher_id');
     // used to get parent id component (extjs)
     //$this->containerId = $request->getParameter('containerId');
     // load modules file of dispatcher
     if ($dispatcher_id) {
         $criteria = new Criteria();
         $criteria->add(EtvaServicePeer::ID, $dispatcher_id);
         //$criteria->add(EtvaServicePeer::NAME_TMPL,$dispatcher);
         $etva_service = EtvaServicePeer::doSelectOne($criteria);
         $dispatcher = $etva_service->getNameTmpl();
         $etva_server = $etva_service->getEtvaServer();
         $tmpl = $etva_server->getAgentTmpl() . '_' . $dispatcher . '_modules';
         $directory = $this->context->getConfiguration()->getTemplateDir('etms', '_' . $tmpl . '.php');
         //echo 'dispatcher_id ---> '.$tmpl;
         if ($directory) {
             return $this->renderPartial($tmpl);
         } else {
             return $this->renderText('Template ' . $tmpl . ' not found');
         }
     } else {
         $this->etva_server = EtvaServerPeer::retrieveByPK($request->getParameter('sid'));
     }
 }
示例#2
0
 public function executeCreatewin(sfWebRequest $request)
 {
     $sid = $request->getParameter('sid');
     if ($sid) {
         $server = EtvaServerPeer::retrieveByPK($sid);
         $this->cid = $server->getClusterId();
     } else {
         $this->cid = $request->getParameter('cid');
     }
 }
示例#3
0
 protected function execute($arguments = array(), $options = array())
 {
     // Context
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     // server id
     $server = $arguments['server'];
     $this->log("[INFO] Shutdown server with '{$server}'");
     $etva_server = EtvaServerPeer::retrieveByPK($server);
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByUuid($server);
     }
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByName($server);
     }
     if (!$etva_server) {
         $msg_i18n = $context->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_, array('name' => $server));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     } else {
         if ($nid = $options['node']) {
             $etva_node = EtvaNodePeer::retrieveByPK($nid);
         } else {
             $etva_node = $etva_server->getEtvaNode();
         }
         if (!$etva_node) {
             //notify event log
             $msg_i18n = Etva::makeNotifyLogMessage(sfConfig::get('config_acronym'), EtvaNodePeer::_ERR_NOTFOUND_ID_, array('id' => $nid), EtvaServerPeer::_ERR_STOP_, array('name' => $server));
             $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
             $this->log("[ERROR] " . $error['error']);
             return $error;
         }
         $destroy = $options['destroy'] ? 1 : 0;
         $force = $options['force'] ? 1 : 0;
         $extra = array('destroy' => $destroy, 'force' => $force);
         $server_va = new EtvaServer_VA($etva_server);
         $response = $server_va->send_stop($etva_node, $extra);
         if ($response['success']) {
             $this->log("[INFO] " . $response['response']);
         } else {
             $this->log("[ERROR] " . $response['error']);
         }
         return $response;
     }
 }
示例#4
0
 public function executeJsonGetId(sfWebRequest $request)
 {
     $level = $request->getParameter('level');
     $id = $request->getParameter('id');
     if ($level == 'node') {
         $node = EtvaNodePeer::retrieveByPK($id);
         $cluster_id = $node->getClusterId();
     } elseif ($level == 'server') {
         $server = EtvaServerPeer::retrieveByPK($id);
         $cluster_id = $server->getClusterId();
     }
     $return = array('cluster_id' => $cluster_id);
     //        error_log(print_r($return, true));
     $result = json_encode($return);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($result);
 }
示例#5
0
 /**
  * 
  * exports virtual machine in ovf format
  * 
  */
 public function executeOvfDownload(sfWebRequest $request)
 {
     //$this->getUser()->shutdown();
     //session_write_close();
     if ($sid = $request->getParameter('uuid')) {
         $etva_server = EtvaServerPeer::retrieveByUuid($sid);
     } else {
         $sid = $request->getParameter('sid');
         $etva_server = EtvaServerPeer::retrieveByPK($sid);
     }
     if (!$etva_server) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid));
         return $this->renderText($msg_i18n);
     }
     $snapshot = $request->getParameter('snapshot');
     if (!$snapshot && $etva_server->getVmState() != 'stop' && $etva_server->getVmState() != 'notrunning') {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid));
         return $this->renderText($msg_i18n);
     }
     $etva_node = $etva_server->getEtvaNode();
     $url = "http://" . $etva_node->getIp();
     $request_body = "uuid=" . $etva_server->getUuid();
     if ($snapshot) {
         $request_body .= "&snapshot={$snapshot}";
     }
     $filename = $etva_server->getName() . ".tar";
     $port = $etva_node->getPort();
     if ($port) {
         $url .= ":" . $port;
     }
     $url .= "/vm_ovf_export_may_fork";
     /*
      * get response stream data
      */
     $ovf_curl = new ovfcURL($url);
     $ovf_curl->post($request_body);
     $ovf_curl->setFilename($filename);
     $ovf_curl->exec();
     if ($ovf_curl->getStatus() == 500) {
         return $this->renderText('Error 500');
     }
     return sfView::NONE;
 }
示例#6
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeView(sfWebRequest $request)
 {
     $dispatcher_id = $request->getParameter('dispatcher_id');
     // load modules file of dispatcher
     if ($dispatcher_id) {
         $criteria = new Criteria();
         $criteria->add(EtvaServicePeer::ID, $dispatcher_id);
         $etva_service = EtvaServicePeer::doSelectOne($criteria);
         $dispatcher = $etva_service->getNameTmpl();
         $etva_server = $etva_service->getEtvaServer();
         $tmpl = $etva_server->getAgentTmpl() . '_' . $dispatcher . '_modules';
         //if exists, load _DUMMY_main_modules.php file
         $directory = $this->context->getConfiguration()->getTemplateDir('dummy', '_' . $tmpl . '.php');
         if ($directory) {
             return $this->renderPartial($tmpl);
         } else {
             return $this->renderText('Template ' . $tmpl . ' not found');
         }
     } else {
         $this->etva_server = EtvaServerPeer::retrieveByPK($request->getParameter('sid'));
     }
 }
示例#7
0
 public function executeJsonMainETFW(sfWebRequest $request)
 {
     $etva_server = EtvaServerPeer::retrieveByPK($request->getParameter('sid'));
     $method = $request->getParameter('method');
     $mode = $request->getParameter('mode');
     $params = json_decode($request->getParameter('params'), true);
     if (!$params) {
         $params = array();
     }
     $ret = $this->ETFW_main($etva_server, $method, $params, $mode);
     if ($ret['success']) {
         $result = json_encode($ret);
     } else {
         $result = $this->setJsonError($ret);
     }
     $result = array();
     $this->getResponse()->setHttpHeader('Content-type', 'application/json; charset=utf-8');
     $this->getResponse()->setHttpHeader("X-JSON", '()');
     return $this->renderText($result);
 }
示例#8
0
 /**
  * Executes view action
  *
  * @param sfRequest $request A request object
  */
 public function executeView(sfWebRequest $request)
 {
     $this->etva_server = EtvaServerPeer::retrieveByPK($request->getParameter('sid'));
 }
示例#9
0
 /**
  * List logical volumes by server ID or node ID
  *
  *
  * Returns json array('id'=>id,'lv'=> lv name)
  *
  *
  */
 public function executeJsonList(sfWebRequest $request)
 {
     $nid = $request->getParameter('nid');
     $sid = $request->getParameter('sid');
     $listBy = $sid ? 'server' : 'node';
     if ($nid && !($etva_ = 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);
         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 ($sid && !($etva_ = EtvaServerPeer::retrieveByPK($sid))) {
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         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);
     }
     $lvs = array();
     switch ($listBy) {
         case 'server':
             $criteria = new Criteria();
             $criteria->addAscendingOrderByColumn(EtvaServerLogicalPeer::BOOT_DISK);
             $list = $etva_->getEtvaServerLogical($criteria);
             $pos = 0;
             foreach ($list as $elem) {
                 $disk_type = $elem->getDiskType();
                 $lv = $elem->getEtvaLogicalVolume();
                 $lv_array = $lv->toArray(BasePeer::TYPE_FIELDNAME);
                 $lv_array['disk_type'] = $disk_type;
                 $lv_array['pos'] = $pos;
                 $lv_array['per_usage'] = $lv_array['virtual_size'] / $lv_array['size'];
                 $lv_array['per_usage_snapshots'] = $lv->getPerUsageSnapshots();
                 $lvs[] = $lv_array;
                 $pos++;
             }
             break;
         default:
             $criteria = new Criteria();
             $criteria->addAscendingOrderByColumn(EtvaServerLogicalPeer::BOOT_DISK);
             $list = $etva_->getEtvaLogicalvolumes($criteria);
             foreach ($list as $elem) {
                 $id = $elem->getId();
                 $lv = $elem->getLv();
                 $lvs[$id] = array('id' => $id, 'lv' => $lv, 'target');
             }
     }
     $result = array('success' => true, 'total' => count($lvs), 'data' => $lvs);
     $return = json_encode($result);
     if (sfConfig::get('sf_environment') == 'soap') {
         return $return;
     }
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
示例#10
0
 protected function execute($arguments = array(), $options = array())
 {
     // Context
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     // server id
     $server = $arguments['server'];
     $this->log("[INFO] Start server with '{$server}'");
     $etva_server = EtvaServerPeer::retrieveByPK($server);
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByUuid($server);
     }
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByName($server);
     }
     if (!$etva_server) {
         $msg_i18n = $context->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_, array('name' => $server));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     } else {
         if ($nid = $options['node']) {
             if (!($etva_node = EtvaNodePeer::retrieveByPK($nid))) {
                 //notify event log
                 $msg_i18n = Etva::makeNotifyLogMessage(sfConfig::get('config_acronym'), EtvaNodePeer::_ERR_NOTFOUND_ID_, array('id' => $nid), EtvaServerPeer::_ERR_START_, array('name' => $server));
                 $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
                 $this->log("[ERROR] " . $error['error']);
                 return $error;
             }
         } else {
             // get list of nodes that server can assign
             $nodes_toassign = $etva_server->listNodesAssignTo();
             if (count($nodes_toassign)) {
                 $etva_node = $nodes_toassign[0];
                 // get first
             } else {
                 //notify event log
                 $msg_i18n = Etva::makeNotifyLogMessage(sfConfig::get('config_acronym'), EtvaServerPeer::_ERR_NO_NODE_TO_ASSIGN_, array(), EtvaServerPeer::_ERR_START_, array('name' => $server));
                 $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
                 $this->log("[ERROR] " . $error['error']);
                 return $error;
             }
         }
         $server_va = new EtvaServer_VA($etva_server);
         if ($options['assign'] || $etva_server->getUnassigned()) {
             // Assign server to node
             $response = $server_va->send_assign($etva_node);
             if (!$response['success']) {
                 $this->log("[ERROR] " . $response['error']);
                 return $response;
             }
         }
         // start server
         $response = $server_va->send_start($etva_node);
         if ($response['success']) {
             // update GA Info
             $response_ga = $server_va->getGAInfo($etva_node);
             $this->log("[INFO] " . $response['response']);
         } else {
             $this->log("[ERROR] " . $response['error']);
         }
         return $response;
     }
 }
示例#11
0
 public function executeJsonListCluster(sfWebRequest $request)
 {
     $filterBy = '';
     if ($request->hasParameter('sid')) {
         $filterBy = 'sid';
     }
     if ($request->hasParameter('cid')) {
         $filterBy = 'cid';
     }
     $cluster_nodes = array();
     $criteria = new Criteria();
     if ($request->hasParameter('initialize')) {
         // filter by initialized nodes only
         $criteria->add(EtvaNodePeer::INITIALIZE, 'ok', Criteria::EQUAL);
     }
     switch ($filterBy) {
         case 'sid':
             $value = $request->getParameter($filterBy);
             $server = EtvaServerPeer::retrieveByPK($value);
             $node = $server->getEtvaNode();
             $criteria->add(EtvaNodePeer::ID, $node->getId(), Criteria::NOT_EQUAL);
             $cluster_nodes = $node->getNodesCluster($criteria);
             break;
         case 'cid':
             $value = $request->getParameter($filterBy);
             if ($cluster = EtvaClusterPeer::retrieveByPK($value)) {
                 $criteria->add(EtvaNodePeer::CLUSTER_ID, $cluster->getId());
                 $cluster_nodes = EtvaNodePeer::doSelect($criteria);
             }
             break;
         default:
             $cluster_nodes = EtvaNodePeer::doSelect($criteria);
             break;
     }
     $elements = array();
     foreach ($cluster_nodes as $node) {
         $node_array = $node->toArray();
         // get max allocatable memory
         $node_array['maxmem'] = $node->getMaxmem();
         $elements[] = $node_array;
     }
     $result = array('success' => true, 'total' => count($elements), 'data' => $elements);
     $return = json_encode($result);
     if (sfConfig::get('sf_environment') == 'soap') {
         return $return;
     }
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
示例#12
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);
 }
示例#13
0
 protected function _execute($arguments = array(), $options = array())
 {
     // get server id
     $sid = $arguments['serverid'];
     $etva_server = EtvaServerPeer::retrieveByPK($sid);
     // try by id
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByUuid($sid);
     }
     // try by uuid
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByName($sid);
     }
     // try by name
     if (!$etva_server) {
         $msg_i18n = sfContext::getInstance()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid));
         // Error
         $err_m = "[ERROR] {$msg_i18n}";
         $this->report .= $err_m . "\r\n";
         $this->log($err_m);
         array_push($this->errors, array('message' => $err_m));
         return -1;
     } else {
         $etva_node = $etva_server->getEtvaNode();
         if ($etva_node) {
             $info_m = '[INFO] Backup of the server ' . $etva_server->getName() . ' assign to node ' . $etva_node->getName() . '...';
             $this->log($info_m . "\n");
             $params = array('name' => $etva_server->getName(), 'uuid' => $etva_server->getUuid());
             if ($options['location']) {
                 // location set
                 $params['location'] = $options['location'];
                 if ($options['do_not_generate_tar'] && $options['do_not_generate_tar'] != 'false') {
                     // do not generate tar
                     $params['do_not_generate_tar'] = true;
                 }
             }
             if ($options['shutdown']) {
                 // set shutdown
                 $params['shutdown'] = true;
             }
             if ($options['delete_backups_n_days']) {
                 $params['clean_old_backups'] = true;
                 $n_days = intval($options['delete_backups_n_days']);
                 if ($n_days) {
                     $params['n_days'] = $n_days;
                 }
             }
             if (!$etva_server->getHasSnapshots() && !$options['shutdown'] && !$options['snapshot'] && !$options['newsnapshot'] && $etva_server->getVmState() != 'stop' && $etva_server->getVmState() != 'notrunning') {
                 // Error is running
                 $err_m = "[ERROR] Server '" . $etva_server->getName() . "' can't create backup file of running server without snapshots";
                 $this->report .= $err_m . "\r\n";
                 $this->log($err_m);
                 array_push($this->errors, array('message' => $err_m));
                 return -101;
             }
             $server_va = new EtvaServer_VA($etva_server);
             // use snapshot for backup
             if ($options['snapshot']) {
                 // set snapshot
                 $params['snapshot'] = $options['snapshot'];
             }
             if ($options['newsnapshot'] || !$options['shutdown']) {
                 // create new snapshot
                 $newsnapshot = $options['newsnapshot'];
                 if (!$etva_server->getHasSnapshots() || $newsnapshot) {
                     $response = $server_va->create_snapshot($etva_node, $newsnapshot);
                     if (!$response['success']) {
                         $msg_i18n = $response['info'];
                         $err_m = "[ERROR] Server '" . $etva_server->getName() . "' can't create snapshot: {$msg_i18n}";
                         $this->report .= $err_m . "\r\n";
                         $this->log($err_m);
                         array_push($this->errors, array('message' => $err_m, 'error' => $response));
                         // Error
                         return -110;
                     }
                     $params['snapshot'] = $newsnapshot;
                 }
             }
             // call backup
             $res = $this->call_backup($etva_node, $params, $options['filepath']);
             if ($res < 0) {
                 return $res;
             }
             if ($options['deletesnapshot'] && $options['deletesnapshot'] != 'false') {
                 // delete snapshot after
                 if ($newsnapshot) {
                     $server_va->remove_snapshot($etva_node, $newsnapshot);
                 } else {
                     if ($snapshot) {
                         $server_va->remove_snapshot($etva_node, $snapshot);
                     }
                 }
             }
             return 0;
         } else {
             $warn_m = '[WARN] ' . $etva_server->getName() . ' VM is not assigned and will be ignored.';
             $this->report .= $warn_m . "\r\n";
             $this->log($warn_m . "\n");
             return -1010;
         }
     }
 }
示例#14
0
 /**
  *
  *
  * Download server backup from snapshot
  *
  * request object is like this;
  * <code>
  * $request['id'] = $id; //server ID
  * $request['snapshot'] = $snapshot; //using snapshot
  * </code>
  *
  * @param sfWebRequest $request A request object
  *
  * donwload machine in OVF format
  *
  */
 public function executeDownloadBackupSnapshot(sfWebRequest $request)
 {
     if ($sid = $request->getParameter('uuid')) {
         $etva_server = EtvaServerPeer::retrieveByUuid($sid);
     } else {
         if ($sid = $request->getParameter('name')) {
             $etva_server = EtvaServerPeer::retrieveByName($sid);
         } else {
             $sid = $request->getParameter('id');
             $etva_server = EtvaServerPeer::retrieveByPK($sid);
         }
     }
     /*if(!$etva_server){
                 $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_,array('%id%'=>$sid));            
                 return $this->renderText($msg_i18n);
             }
     
             $newsnapshot = $request->getParameter('newsnapshot');
             $snapshot = $request->getParameter('snapshot');
             $delete = $request->getParameter('delete');
     
             if(!$etva_server->getHasSnapshots() && !$snapshot && !$newsnapshot && ($etva_server->getVmState() != 'stop') && ($etva_server->getVmState() != 'notrunning') ){
                 $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_,array('%id%'=>$sid));            
                 return $this->renderText($msg_i18n);
             }
             
             $etva_node = $etva_server->getEtvaNode();
             
             $server_va = new EtvaServer_VA($etva_server);
     
             if( !$etva_server->getHasSnapshots() || $newsnapshot ){
                 $response = $server_va->create_snapshot($etva_node,$newsnapshot);
                 if( !$response['success'] ){
                     $msg_i18n = $response['info'];
                     return $this->renderText($msg_i18n);
                 }
             }
     
             $url = "http://".$etva_node->getIp();
             $request_body = "uuid=".$etva_server->getUuid();
     
             if( $snapshot ){
                 $request_body .= "&snapshot=$snapshot";
             }
     
             $filename = $etva_server->getName().".tar";
             
             $port = $etva_node->getPort();
             if($port) $url.=":".$port;        
             $url.="/vm_backup_snapshot_may_fork";*/
     /*
      * get response stream data
      */
     /*$ovf_curl = new ovfcURL($url);
             $ovf_curl->post($request_body);
             $ovf_curl->setFilename($filename);
             $ovf_curl->exec();
     
             if($ovf_curl->getStatus()==500) return $this->renderText('Error 500');*/
     $options_task_server_backup = array('filepath' => 'STDOUT');
     $snapshot = $request->getParameter('snapshot');
     if ($snapshot) {
         $options_task_server_backup['snapshot'] = $snapshot;
     }
     $newsnapshot = $request->getParameter('newsnapshot');
     if ($newsnapshot) {
         $options_task_server_backup['newsnapshot'] = $newsnapshot;
     }
     $delete = $request->getParameter('delete');
     if ($delete && $delete != 'false') {
         // delete after
         $options_task_server_backup['deletesnapshot'] = true;
     }
     $task_server_backup = new serverBackupTask($this->dispatcher, new sfFormatter());
     $res_task = $task_server_backup->run(array('serverid' => $sid), $options_task_server_backup);
     if ($res_task < 0) {
         // TODO treat error
         return $this->renderText('Error 500');
     }
     return sfView::NONE;
 }
示例#15
0
 protected function execute($arguments = array(), $options = array())
 {
     // Context
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // add your code here
     // server id
     $server = $arguments['server'];
     $this->log("[INFO] Check status of server '{$server}'");
     $etva_server = EtvaServerPeer::retrieveByPK($server);
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByUuid($server);
     }
     if (!$etva_server) {
         $etva_server = EtvaServerPeer::retrieveByName($server);
     }
     if (!$etva_server) {
         $msg_i18n = $context->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_, array('name' => $server));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     } else {
         if ($nid = $options['node']) {
             $etva_node = EtvaNodePeer::retrieveByPK($nid);
         } else {
             $etva_node = $etva_server->getEtvaNode();
         }
         /*if(!$etva_node){
         
                     //notify event log
                     $msg_i18n = Etva::makeNotifyLogMessage(sfConfig::get('config_acronym'),
                                                                             EtvaNodePeer::_ERR_NOTFOUND_ID_, array('id'=>$nid));
                     $error = array('success'=>false,'agent'=>sfConfig::get('config_acronym'),'error'=>$msg_i18n,'info'=>$msg_i18n);
         
                     $this->log("[ERROR] ".$error['error']);
                     return $error;
                 }
         
                 $server_va = new EtvaServer_VA($etva_server);
                 $response = $server_va->getGAInfo($etva_node);   // update GA Info
                 */
         // TODO force check
         $response = array('success' => true, 'response' => 'check ok', 'agent' => sfConfig::get('config_acronym'));
         if ($etva_node) {
             $response['agent'] = $etva_node->getName();
         }
         if ($options['check']) {
             if (!$options['request_id']) {
                 $options['request_id'] = UUID::generate(UUID::UUID_RANDOM, UUID::FMT_STRING);
             }
             $response['_request_id'] = $options['request_id'];
             $response['_request_status'] = EtvaAsynchronousJob::PENDING;
             if ($etva_server->getVmState() == $options['check']) {
                 $response['_request_status'] = EtvaAsynchronousJob::FINISHED;
                 $msg_ok_type = '';
                 if ($options['check'] == EtvaServer::STATE_RUNNING) {
                     $msg_ok_type = EtvaServerPeer::_OK_START_;
                 } elseif ($options['check'] == EtvaServer::STATE_STOP) {
                     $msg_ok_type = EtvaServerPeer::_OK_STOP_;
                 }
                 if ($msg_ok_type) {
                     $response['response'] = Etva::makeNotifyLogMessage($response['agent'], $msg_ok_type, array('name' => $etva_server->getName()), null, array(), EtvaEventLogger::INFO);
                 }
             }
             //$this->log("[DEBUG] status=".$response['_request_status']." state=".$etva_server->getVmState()." == ".$options['check']);
         }
         if ($response['success']) {
             $this->log("[INFO] " . $response['response']);
             //$this->log("[DEBUG ".print_r($response,true));
         } else {
             $this->log("[ERROR] " . $response['error']);
         }
         return $response;
     }
 }