Example #1
0
 public function dependsOnIt(EtvaAsynchronousJob $j1, EtvaAsynchronousJob $j2)
 {
     if ($j2->getTasknamespace() == 'logicalvolume') {
         $j2_args = (array) json_decode($j1->getArguments());
         $j2_opts = (array) json_decode($j1->getOptions());
         $etva_node = EtvaNodePeer::getOrElectNodeFromArray(array_merge($j2_opts, $j2_args));
         if ($etva_node) {
             // original logical volume
             $original_lv = $j2_args['original'];
             $original_vg = $j2_opts['original-volumegroup'];
             // find orignal logical volume
             $etva_original_lv = $etva_node->retrieveLogicalvolumeByAny($original_lv, $original_vg);
             if ($etva_original_lv) {
                 $j1_args = (array) json_decode($j1->getArguments());
                 $lv_servers = $etva_original_lv->getServers();
                 // get servers where logical volume is attached
                 foreach ($lv_servers as $srv) {
                     if ($srv->getId() == $j1_args['server'] || $srv->getUuid() == $j1_args['server'] || $srv->getName() == $j1_args['server']) {
                         return true;
                         // depends on it
                     }
                 }
             }
         }
     }
     return false;
 }
 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;
 }
 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 node
     $node_id = $options['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;
     }
     // logical volume to clone
     $lv = $arguments['logicalvolume'];
     $vg = $options['volumegroup'];
     // check if a logical volume exists
     if (!($etva_lv = $etva_node->retrieveLogicalvolumeByAny($lv, $vg))) {
         $msg = Etva::getLogMessage(array('name' => $lv), EtvaLogicalvolumePeer::_ERR_NOTFOUND_);
         $msg_i18n = $context->getI18N()->__(EtvaLogicalvolumePeer::_ERR_NOTFOUND_, array('%name%' => $lv));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     }
     // original logical volume
     $original_lv = $arguments['original'];
     $original_vg = $options['original-volumegroup'];
     // if cannot find logical volume
     if (!($etva_original_lv = $etva_node->retrieveLogicalvolumeByAny($original_lv, $original_vg))) {
         $msg = Etva::getLogMessage(array('name' => $original_lv), EtvaLogicalvolumePeer::_ERR_NOTFOUND_);
         $msg_i18n = $context->getI18N()->__(EtvaLogicalvolumePeer::_ERR_NOTFOUND_, array('%name%' => $original_lv));
         $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n);
         $this->log("[ERROR] " . $error['error']);
         return $error;
     }
     // prepare soap info....
     $lv_va = new EtvaLogicalvolume_VA($etva_lv);
     $response = $lv_va->send_clone($etva_node, $etva_original_lv);
     if (!$response['success']) {
         $this->log("[ERROR] " . $response['error']);
     } else {
         $this->log("[INFO] " . $response['response']);
     }
     return $response;
 }