]> git.datanom.net - omvzfs.git/commitdiff
Started implementation of Dataset class
authorNiclas Berglind <nb@kjam.se>
Sun, 2 Mar 2014 14:34:16 +0000 (15:34 +0100)
committerMichael Rasmussen <mir@datanom.net>
Sun, 2 Mar 2014 22:58:17 +0000 (23:58 +0100)
Signed-off-by: Niclas Berglind <nb@kjam.se>
src/Dataset.php

index c620e8a9a0986234d316b45625aad7ffb61909c9..49ddfb2a466d487bd9056c90f6f9172ab2838988 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+require_once("Exception.php");
 
 /**
  * XXX detailed description
@@ -18,81 +19,116 @@ class OMVModuleZFSDataset {
     private $name;
 
     /**
-     * XXX
+     * Size of Dataset
      *
      * @var    int $size
      * @access private
      */
-    private $_size;
+    private $size;
 
     /**
-     * XXX
+     * Mountpoint of the Dataset
      *
      * @var    string $mountPoint
      * @access private
      */
-    private $_mountPoint;
+    private $mountPoint;
 
     /**
-     * XXX
+     * List of features assigned to the Dataset
      *
      * @var    array $features
      * @access private
      */
-    private $_features;
+    private $features;
 
-    // Associations
-    // Operations
-    /**
-     * Return name of the Dataset
-     *
-     * @return string $name
-     * @access public
-     */
-    public function getName() {
-        return $this->name;
-    }
+       // Associations
+       // Operations
 
-    /**
-     * XXX
-     *
-     * @return int XXX
-     * @access public
-     */
-    public function getSize() {
-        trigger_error('Not Implemented!', E_USER_WARNING);
-    }
+       /**
+        * Constructor
+        * 
+        * @param string $name Name of the new Dataset
+        * @param array $features An array of features to set when creating the Dataset
+        *
+        */
+       public function __construct($name, array $features = null) {
+               $cmd = "zfs create ";
+               if (isset($features)) {
+                       $cmd .= "-o " . implode(",", $features) . " ";
+               }
+               $cmd .= $name . " 2>&1";
+               exec($cmd,$out,$res);
+               if ($res == 1) {
+                       throw new OMVModuleZFSException(implode("\n", $out));
+               }
+               unset($res);
+               $this->name = $name;
+               if (isset($features)) {
+                       $this->features = $features;
+                       foreach ($features as $feature) {
+                               if (preg_match('/^mountpoint\=(.*)$/', $feature, $res)) {
+                                       $this->mountPoint = $res[1];
+                                       continue;
+                               }
+                       }
+               } else {
+                       $this->features = array();
+                       $this->mountPoint = "/" . $name;
+               }
+       }
 
-    /**
-     * XXX
-     *
-     * @return string XXX
-     * @access public
-     */
-    public function getMountPoint() {
-        trigger_error('Not Implemented!', E_USER_WARNING);
-    }
+       /**
+        * Return name of the Dataset
+        *
+        * @return string $name
+        * @access public
+        */
+       public function getName() {
+               return $this->name;
+       }
 
-    /**
-     * XXX
-     *
-     * @return array XXX
-     * @access public
-     */
-    public function getFeatures() {
-        trigger_error('Not Implemented!', E_USER_WARNING);
-    }
+       /**
+        * Get the size of the Dataset
+        *
+        * @return int $size
+        * @access public
+        */
+       public function getSize() {
+               return $this->size;
+       }
 
-    /**
-     * XXX
-     *
-     * @param  array XXX
-     * @return void XXX
-     * @access public
-     */
-    public function setFeatures($list) {
-        trigger_error('Not Implemented!', E_USER_WARNING);
-    }
+
+       /**
+        * Get the mountpoint of the Dataset
+        *
+        * @return string $mountPoint
+        * @access public
+        */
+       public function getMountPoint() {
+               return $this->mountPoint;
+       }
+
+       /**
+        * Get an array of features associated with the Dataset
+        *
+        * @return array $features
+        * @access public
+        */
+       public function getFeatures() {
+               return $this->features;
+       }
+
+       /**
+        * XXX
+        *
+        * @param  array XXX
+        * @return void XXX
+        * @access public
+        */
+       public function setFeatures($list) {
+               trigger_error('Not Implemented!', E_USER_WARNING);
+       }
 
 }
 
This page took 0.038959 seconds and 5 git commands to generate.