]>
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
48 public function __construct($name, array $properties = null) {
49 $cmd = "zfs create -p " . $name . " 2>&1";
50 $this->exec($cmd,$out,$res);
52 $this->updateAllProperties();
53 $this->setProperties($properties);
54 $this->mountPoint
= $this->properties
["mountpoint"][0];
58 * Return name of the Dataset
60 * @return string $name
63 public function getName() {
68 * Get the mountpoint of the Dataset
70 * @return string $mountPoint
73 public function getMountPoint() {
74 return $this->mountPoint
;
78 * Get a single property value associated with the Dataset
80 * @param string $property Name of the property to fetch
81 * @return array The returned array key 0=property value and key 1=property source.
84 public function getProperty($property) {
85 return $this->properties
["$property"];
89 * Get an associative array of all properties associated with the Dataset.
91 * @return array $properties Each entry is an array where key 0=property value and key
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 $this->exec($cmd,$out,$res);
111 $this->updateProperty($newpropertyk);
116 * Get all Dataset properties from commandline and update object properties attribute
121 private function updateAllProperties() {
122 $cmd = "zfs get -H all " . $this->name
;
123 $this->exec($cmd,$out,$res);
124 unset($this->properties
);
125 foreach ($out as $line) {
126 $tmpary = preg_split('/\t+/', $line);
127 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
132 * Get single Datset property from commandline and update object property attribute
134 * @param string $property Name of the property to update
138 private function updateProperty($property) {
139 $cmd = "zfs get -H " . $property . " " . $this->name
;
140 $this->exec($cmd,$out,$res);
141 $tmpary = preg_split('/\t+/', $out[0]);
142 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
146 * Destroy the Dataset.
151 public function destroy() {
152 $cmd = "zfs destroy " . $this->name
;
153 $this->exec($cmd,$out,$res);
159 * @param string $newname New name of the Dataset
163 public function rename($newname) {
164 $cmd = "zfs rename -p " . $this->name
. " " . $newname . " 2>&1";
165 $this->exec($cmd,$out,$res);
166 $this->name
= $newname;
170 * Clears a previously set proporty and specifies that it should be
171 * inherited from it's parent.
173 * @param string $property Name of the property to inherit.
177 public function inherit($property) {
178 $cmd = "zfs inherit " . $property . " " . $this->name
. " 2>&1";
179 $this->exec($cmd,$out,$res);
180 $this->updateProperty($property);
184 * Upgrades the Dataset to latest filesystem version
189 public function upgrade() {
190 $cmd = "zfs upgrade " . $this->name
. " 2>&1";
191 $this->exec($cmd,$out,$res);
195 * Helper function to execute a command and throw an exception on error
196 * (requires stderr redirected to stdout for proper exception message).
198 * @param string $cmd Command to execute
199 * @param array &$out If provided will contain output in an array
200 * @param int &$res If provided will contain Exit status of the command
201 * @return string Last line of output when executing the command
202 * @throws OMVModuleZFSException
205 private function exec($cmd, &$out = null, &$res = null) {
206 $tmp = OMVUtil
::exec($cmd, $out, $res);
208 throw new OMVModuleZFSException(implode("\n", $out));
This page took 0.085575 seconds and 6 git commands to generate.