From: Niclas Berglind Date: Wed, 12 Mar 2014 19:34:18 +0000 (+0100) Subject: Added constructor and associated support function to Zvol class. X-Git-Url: http://git.datanom.net/omvzfs.git/commitdiff_plain/112892fb46436d0e1ca23f3d8c66c659e04d8651 Added constructor and associated support function to Zvol class. Signed-off-by: Niclas Berglind --- diff --git a/src/Zvol.php b/src/Zvol.php index a262241..e6fba7b 100644 --- a/src/Zvol.php +++ b/src/Zvol.php @@ -44,7 +44,30 @@ class OMVModuleZFSZvol { // Associations // Operations - + + /** + * 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 __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; + } + } + } + /** * Return name of the Zvol * @@ -110,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).