Esempio n. 1
0
 /**
  * Return pre-formatted data for tree-column extjs
  *
  * $request may contain the following keys:
  * - nid: nid (virtAgent node ID)
  * @return array json array
  */
 public function executeJsonClusterLvsTree(sfWebRequest $request)
 {
     $cluster_id = $request->getParameter('cid');
     $lvs = array();
     //        $etva_node = EtvaNodePeer::retrieveByPK($request->getParameter('nid'));
     //
     //        if(!$etva_node){
     //            $msg_i18n = $this->getContext()->getI18N()->__('No data found');
     //            $lvs[] = array('expanded'=>true,'text'=>$msg_i18n,'qtip'=>$msg_i18n,'leaf'=>true);
     //            $return = json_encode($lvs);
     //
     //            $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     //            return $this->renderText($return);
     //        }
     //
     //        $criteria = new Criteria();
     //        $node_lvs = $etva_node->getEtvaLogicalvolumes($criteria);
     //get cluster logical volumes
     $criteria = new Criteria();
     $criteria->add(EtvaLogicalVolumePeer::CLUSTER_ID, $cluster_id, Criteria::EQUAL);
     $criteria->addAnd(EtvaLogicalVolumePeer::STORAGE_TYPE, EtvaLogicalVolume::STORAGE_TYPE_LOCAL_MAP, Criteria::ALT_NOT_EQUAL);
     $criteria->addAscendingOrderByColumn(EtvaLogicalvolumePeer::LV);
     $cluster_lvs = EtvaLogicalVolumePeer::doSelect($criteria);
     $snapshots = array();
     foreach ($cluster_lvs as $etva_lv) {
         $vm_name = '';
         $vm_state = '';
         $etva_vg = $etva_lv->getEtvaVolumegroup();
         $etva_server = $etva_lv->getEtvaServer();
         if ($etva_server) {
             $vm_name = $etva_server->getName();
             $vm_state = $etva_server->getVmState();
         }
         //check data consistency....should be fine
         if ($etva_vg) {
             $id = $etva_lv->getId();
             $text = $etva_lv->getLv();
             $disabled = false;
             if ($etva_lv->getInUse()) {
                 $qtip = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INUSE_, array('%name%' => $text, '%server%' => $vm_name));
             } else {
                 if ($etva_lv->getMounted()) {
                     $qtip = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_SYSTEM_LV_, array('%name%' => $text));
                     $disabled = true;
                     //                } else if( $etva_lv->getSnapshotNodeId() && ($etva_lv->getSnapshotNodeId() != $etva_node->getId()) ){
                     //                    $qtip = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_SNAPSHOT_INOTHERNODE_,array('%name%'=>$text));
                     //                    $disabled = true;
                 } else {
                     if ($etva_lv->getSnapshot()) {
                         $qtip = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_SNAPSHOT_CLUSTER_CONTEXT_, array('%name%' => $text, '%node%' => ''));
                         $disabled = true;
                     } else {
                         if ($etva_lv->getInconsistent()) {
                             $qtip = $this->getContext()->getI18N()->__('Inconsistent');
                             $disabled = true;
                         } else {
                             $qtip = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_NOTINUSE_, array('%name%' => $text));
                         }
                     }
                 }
             }
             $pretty_size = $etva_lv->getSize();
             $size = $etva_lv->getSize();
             $vg = $etva_vg->getVg();
             $vg_size = $etva_vg->getSize();
             $vg_freesize = $etva_vg->getFreesize();
             $cls = 'lv';
             if ($etva_lv->getSnapshot()) {
                 $snapshots[] = array('id' => $id, 'cls' => $cls, 'iconCls' => 'task', 'text' => $text, 'size' => $size, 'prettysize' => $pretty_size, 'vgsize' => $vg_size, 'singleClickExpand' => true, 'type' => 'lv-snapshot', 'vg' => $vg, 'vgfreesize' => $vg_freesize, 'snapshot' => $etva_lv->getSnapshot(), 'vm_state' => $vm_state, 'disabled' => $disabled, 'uuid' => $etva_lv->getUuid(), 'origin' => $etva_lv->getOrigin(), 'format' => $etva_lv->getFormat(), 'snapshot_node_id' => $etva_lv->getSnapshotNodeId(), 'vm_name' => $vm_name, 'qtip' => $qtip, 'leaf' => true);
             } else {
                 $per_usage = $etva_lv->getVirtualSize() / $etva_lv->getSize();
                 $lv_iconCls = 'devices-folder';
                 if ($etva_lv->getPerUsageSnapshots() >= EtvaLogicalvolume::PER_USAGESNAPSHOTS_CRITICAL) {
                     $lv_iconCls = 'devices-folder-error';
                 }
                 $lvs[] = array('id' => $id, 'cls' => $cls, 'iconCls' => $lv_iconCls, 'text' => $text, 'size' => $size, 'prettysize' => $pretty_size, 'vgsize' => $vg_size, 'singleClickExpand' => true, 'type' => 'lv', 'vg' => $vg, 'vgfreesize' => $vg_freesize, 'format' => $etva_lv->getFormat(), 'uuid' => $etva_lv->getUuid(), 'vm_state' => $vm_state, 'disabled' => $disabled, 'virtual_size' => $etva_lv->getVirtualSize(), 'size_snapshots' => $etva_lv->getSizeSnapshots(), 'per_usage' => $per_usage, 'per_usage_snapshots' => $etva_lv->getPerUsageSnapshots(), 'vm_name' => $vm_name, 'qtip' => $qtip, 'leaf' => true);
             }
         }
     }
     foreach ($snapshots as $sn) {
         for ($i = 0; $i < sizeof($lvs); $i++) {
             if ($sn['vg'] == $lvs[$i]['vg'] && $sn['origin'] == $lvs[$i]['text']) {
                 $lvs[$i]['leaf'] = false;
                 $lvs[$i]['expanded'] = true;
                 $lvs[$i]['children'][] = $sn;
                 $lvs[$i]['havesnapshots'] = true;
                 if ($sn['vm_name']) {
                     $lvs[$i]['havesnapshots_inuse'] = true;
                 }
                 if ($sn['vm_state'] == 'running') {
                     $lvs[$i]['havesnapshots_inuse_inrunningvm'] = true;
                 }
                 if ($sn['snapshot_node_id']) {
                     $lvs[$i]['snapshot_node_id'];
                 }
                 if ($sn['snapshot_node_id']) {
                     $lvs[$i]['qtip'] = $this->getContext()->getI18N()->__(EtvaLogicalvolumePeer::_LV_HAVESNAPSHOTS_INNODE_CONTEXT_, array('%name%' => $text));
                     $lvs[$i]['disabled'] = true;
                 }
             }
         }
     }
     //$return = json_encode(array(array('text'=>'Lvs','expanded'=>true,'children'=>$lvs)));
     if (empty($lvs)) {
         $msg_i18n = $this->getContext()->getI18N()->__('No data found');
         $lvs[] = array('expanded' => true, 'text' => $msg_i18n, 'qtip' => $msg_i18n, 'leaf' => true);
     }
     $return = json_encode($lvs);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($return);
 }
 public function unregister(EtvaNode $etva_node)
 {
     $etva_volgroup = $this->etva_vg;
     /*
      * delete pvs with vg
      */
     $etva_volgroup_physical_list = EtvaVolumePhysicalPeer::getByEtvaVolumeGroupId($etva_volgroup->getId());
     foreach ($etva_volgroup_physical_list as $etva_volgroup_physical) {
         $etva_physical = $etva_volgroup_physical->getEtvaPhysicalvolume();
         $etva_volgroup_physical->delete();
         $etva_physical->delete();
     }
     /*
      * delete lvs with vg
      */
     $etva_logicalvolumes_list = EtvaLogicalVolumePeer::getByEtvaVolumeGroupId($etva_volgroup->getId());
     foreach ($etva_logicalvolumes_list as $etva_logicalvolume) {
         $etva_logicalvolume->delete();
     }
     // delete it
     $etva_volgroup->delete();
     return array('success' => true);
 }