]>
git.datanom.net - omvzfs.git/blob - src/Dataset.php
2 require_once("Exception.php");
3 require_once("openmediavault/util.inc");
6 * XXX detailed description
12 class OMVModuleZFSDataset
{
22 * Mountpoint of the Dataset
24 * @var string $mountPoint
30 * Array with properties assigned to the Dataset
32 * @var array $properties
43 * @param string $name Name of the new Dataset
44 * @param array $properties An associative array with properties to set when creating the Dataset
45 * @throws OMVModuleZFSException
48 public function __construct($name, array $properties = null) {
49 $cmd = "zfs create " . $name . " 2>&1";
50 OMVUtil
::exec($cmd,$out,$res);
52 throw new OMVModuleZFSException(implode("\n", $out));
55 $this->setProperties($properties);
56 $this->mountPoint
= $this->properties
["mountpoint"];
60 * Return name of the Dataset
62 * @return string $name
65 public function getName() {
70 * Get the mountpoint of the Dataset
72 * @return string $mountPoint
75 public function getMountPoint() {
76 return $this->mountPoint
;
80 * Get a single property value associated with the Dataset
82 * @param string $property Name of the property to fetch
86 public function getProperty($property) {
87 return $this->properties
["$property"];
91 * Get an array of all properties associated with the Dataset
93 * @return array $properties
96 public function getProperties() {
97 return $this->properties
;
101 * Sets a number of Dataset properties. If a property is already set it will be updated with the new value.
103 * @param array $properties An associative array with properties to set
107 public function setProperties($properties) {
108 foreach ($properties as $newpropertyk => $newpropertyv) {
109 $cmd = "zfs set " . $newpropertyk . "=" . $newpropertyv . " " . $this->name
;
110 OMVUtil
::exec($cmd,$out,$res);
112 throw new OMVModuleZFSException(implode("\n", $out));
114 $this->properties
["$newpropertyk"] = $newpropertyv;
116 $this->updateAllProperties();
120 * Get all Dataset properties from commandline and update object properties attribute
122 * @throws OMVModuleZFSException
125 private function updateAllProperties() {
126 $cmd = "zfs get -H all " . $this->name
;
127 OMVUtil
::exec($cmd,$out,$res);
129 throw new OMVModuleZFSException(implode("\n", $out));
131 unset($this->properties
);
132 foreach ($out as $line) {
133 $tmpary = preg_split('/\t+/', $line);
134 $this->properties
["$tmpary[1]"] = $tmpary[2];
139 * Destroy the Dataset.
141 * @throws OMVModuleZFSException
144 public function destroy() {
145 $cmd = "zfs destroy " . $this->name
;
146 OMVUtil
::exec($cmd,$out,$res);
148 throw new OMVModuleZFSException(implode("\n", $out));
This page took 0.107226 seconds and 6 git commands to generate.