From ba6cf545d4cb6312a9ac99b04827ccac7a33c039 Mon Sep 17 00:00:00 2001 From: Niclas Berglind Date: Sun, 2 Mar 2014 15:34:16 +0100 Subject: [PATCH] Started implementation of Dataset class Signed-off-by: Niclas Berglind --- src/Dataset.php | 144 ++++++++++++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 54 deletions(-) diff --git a/src/Dataset.php b/src/Dataset.php index c620e8a..49ddfb2 100644 --- a/src/Dataset.php +++ b/src/Dataset.php @@ -1,4 +1,5 @@ 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); + } } -- 2.39.2