]> git.datanom.net - omvzfs.git/blobdiff - src/Zvol.php
Added constructor and associated support function to Zvol class.
[omvzfs.git] / src / Zvol.php
index 5c07ebb427d1ba9cc920c43f4d8a78b4bc35e4a7..e6fba7bd81c97dc4d6df37d37fae0e2d8a5c8900 100644 (file)
@@ -44,43 +44,81 @@ class OMVModuleZFSZvol {
 
        // Associations
        // Operations
+
        /**
-        * XXX
-        *
-        * @return string XXX
+        * Constructor. If the Zvol already exists in the system the object will be updated with all
+        * associated properties from commandline.
+        * 
+        * @param string $name Name of the new Zvol
+        * @return void
         * @access public
         */
-       public function getName() {
-               trigger_error('Not Implemented!', E_USER_WARNING);
+       public function __construct($name) {
+               $this->name = $name;
+               $qname = preg_quote($name, '/');
+               $cmd = "zfs list -H -t volume";
+               $this->exec($cmd, $out, $res);
+               foreach ($out as $line) {
+                       if (preg_match('/^' . $qname . '\t.*$/', $line)) {
+                               $this->updateAllProperties();
+                               $this->mountPoint = $this->properties["mountpoint"]["value"];
+                               $this->size = $this->properties["size"]["value"];
+                               continue;
+                       }
+               }
        }
 
        /**
-        * XXX
-        *
-        * @return int XXX
+        * Return name of the Zvol
+        * 
+        * @return string $name
         * @access public
         */
-       public function getSize() {
-               trigger_error('Not Implemented!', E_USER_WARNING);
+       public function getName() {
+               return $this->name;
        }
 
        /**
-        * XXX
-        *
-        * @return string XXX
+        * Get the mountpoint of the Zvol
+        * 
+        * @return string $mountPoint
         * @access public
         */
        public function getMountPoint() {
-               trigger_error('Not Implemented!', E_USER_WARNING);
+               return $this->mountPoint;
+       }
+
+       /**
+        * Get a single property value associated with the Zvol
+        * 
+        * @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) {
+               return $this->properties["$property"];
        }
 
+       /**
+        * Get an associative array of all properties associated with the Zvol
+        * 
+        * @return array $properties Each entry is an associative array with two elements
+        * <value> and <source>
+        * @access public
+        */
+       public function getProperties() {
+               return $this->properties;
+       }
+
+
        /**
         * XXX
         *
-        * @return list<Feature> XXX
+        * @return int XXX
         * @access public
         */
-       public function getProperties() {
+       public function getSize() {
                trigger_error('Not Implemented!', E_USER_WARNING);
        }
 
@@ -95,6 +133,22 @@ class OMVModuleZFSZvol {
                trigger_error('Not Implemented!', E_USER_WARNING);
        }
 
+       /**
+        * Get all Zvol properties from commandline and update object properties attribute
+        * 
+        * @return void
+        * @access private
+        */
+       private function updateAllProperties() {
+               $cmd = "zfs get -H all " . $this->name;
+               $this->exec($cmd,$out,$res);
+               unset($this->properties);
+               foreach ($out as $line) {
+                       $tmpary = preg_split('/\t+/', $line);
+                       $this->properties["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]);
+               }
+       }
+
        /**
         * Helper function to execute a command and throw an exception on error
         * (requires stderr redirected to stdout for proper exception message).
This page took 0.291874 seconds and 5 git commands to generate.