<?php
require_once("Exception.php");
+require_once("openmediavault/util.inc");
/**
* XXX detailed description
* @access private
*/
private $name;
-
- /**
- * Size of Dataset
- *
- * @var int $size
- * @access private
- */
- private $size;
-
/**
* Mountpoint of the Dataset
*
private $mountPoint;
/**
- * List of features assigned to the Dataset
+ * Array with properties assigned to the Dataset
*
- * @var array $features
+ * @var array $properties
* @access private
*/
- private $features;
+ private $properties;
// Associations
// Operations
/**
* Constructor
- *
+ *
* @param string $name Name of the new Dataset
- * @param array $features An array of features to set when creating the Dataset
+ * @param array $properties An associative array with properties 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) . " ";
- }
- $cmd .= $name . " 2>&1";
- exec($cmd,$out,$res);
- if ($res == 1) {
+ public function __construct($name, array $properties = null) {
+ $cmd = "zfs create " . $name . " 2>&1";
+ OMVUtil::exec($cmd,$out,$res);
+ if ($res) {
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;
- }
+ $this->setProperties($properties);
+ $this->mountPoint = $this->properties["mountpoint"];
}
/**
}
/**
- * Get the size of the Dataset
+ * Get the mountpoint of the Dataset
*
- * @return int $size
+ * @return string $mountPoint
* @access public
*/
- public function getSize() {
- return $this->size;
+ public function getMountPoint() {
+ return $this->mountPoint;
}
+ /**
+ * Get a single property value associated with the Dataset
+ *
+ * @param string $property Name of the property to fetch
+ * @return string
+ * @access public
+ */
+ public function getProperty($property) {
+ return $this->properties["$property"];
+ }
/**
- * Get the mountpoint of the Dataset
+ * Get an array of all properties associated with the Dataset
*
- * @return string $mountPoint
+ * @return array $properties
* @access public
*/
- public function getMountPoint() {
- return $this->mountPoint;
+ public function getProperties() {
+ return $this->properties;
}
/**
- * Get an array of features associated with the Dataset
+ * Sets a number of Dataset properties. If a property is already set it will be updated with the new value.
*
- * @return array $features
+ * @param array $properties An associative array with properties to set
+ * @return void
* @access public
*/
- public function getFeatures() {
- return $this->features;
+ public function setProperties($properties) {
+ foreach ($properties as $newpropertyk => $newpropertyv) {
+ $cmd = "zfs set " . $newpropertyk . "=" . $newpropertyv . " " . $this->name;
+ OMVUtil::exec($cmd,$out,$res);
+ if ($res) {
+ throw new OMVModuleZFSException(implode("\n", $out));
+ }
+ $this->properties["$newpropertyk"] = $newpropertyv;
+ }
+ $this->updateAllProperties();
}
/**
- * XXX
+ * Get all Dataset properties from commandline and update object properties attribute
*
- * @param array XXX
- * @return void XXX
+ * @throws OMVModuleZFSException
+ * @access private
+ */
+ private function updateAllProperties() {
+ $cmd = "zfs get -H all " . $this->name;
+ OMVUtil::exec($cmd,$out,$res);
+ if ($res) {
+ throw new OMVModuleZFSException(implode("\n", $out));
+ }
+ unset($this->properties);
+ foreach ($out as $line) {
+ $tmpary = preg_split('/\t+/', $line);
+ $this->properties["$tmpary[1]"] = $tmpary[2];
+ }
+ }
+
+ /**
+ * Destroy the Dataset.
+ *
+ * @throws OMVModuleZFSException
* @access public
*/
- public function setFeatures($list) {
- trigger_error('Not Implemented!', E_USER_WARNING);
+ public function destroy() {
+ $cmd = "zfs destroy " . $this->name;
+ OMVUtil::exec($cmd,$out,$res);
+ if ($res) {
+ throw new OMVModuleZFSException(implode("\n", $out));
+ }
}
}