]>
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
47 public function __construct($name, array $properties = null) {
48 $cmd = "zfs create -p " . $name . " 2>&1";
49 $this->exec($cmd,$out,$res);
51 $this->updateAllProperties();
52 $this->setProperties($properties);
53 $this->mountPoint
= $this->properties
["mountpoint"][0];
57 * Return name of the Dataset
59 * @return string $name
62 public function getName() {
67 * Get the mountpoint of the Dataset
69 * @return string $mountPoint
72 public function getMountPoint() {
73 return $this->mountPoint
;
77 * Get a single property value associated with the Dataset
79 * @param string $property Name of the property to fetch
80 * @return array The returned array key 0=property value and key 1=property source.
83 public function getProperty($property) {
84 return $this->properties
["$property"];
88 * Get an associative array of all properties associated with the Dataset.
90 * @return array $properties Each entry is an array where key 0=property value and key
95 public function getProperties() {
96 return $this->properties
;
100 * Sets a number of Dataset properties. If a property is already set it will be updated with the new value.
102 * @param array $properties An associative array with properties to set
106 public function setProperties($properties) {
107 foreach ($properties as $newpropertyk => $newpropertyv) {
108 $cmd = "zfs set " . $newpropertyk . "=" . $newpropertyv . " " . $this->name
;
109 $this->exec($cmd,$out,$res);
110 $this->updateProperty($newpropertyk);
115 * Get all Dataset properties from commandline and update object properties attribute
120 private function updateAllProperties() {
121 $cmd = "zfs get -H all " . $this->name
;
122 $this->exec($cmd,$out,$res);
123 unset($this->properties
);
124 foreach ($out as $line) {
125 $tmpary = preg_split('/\t+/', $line);
126 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
131 * Get single Datset property from commandline and update object property attribute
133 * @param string $property Name of the property to update
137 private function updateProperty($property) {
138 $cmd = "zfs get -H " . $property . " " . $this->name
;
139 $this->exec($cmd,$out,$res);
140 $tmpary = preg_split('/\t+/', $out[0]);
141 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
145 * Destroy the Dataset.
150 public function destroy() {
151 $cmd = "zfs destroy " . $this->name
;
152 $this->exec($cmd,$out,$res);
158 * @param string $newname New name of the Dataset
162 public function rename($newname) {
163 $cmd = "zfs rename -p " . $this->name
. " " . $newname . " 2>&1";
164 $this->exec($cmd,$out,$res);
165 $this->name
= $newname;
169 * Clears a previously set proporty and specifies that it should be
170 * inherited from it's parent.
172 * @param string $property Name of the property to inherit.
176 public function inherit($property) {
177 $cmd = "zfs inherit " . $property . " " . $this->name
. " 2>&1";
178 $this->exec($cmd,$out,$res);
179 $this->updateProperty($property);
183 * Helper function to execute a command and throw an exception on error
184 * (requires stderr redirected to stdout for proper exception message).
186 * @param string $cmd Command to execute
187 * @param array &$out If provided will contain output in an array
188 * @param int &$res If provided will contain Exit status of the command
189 * @return string Last line of output when executing the command
190 * @throws OMVModuleZFSException
193 private function exec($cmd, &$out = null, &$res = null) {
194 $tmp = OMVUtil
::exec($cmd, $out, $res);
196 throw new OMVModuleZFSException(implode("\n", $out));
This page took 0.128042 seconds and 6 git commands to generate.