protected function execute($arguments = array(), $options = array())
 {
     $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
     // get parameters
     $lv = $arguments['name'];
     $size = $arguments['size'];
     $vg = $arguments['volumegroup'];
     $node_id = $options['node'];
     $format = $options['format'];
     $persnapshotusage = $options['persnapshotusage'];
     /*
      * check if lv is a file disk instead
      * if is a file disk check if special volume group exists. if not create
      */
     $is_DiskFile = $vg == sfConfig::get('app_volgroup_disk_flag') ? 1 : 0;
     // get etva_node
     $etva_node = EtvaNodePeer::getOrElectNodeFromArray(array_merge($options, $arguments));
     if (!$etva_node) {
         $msg_i18n = $context->getI18N()->__(EtvaNodePeer::_ERR_NOTFOUND_ID_, array('%id%' => $node_id));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     }
     // get logical volume
     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 = $context->getI18N()->__($msg_type, array('%name%' => $lv));
         $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     }
     if (!($etva_vg = $etva_node->retrieveVolumegroupByVg($vg))) {
         $msg = Etva::getLogMessage(array('name' => $vg), EtvaVolumegroupPeer::_ERR_NOTFOUND_);
         $msg_i18n = $context->getI18N()->__(EtvaVolumegroupPeer::_ERR_NOTFOUND_, array('%name%' => $vg));
         $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     }
     // prepare soap info....
     $etva_lv = new EtvaLogicalvolume();
     $etva_lv->setEtvaVolumegroup($etva_vg);
     $etva_lv->setLv($lv);
     $lv_va = new EtvaLogicalvolume_VA($etva_lv);
     $response = $lv_va->send_create($etva_node, $size, $format, $persnapshotusage);
     if (!$response['success']) {
         $this->log("[ERROR] " . $response['error']);
     } else {
         $this->log("[INFO] " . $response['response']);
     }
     return $response;
 }
Esempio n. 2
0
 /**
  * Create logical volume snapshot
  *
  * $request may contain the following keys:
  * - nid: node ID
  * - slv: snapshot name
  * - olv: logical volume
  * - size: size
  *
  */
 public function executeJsonCreateSnapshot(sfWebRequest $request)
 {
     // logical volume id
     $nid = $request->getParameter('nid');
     $slv = $request->getParameter('slv');
     $olv = $request->getParameter('olv');
     $size = $request->getParameter('size');
     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 system log
         $node_log = Etva::getLogMessage(array('id' => $nid), EtvaNodePeer::_ERR_NOTFOUND_ID_);
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $msg_i18n, '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_lv = $etva_node->retrieveLogicalvolumeByLv($olv))) {
         $msg = Etva::getLogMessage(array('name' => $lv), EtvaLogicalvolumePeer::_ERR_NOTFOUND_);
         $msg_i18n = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_NOTFOUND_, array('%name%' => $lv));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         //notify system log
         $this->dispatcher->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $msg_i18n, '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_slv = $etva_node->retrieveLogicalvolumeByLv($slv)) {
         $msg_type = $is_DiskFile ? EtvaLogicalvolumePeer::_ERR_DISK_EXIST_ : EtvaLogicalvolumePeer::_ERR_LV_EXIST_;
         $msg = Etva::getLogMessage(array('name' => $slv), $msg_type);
         $msg_i18n = $this->getContext()->getI18N()->__($msg_type, array('%name%' => $slv));
         $error = array('success' => false, 'agent' => $etva_node->getName(), 'error' => $msg_i18n, 'info' => $msg_i18n);
         //notify system log
         $message = Etva::getLogMessage(array('name' => $slv, 'info' => $msg), EtvaLogicalvolumePeer::_ERR_CREATESNAPSHOT_);
         $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);
     }
     // HERE
     $etva_vg = $etva_lv->getEtvaVolumegroup();
     /*
      * send logical volume to VA
      */
     #$lv_va = new EtvaLogicalvolume_VA($etva_lv);
     // prepare soap info....
     $etva_slv = new EtvaLogicalvolume();
     $etva_slv->setEtvaVolumegroup($etva_vg);
     $etva_slv->setLv($slv);
     $slv_va = new EtvaLogicalvolume_VA($etva_slv);
     $response = $slv_va->send_createsnapshot($etva_node, $etva_lv, $size);
     if ($response['success']) {
         $return = json_encode($response);
         // 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);
     } else {
         if (sfConfig::get('sf_environment') == 'soap') {
             return json_encode($response);
         }
         $return = $this->setJsonError($response);
         return $this->renderText($return);
     }
 }