From 0b156fc35ef4c22fbffd506fd2c8bbb2cf6187db Mon Sep 17 00:00:00 2001 From: Niclas Berglind Date: Sun, 2 Mar 2014 21:59:28 +0100 Subject: [PATCH] Removed size from Dataset. Implemented setFeatures and destroy methods to Dataset. Signed-off-by: Niclas Berglind --- src/Dataset.php | 70 ++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/src/Dataset.php b/src/Dataset.php index 49ddfb2..afdd172 100644 --- a/src/Dataset.php +++ b/src/Dataset.php @@ -17,15 +17,6 @@ class OMVModuleZFSDataset { * @access private */ private $name; - - /** - * Size of Dataset - * - * @var int $size - * @access private - */ - private $size; - /** * Mountpoint of the Dataset * @@ -49,13 +40,16 @@ class OMVModuleZFSDataset { * Constructor * * @param string $name Name of the new Dataset - * @param array $features An array of features to set when creating the Dataset + * @param array $features An array of features (strings) in the form = to set when creating the Dataset + * @throws OMVModuleZFSException * */ public function __construct($name, array $features = null) { $cmd = "zfs create "; if (isset($features)) { - $cmd .= "-o " . implode(",", $features) . " "; + foreach ($features as $feature) { + $cmd .= "-o " . $feature . " "; + } } $cmd .= $name . " 2>&1"; exec($cmd,$out,$res); @@ -88,17 +82,6 @@ class OMVModuleZFSDataset { return $this->name; } - /** - * Get the size of the Dataset - * - * @return int $size - * @access public - */ - public function getSize() { - return $this->size; - } - - /** * Get the mountpoint of the Dataset * @@ -120,14 +103,47 @@ class OMVModuleZFSDataset { } /** - * XXX + * Sets a number of Dataset properties. If a property is already set it will be updated with the new value. * - * @param array XXX - * @return void XXX + * @param array $features An array of strings in format = + * @return void * @access public */ - public function setFeatures($list) { - trigger_error('Not Implemented!', E_USER_WARNING); + public function setFeatures($features) { + foreach ($features as $newfeature) { + $cmd = "zfs set " . $newfeature . " " . $this->name; + exec($cmd,$out,$res); + if ($res == 1) { + throw new OMVModuleZFSException(implode("\n", $out)); + } + $tmp = explode("=", $newfeature); + $newfeaturek = $tmp[0]; + $found = false; + for ($i=0; $ifeatures); $i++) { + $tmp = explode("=", $this->features[$i]); + $oldfeaturek = $tmp[0]; + if (strcmp($newfeaturek, $oldfeaturek) == 0) { + $this->features[$i] = $newfeature; + $found = true; + continue; + } + } + if (!$found) { + array_push($this->features, $newfeature); + } + } + } + + /** + * Destroy the Dataset. + * + */ + public function destroy() { + $cmd = "zfs destroy " . $this->name; + exec($cmd,$out,$res); + if ($res == 1) { + throw new OMVModuleZFSException(implode("\n", $out)); + } } } -- 2.39.2