]> git.datanom.net - omvzfs.git/blobdiff - src/Dataset.php
Started implementation of Dataset class
[omvzfs.git] / src / Dataset.php
index 210fc6ea2f54e57fcb82d2d458f881115fedf661..49ddfb2a466d487bd9056c90f6f9172ab2838988 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+require_once("Exception.php");
 
 /**
  * XXX detailed description
  * @version   XXX
  * @copyright XXX
  */
-class Dataset {
+class OMVModuleZFSDataset {
     // Attributes
     /**
-     * XXX
+     * Name of Dataset
      *
      * @var    string $name
      * @access private
      */
-    private $_name;
+    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
-    /**
-     * XXX
-     *
-     * @return string XXX
-     * @access public
-     */
-    public function getName() {
-        trigger_error('Not Implemented!', E_USER_WARNING);
-    }
+       // 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<Feature>) {
-        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.072037 seconds and 5 git commands to generate.