]> git.datanom.net - omvzfs.git/blobdiff - gui/rpc/zfs.inc
Support for cloned filesystems and volumes.
[omvzfs.git] / gui / rpc / zfs.inc
index f52f5dbb8a7370c69222c8c11c04a01421d65f4a..bbab27ca3824b961d5dc8136ab5cc2406dd5e62a 100644 (file)
@@ -31,6 +31,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                $this->registermethod("getSharedParams");
                $this->registermethod("createShare");
                $this->registermethod("getObjectDetails");
+               $this->registermethod("expandPool");
        }
 
        public function addPool($params, $context) {
@@ -125,13 +126,18 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                          "type":"object",
                          "properties":{
                                  "type":{"type":"string","enum":["filesystem","snapshot",' .
-                                       '"volume"]},
+                                       '"volume","clone"]},
                                  "path":{"type":"string"},
                                  "name":{"type":"string"},
-                                 "size":{"type":"string"}
+                                 "size":{"type":"string"},
+                                 "clonename":{"type":"string"}
                          }
                  }');
                switch ($params['type']) {
+               case "clone":
+                       $tmp = new OMVModuleZFSSnapshot($params['path']);
+                       $tmp->clonesnap($params['clonename']);
+                       break;
                case "filesystem":
                        $name = $params['path'] . "/" . $params['name'];
                        $tmp = new OMVModuleZFSDataset($name);
@@ -158,7 +164,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                          "type":"object",
                          "properties":{
                                  "type":{"type":"string","enum":["Filesystem","Snapshot",' .
-                                       '"Volume","Clone","Pool"]},
+                                       '"Volume","Pool"]},
                                  "name":{"type":"string"}
                          }
                  }');
@@ -170,10 +176,6 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                        $tmp = new OMVModuleZFSDataset($name);
                        $tmp->destroy();
                        break;
-               case "Clone":
-                       $tmp = new OMVModuleZFSDataset($name);
-                       $tmp->destroy();
-                       break;
                case "Snapshot":
                        $tmp = new OMVModuleZFSSnapshot($name);
                        $tmp->destroy();
@@ -216,7 +218,6 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                $name = $params['name'];
                switch ($params['type']) {
                case "Filesystem":
-               case "Clone":
                        $tmp = new OMVModuleZFSDataset($name);
                        break;
                case "Snapshot":
@@ -251,7 +252,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                        "type":"object",
                                "properties":{
                                        "type":{"type":"string","enum":["Filesystem","Snapshot",' .
-                                               '"Volume","Clone","Pool"]},
+                                               '"Volume","Pool"]},
                                        "name":{"type":"string"},
                                        "properties":{"type":"array","items":{
                                                "type":"object",
@@ -263,7 +264,6 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                global $xmlConfig;
                switch ($params['type']) {
                case "Filesystem":
-               case "Clone":
                        $tmp = new OMVModuleZFSDataset($params['name']);
                        break;
                case "Snapshot":
@@ -297,7 +297,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                          "type":"object",
                          "properties":{
                                  "type":{"type":"string","enum":["Filesystem","Snapshot",' .
-                                       '"Volume","Clone","Pool"]},
+                                       '"Volume","Pool"]},
                                  "name":{"type":"string"},
                                  "property":{"type":"string"}
                          }
@@ -315,7 +315,6 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                        $this->updateBgProcStatus($bgStatusFilename, "outputfilename", $bgOutputFilename);
                        switch ($params['type']) {
                        case "Filesystem":
-                       case "Clone":
                                $tmp = new OMVModuleZFSDataset($params['name']);
                                break;
                        case "Snapshot":
@@ -367,7 +366,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                          "type":"object",
                          "properties":{
                                  "name":{"type":"string"},
-                                 "type":{"type":"string","enum":["Filesystem","Clone"]},
+                                 "type":{"type":"string","enum":["Filesystem"]},
                                  "sharename":{'.$GLOBALS['OMV_JSONSCHEMA_SHARENAME'].'},
                                  "comment":{"type":"string"},
                                  "mode":{"type":"string","enum":["700","750","755",'.
@@ -390,9 +389,6 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                case "Filesystem":
                        $tmp = new OMVModuleZFSDataset($params['name']);
                        break;
-               case "Clone":
-                       $tmp = new OMVModuleZFSDataset($params['name']);
-                       break;
                default:
                        throw new OMVModuleZFSException("Illegal type provided: " . $params['type']);
                        break;
@@ -525,6 +521,59 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract {
                $output .= implode("\n\r", $out);
                return array("details" => $output);
        }
+       
+       public function expandPool($params, $context) {
+               $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR));
+               // Validate the parameters of the RPC service method.
+               $this->validateMethodParams($params, '{
+                         "type":"object",
+                         "properties":{
+                                 "vdevtype":{"type":"string","enum":["basic","mirror",' .
+                                       '"raidz1","raidz2","raidz3"]},
+                                 "name":{"type":"string"},
+                                 "devices":{"type":"string"},
+                                 "force":{"type":"boolean"}
+                         }
+               }');
+               $pool = new OMVModuleZFSZpool($params['name']);
+               switch ($params['vdevtype']) {
+               case "basic":
+                       $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSPLAIN;
+                       break;
+               case "mirror":
+                       $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSMIRROR;
+                       break;
+               case "raidz1":
+                       $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ1;
+                       break;
+               case "raidz2":
+                       $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ2;
+                       break;
+               case "raidz3":
+                       $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ3;
+                       break;
+               default:
+                       throw new OMVModuleZFSException("Incorrect pool type specified");
+                       break;
+               }
+               if ($params['force']) {
+                       $opts .= "-f ";
+               }
+               //Use /dev/disk/by-path as deafult when creating new pools as suggested in ZoL FAQ.
+               $disks = preg_split("/[,;]/", $params['devices']);
+               if (file_exists("/dev/disk/by-path/")) {
+                       $tmp_disks = array();
+                       foreach ($disks as $disk) {
+                               $tmp_disks[] = OMVModuleZFSUtil::getDiskPath($disk);
+                       }
+                       $disks = $tmp_disks;
+               }
+               $vdev[] = new OMVModuleZFSVdev($params['name'], $pooltype, $disks);
+               $pool->addVdev($vdev, $opts);
+               //Ugly fix to solve the problem of blkid not displaying info on newly created pools
+               $pool->export();
+               $pool->import($pool->getName());
+       }
 }
 
 // Register the RPC service.
This page took 0.037894 seconds and 5 git commands to generate.