centralM
[ class tree: centralM ] [ index: centralM ] [ all elements ]

Source for file actions.class.php

Documentation is available at actions.class.php

  1. <?php
  2.  
  3. /**
  4.  * physicalvol actions.
  5.  *
  6.  * @package    centralM
  7.  * @subpackage physicalvol
  8.  * @author     Your name here
  9.  * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
  10.  */
  11. class physicalvolActions extends sfActions
  12. {
  13.   
  14.  
  15.   
  16.   /*
  17.    * Initializes a physical device
  18.    * Params: array pv (mapping to db phpnames), nid (virtAgent node ID)
  19.    * Return json array
  20.    */
  21.   public function executeJsonCreate(sfWebRequest $request)
  22.   {
  23.         // set node id criteria
  24.         $criteria new Criteria();
  25.         $criteria->add(EtvaPhysicalvolumePeer::NODE_ID,$request->getParameter('nid'));
  26.  
  27.  
  28.         $pv ($request->getParameter('pv')) json_decode($request->getParameter('pv'),true):array();
  29.  
  30.         $pv_device $pv['Device'];
  31.  
  32.         // checks if an physical device matchs the physical volume we want to initialize
  33.         if(!$etva_pv EtvaPhysicalvolumePeer::retrieveByDevice($pv_device,$criteria)){
  34.             $error_msg sprintf('Object EtvaPhysicalvolume does not exist (%s).'$pv);
  35.             $info array('success'=>false,'errors'=>$error_msg);
  36.             $error $this->setJsonError($info);
  37.             return $this->renderText($error);
  38.         }
  39.  
  40.         $etva_pv->fromArray($pv);
  41.  
  42.  
  43.         $etva_pv->save();
  44.  
  45.         $result array('success'=>true,'object'=>$etva_pv->toArray());
  46.         $result json_encode($result);
  47.  
  48.         $this->getContext()->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  49.  
  50.         return $this->renderText($result);
  51.   }
  52.  
  53.   /*
  54.    * Params: nid (virtAgent node ID)
  55.    * Used to return pre-formatted data for tree-column extjs
  56.    */
  57.   public function executeJsonPhydiskTree(sfWebRequest $request)
  58.   {
  59.       /* criteria to select only node ID column matching with nid
  60.       */
  61.       $criteria new Criteria();
  62.       $criteria->clearSelectColumns();
  63.       $criteria->add(EtvaPhysicalvolumePeer::NODE_ID,$request->getParameter('nid'));
  64.  
  65.       $criteria->addSelectColumn(EtvaPhysicalvolumePeer::STORAGE_TYPE);
  66.       $criteria->setDistinct();
  67.     
  68.       // select distinct storage types
  69.       $stmt EtvaPhysicalvolumePeer::doSelectStmt($criteria);
  70.  
  71.       $aux array();
  72.       // foreach storage type....
  73.       while ($row $stmt->fetch(PDO::FETCH_NUM)) {
  74.  
  75.           $storage_type $row[0];
  76.           $criteria new Criteria();
  77.           $criteria->add(EtvaPhysicalvolumePeer::NODE_ID,$request->getParameter('nid'));
  78.           $criteria->add(EtvaPhysicalvolumePeer::STORAGE_TYPE,$storage_type);
  79.  
  80.           $list EtvaPhysicalvolumePeer::doSelect($criteria);
  81.           $children array();
  82.           foreach ($list as $elem){
  83.               $id $elem->getDevice();
  84.               $qtip 'Physical volume NOT initialized';
  85.               $type $cls 'dev-pd';
  86.               $tag $elem->getName();
  87.               
  88.               $pvsize $elem->getPvsize();
  89.               $pretty_pvsize $elem->getPvsize();
  90.  
  91.               $pretty_size $elem->getDevsize();
  92.               $size $elem->getDevsize();
  93.  
  94.  
  95.  
  96.               if($elem->getPvinit())$qtip 'Physical volume initialized';
  97.                                   $type'dev-pv';
  98.                                   $cls 'dev-pv';
  99.               }
  100.               
  101.               $children[array('id'=>$id,'uiProvider'=>'col','iconCls'=>'task','cls'=>$cls,'text'=>$tag,'size'=>$size,'prettysize'=>$pretty_size,'pvsize'=>$pvsize,'pretty-pvsize'=>$pretty_pvsize'singleClickExpand'=>true,'type'=>$type,'qtip'=>$qtip,'leaf'=>true);
  102.           }
  103.  
  104.           $aux[array('id'=>$row[0],'uiProvider'=>'col','iconCls'=>'devices-folder','text'=>$storage_type'singleClickExpand'=>true,'children'=>$children);
  105.  
  106.  
  107.       }
  108.  
  109.  
  110.       $return json_encode($aux);
  111.       $this->getResponse()->setHttpHeader("X-JSON"'()');
  112.  
  113.       return $this->renderText($return);
  114.  
  115.   }
  116.  
  117.   /*
  118.    * Params: nid (virtAgent node ID)
  119.    * Used to return pre-formatted data for the combo box of the vgcreate process (extjs)
  120.    * Returns data thas has allocatable==1 AND pvinit==1
  121.    */
  122.   public function executeJsonGetAllocatable(sfWebRequest $request)
  123.   {
  124.  
  125.  
  126.     $isAjax $request->isXmlHttpRequest();
  127.  
  128.     // If is not an Ajax Request redirect to homepage
  129.     if(!$isAjaxreturn $this->redirect('@homepage');
  130.  
  131.     $criteria new Criteria();
  132.  
  133.     $criteria->add(EtvaPhysicalvolumePeer::NODE_ID,$request->getParameter('nid'));
  134.  
  135.     $criteria->add(EtvaPhysicalvolumePeer::ALLOCATABLE1);
  136.     $criteria->add(EtvaPhysicalvolumePeer::PVINIT1);
  137.  
  138.     $etva_pvs EtvaPhysicalvolumePeer::doSelect($criteria);
  139.  
  140.     // Check if there are physical volumes available to create a new volume group
  141.     if(!$etva_pvs){
  142.         $info array('success'=>false,'errors'=>'No physical volumes available');
  143.         $error $this->setJsonError($info);
  144.         return $this->renderText($error);
  145.     }
  146.  
  147.  
  148.     $elements array();
  149.     foreach ($etva_pvs as $pv){
  150.  
  151.             $device $pv->getDevice();
  152.             $name $pv->getName();           
  153.             $elements[array('value'=>$device,'name'=>$name);
  154.  
  155.  
  156.     }
  157.  
  158.     $result array('total' =>   count($elements),'data'  => $elements);
  159.  
  160.     $return json_encode($result);
  161.     $this->getResponse()->setHttpHeader("X-JSON"'()');
  162.     return $this->renderText($return);
  163.  
  164.   }
  165.  
  166.   /*
  167.    * Unitialize the device
  168.    * Params: device, nid (virtAgent node ID)
  169.    * Unsets the physical volume info
  170.    * 
  171.    */
  172.   public function executeJsonRemove(sfWebRequest $request)
  173.   {
  174.     $isAjax $request->isXmlHttpRequest();
  175.  
  176.     if(!$isAjaxreturn $this->redirect('@homepage');
  177.  
  178.     $criteria new Criteria();
  179.     $criteria->add(EtvaPhysicalvolumePeer::NODE_ID,$request->getParameter('nid'));
  180.  
  181.     // get physical volume by device name
  182.     if(!$etva_pv EtvaPhysicalvolumePeer::retrieveByDevice($request->getParameter('device'),$criteria)){
  183.  
  184.         $error_msg sprintf('Object EtvaPhysicalvolume does not exist (%s).'$request->getParameter('device'));
  185.         $info array('success'=>false,'errors'=>$error_msg);
  186.         $error $this->setJsonError($info);
  187.         return $this->renderText($error);
  188.     }
  189.  
  190.     // unset physical volume
  191.     $etva_pv->setPvinit('');
  192.     $etva_pv->setPv('');
  193.     $etva_pv->setPvsize('');
  194.     $etva_pv->setPvfreesize('');
  195.     $etva_pv->setAllocatable(0);
  196.  
  197.     $etva_pv->save()
  198.  
  199.     $result array('success'=>true);
  200.     $result json_encode($result);
  201.     $this->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  202.     return $this->renderText($result);
  203.   }
  204.  
  205.  
  206.   protected function setJsonError($info,$statusCode 400){
  207.  
  208.       $this->getContext()->getResponse()->setStatusCode($statusCode);
  209.       $error json_encode($info);
  210.       $this->getContext()->getResponse()->setHttpHeader("X-JSON"'()');
  211.       return $error;
  212.  
  213.   }
  214.  
  215.  
  216.  
  217.  
  218.   /*
  219.    * Used to process soap requests => updateVirtAgentDevices
  220.    * Updates physical volume/device info
  221.    * 
  222.    * Params: uid (virtAgent uid), devs (object containing devices info)
  223.    * Return: array success
  224.    */
  225.   public function executeSoapUpdate(sfWebRequest $request)
  226.   {
  227.       /*
  228.        * Check if the request is made via soapapi.php interface
  229.        */
  230.       if(SF_ENVIRONMENT == 'soap'){
  231.  
  232.             $devs $request->getParameter('devs');
  233.  
  234.             // check node ID correspondig to the uid given
  235.             $c new Criteria();
  236.             $c->add(EtvaNodePeer::UID ,$request->getParameter('uid'));
  237.  
  238.  
  239.             if(!$etva_node EtvaNodePeer::doSelectOne($c)){
  240.                 $error_msg sprintf('Object etva_node does not exist (%s).'$request->getParameter('uid'));
  241.                 $error array('success'=>false,'errors'=>$error_msg);
  242.                 return $error;
  243.             }
  244.  
  245.             //check physical volumes of the agent
  246.             $criteriaPV new Criteria();
  247.             $criteriaPV->add(EtvaPhysicalvolumePeer::NODE_ID,$etva_node->getId());
  248.  
  249.  
  250.             foreach($devs as $dev=>$devInfo){
  251.  
  252.                 /*
  253.                  * check if already in DB the data
  254.                  * if not, insert it, otherwise update
  255.                  */
  256.                 $etva_physicalvol EtvaPhysicalvolumePeer::retrieveByDevice($devInfo->device,$criteriaPV);
  257.                 if(!$etva_physicalvol$etva_physicalvol new EtvaPhysicalvolume();
  258.  
  259.                 
  260.                 $etva_physicalvol->setNodeId($etva_node->getId());
  261.                 $etva_physicalvol->setName($dev);
  262.                 $etva_physicalvol->setDevice($devInfo->device);
  263.                 $etva_physicalvol->setDevsize($devInfo->size);
  264.                 $etva_physicalvol->setPv($devInfo->pv);
  265.                 $etva_physicalvol->setPvsize($devInfo->pvsize);
  266.                 $etva_physicalvol->setPvfreesize($devInfo->pvfreesize);
  267.                 $etva_physicalvol->setPvinit($devInfo->pvinit);
  268.                 $etva_physicalvol->setStorageType($devInfo->type);
  269.  
  270.                 if(empty($devInfo->vg)) $etva_physicalvol->setAllocatable(1);
  271.                 else $etva_physicalvol->setAllocatable(0);
  272.  
  273.  
  274.                 $etva_physicalvol->save();
  275.  
  276.             }
  277.  
  278.             return array('success'=>true);
  279.      }// end soap request
  280.  
  281.   }
  282.  
  283.   
  284.  
  285.   
  286. }

Documentation generated on Fri, 19 Jun 2009 10:45:51 +0100 by phpDocumentor 1.4.2