]> git.datanom.net - omvzfs.git/commitdiff
Fix some bugs. Implement methods needed by zfs.inc. Zpool.php completed
authorMichael Rasmussen <mir@datanom.net>
Sat, 2 Aug 2014 01:41:14 +0000 (03:41 +0200)
committerMichael Rasmussen <mir@datanom.net>
Sat, 2 Aug 2014 01:41:14 +0000 (03:41 +0200)
gui/rpc/zfs.inc
src/Zpool.php

index 48c7ef40a32c524c5a414096e90e2ef79a228831..c7fcb264d3e0088bed6aede3a93c9ea29fdda87f 100644 (file)
@@ -10,6 +10,7 @@ require_once("zfs/Utils.php");
 require_once("zfs/Dataset.php");
 require_once("zfs/Snapshot.php");
 require_once("zfs/Zvol.php");
+require_once("zfs/Zpool.php");
 
 class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
        public function getName() { return "ZFS";} // RPC Service name. Same as in .js files
@@ -48,19 +49,23 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
        public function addObject($params, $context) {
                $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR));
                switch ($params['type']) {
-               case "filesystem":
+               case "Filesystem":
                        $name = $params['path'] . "/" . $params['name'];
                        $tmp = new OMVModuleZFSDataset($name);
                        break;
-               case "snapshot":
+               case "Snapshot":
                        $name = $params['path'] . "@" . $params['name'];
                        $tmp = new OMVModuleZFSSnapshot($name);
                        break;
-               case "volume":
+               case "Volume":
                        $name = $params['path'] . "/" . $params['name'];
                        $tmp = new OMVModuleZFSZvol($name);
                        $tmp->create($params['size']);
                        break;
+               case "Pool":
+                       $name = $params['path'] . "/" . $params['name'];
+                       $tmp = new OMVModuleZFSZpool($name);
+                       break;
                default:
                        throw new OMVModuleZFSException("Illegal type provided: " . $params['type']);
                        break;
@@ -86,6 +91,11 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                        $tmp = new OMVModuleZFSZvol($name);
                        $tmp->destroy();
                        break;
+               case "Pool":
+                       $name = $params['name'];
+                       $tmp = new OMVModuleZFSZpool($name);
+                       $tmp->destroy();
+                       break;
                default:
                        throw new OMVModuleZFSException("Illegal type provided: " . $params['type']);
                        break;
@@ -107,6 +117,9 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                case "Volume":
                        $tmp = new OMVModuleZFSZvol($name);
                        break;
+               case "Pool":
+                               $tmp = new OMVModuleZFSZpool($name);
+                               break;
                default:
                        throw new OMVModuleZFSException("Illegal type provided: " . $params['type']);
                        break;
@@ -137,6 +150,9 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                case "Volume":
                        $tmp = new OMVModuleZFSZvol($params['name']);
                        break;
+               case "Pool":
+                       $tmp = new OMVModuleZFSZpool($params['name']);
+                       break;
                default:
                        throw new OMVModuleZFSException("Illegal type provided: " . $params['type']);
                        break;
@@ -171,6 +187,9 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                        case "Volume":
                                $tmp = new OMVModuleZFSZvol($params['name']);
                                break;
+                       case "Pool":
+                               $tmp = new OMVModuleZFSZpool($params['name']);
+                               break;
                        default:
                                throw new OMVModuleZFSException("Illegal type provided: " . $params['type']);
                                break;
index 4e3401dc3a69d1010a0ea2660c884b3779d4f86e..61220a616827887f3ff5e6fa110e9d53df49b0a1 100644 (file)
@@ -5,6 +5,8 @@ require_once("Vdev.php");
 require_once("Snapshot.php");
 require_once("Dataset.php");
 require_once("Zvol.php");
+require_once("VdevType.php");
+require_once("Utils.php");
 require_once("Exception.php");
 
 /**
@@ -430,7 +432,7 @@ class OMVModuleZFSZpool extends OMVModuleAbstract
      * @return array of features
      * @access public
      */
-    public function getFeatures() {
+    public function getFeatures($internal = true) {
                $attrs = array();
                $featureSet = array(
                        'recordsize', /* default 131072. 512 <= n^2 <=  131072*/
@@ -448,9 +450,16 @@ class OMVModuleZFSZpool extends OMVModuleAbstract
                );
                if (count($this->features) < 1)
                        $this->features = $this->getAllAttributes();
-        foreach ($this->features as $attr => $val) {
-                       if (in_array($attr, $featureSet))
-                               $attrs[$attr] = $val;
+               if ($internal) {
+                       foreach ($this->features as $attr => $val) {
+                               if (in_array($attr, $featureSet))
+                                       $attrs[$attr] = $val['value'];
+                       }
+               } else {
+                       foreach ($this->features as $attr => $val) {
+                               if (in_array($attr, $featureSet))
+                                       $attrs[$attr] = $val;
+                       }
                }
 
                return $attrs;
@@ -580,6 +589,73 @@ class OMVModuleZFSZpool extends OMVModuleAbstract
         $this->debug(sprintf("onUpdateNFSShare args=%s", var_export($args, true)));
        }
 
+       /**
+        * Get a single property value associated with the Dataset
+        *
+        * @param string $property Name of the property to fetch
+        * @return array The returned array with the property. The property is an associative array with
+        * two elements, <value> and <source>.
+        * @access public
+        */
+       public function getProperty($property) {
+               $attrs = $this->getFeatures(false);
+               return $attrs["$property"];
+       }
+
+       /**
+        * Get an associative array of all properties associated with the Snapshot
+        *
+        * @return array $properties Each entry is an associative array with two elements
+        * <value> and <source>
+        * @access public
+        */
+       public function getProperties() {
+               $attrs = $this->getFeatures(false);
+               return $attrs;
+       }
+
+       /**
+        * Sets a number of Dataset properties. If a property is already set it will be updated with the new value.
+        *
+        * @param  array $properties An associative array with properties to set
+        * @return void
+        * @access public
+        */
+       public function setProperties($properties) {
+               foreach ($properties as $newpropertyk => $newpropertyv) {
+                       $cmd = "zfs set " . $newpropertyk . "=" . $newpropertyv . " " . $this->name . " 2>&1";
+                       OMVModuleZFSUtil::exec($cmd,$out,$res);
+                       $attr = $this->getAttribute($newpropertyk);
+                       $this->features[$newpropertyk] = $attr;
+               }
+       }
+
+       /**
+        * Destroy the Dataset.
+        *
+        * @return void
+        * @access public
+        */
+       public function destroy() {
+               $cmd = "zpool destroy " . $this->name . " 2>&1";
+               $this->exec($cmd,$out,$res);
+       }
+
+       /**
+        * Clears a previously set proporty and specifies that it should be
+        * inherited from it's parent.
+        *
+        * @param string $property Name of the property to inherit.
+        * @return void
+        * @access public
+        */
+       public function inherit($property) {
+               $cmd = "zfs inherit " . $property . " " . $this->name . " 2>&1";
+               $this->exec($cmd,$out,$res);
+               $attr = $this->getAttribute($newpropertyk);
+               $this->features[$newpropertyk] = $attr;
+       }
+
        /**
         * Convert array of Vdev to command string
         *
@@ -647,20 +723,32 @@ class OMVModuleZFSZpool extends OMVModuleAbstract
                $attrs = array();
                $cmd = "zfs get -H all {$this->name}";
 
-               OMVUtil::exec($cmd, $output, $result);
+               try {
+                       OMVUtil::exec($cmd, $output, $result);
+               } catch (OMVModuleZFSException $e) {}
                if ($result)
                        throw new OMVModuleZFSException($output);
                $output = implode("\n", $output);
-               $res = preg_match_all("/{$this->name}\s+(\w+)\s+([\w\d\.]+).*/", $output, $matches, PREG_SET_ORDER);
+               $res = preg_match_all("/{$this->name}\s+(\w+)\s+([\w\d\.]+)\s+(\w+).*/", $output, $matches, PREG_SET_ORDER);
                if ($res == false || $res == 0)
                        throw new OMVModuleZFSException("Error return by zpool get all: $output");
                foreach ($matches as $match) {
-                       $attrs[$match[1]] = $match[2];
+                       $attrs[$match[1]] = array('value' => $match[2], 'source' => $match[3]);
                }
 
                return $attrs;
        }
 
+       /**
+        * Get all Dataset properties from commandline and update object properties attribute
+        *
+        * @return void
+        * @access private
+        */
+       private function updateAllProperties() {
+               $this->features = $this->getAllAttributes();
+       }
+
        /**
         * Remove a disk from array
         *
This page took 0.044192 seconds and 5 git commands to generate.