]>
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
{
23 * Mountpoint of the Dataset
25 * @var string $mountPoint
31 * Array with properties assigned to the Dataset
33 * @var array $properties
44 * @param string $name Name of the new Dataset
45 * @param array $properties An associative array with properties to set when creating the Dataset
46 * @param bool $create Should the Dataset be created on commandline? Defaults to false.
49 public function __construct($name, array $properties = null, $create = false) {
51 $cmd = "zfs create -p " . $name . " 2>&1";
52 $this->exec($cmd,$out,$res);
55 $this->updateAllProperties();
56 $this->setProperties($properties);
57 $this->mountPoint
= $this->properties
["mountpoint"]["value"];
61 * Return name of the Dataset
63 * @return string $name
66 public function getName() {
71 * Get the mountpoint of the Dataset
73 * @return string $mountPoint
76 public function getMountPoint() {
77 return $this->mountPoint
;
81 * Get a single property value associated with the Dataset
83 * @param string $property Name of the property to fetch
84 * @return array The returned array key 0=property value and key 1=property source.
87 public function getProperty($property) {
88 return $this->properties
["$property"];
92 * Get an associative array of all properties associated with the Dataset.
94 * @return array $properties Each entry is an array where key 0=property value and key
99 public function getProperties() {
100 return $this->properties
;
104 * Sets a number of Dataset properties. If a property is already set it will be updated with the new value.
106 * @param array $properties An associative array with properties to set
110 public function setProperties($properties) {
111 foreach ($properties as $newpropertyk => $newpropertyv) {
112 $cmd = "zfs set " . $newpropertyk . "=" . $newpropertyv . " " . $this->name
;
113 $this->exec($cmd,$out,$res);
114 $this->updateProperty($newpropertyk);
119 * Get all Dataset properties from commandline and update object properties attribute
124 private function updateAllProperties() {
125 $cmd = "zfs get -H all " . $this->name
;
126 $this->exec($cmd,$out,$res);
127 unset($this->properties
);
128 foreach ($out as $line) {
129 $tmpary = preg_split('/\t+/', $line);
130 $this->properties
["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]);
135 * Get single Datset property from commandline and update object property attribute
137 * @param string $property Name of the property to update
141 private function updateProperty($property) {
142 $cmd = "zfs get -H " . $property . " " . $this->name
;
143 $this->exec($cmd,$out,$res);
144 $tmpary = preg_split('/\t+/', $out[0]);
145 $this->properties
["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]);
149 * Destroy the Dataset.
154 public function destroy() {
155 $cmd = "zfs destroy " . $this->name
;
156 $this->exec($cmd,$out,$res);
162 * @param string $newname New name of the Dataset
166 public function rename($newname) {
167 $cmd = "zfs rename -p " . $this->name
. " " . $newname . " 2>&1";
168 $this->exec($cmd,$out,$res);
169 $this->name
= $newname;
173 * Clears a previously set proporty and specifies that it should be
174 * inherited from it's parent.
176 * @param string $property Name of the property to inherit.
180 public function inherit($property) {
181 $cmd = "zfs inherit " . $property . " " . $this->name
. " 2>&1";
182 $this->exec($cmd,$out,$res);
183 $this->updateProperty($property);
187 * Upgrades the Dataset to latest filesystem version
192 public function upgrade() {
193 $cmd = "zfs upgrade " . $this->name
. " 2>&1";
194 $this->exec($cmd,$out,$res);
203 public function mount() {
204 $cmd = "zfs mount " . $this->name
. " 2>&1";
205 $this->exec($cmd,$out,$res);
206 $this->updateProperty("mounted");
210 * Unmount the Dataset
215 public function unmount() {
216 $cmd = "zfs unmount " . $this->name
. " 2>&1";
217 $this->exec($cmd,$out,$res);
218 $this->updateProperty("mounted");
223 * Helper function to execute a command and throw an exception on error
224 * (requires stderr redirected to stdout for proper exception message).
226 * @param string $cmd Command to execute
227 * @param array &$out If provided will contain output in an array
228 * @param int &$res If provided will contain Exit status of the command
229 * @return string Last line of output when executing the command
230 * @throws OMVModuleZFSException
233 private function exec($cmd, &$out = null, &$res = null) {
234 $tmp = OMVUtil
::exec($cmd, $out, $res);
236 throw new OMVModuleZFSException(implode("\n", $out));
This page took 0.111413 seconds and 6 git commands to generate.