]>
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 -p " . $name . " 2>&1";
50 OMVUtil
::exec($cmd,$out,$res);
52 throw new OMVModuleZFSException(implode("\n", $out));
55 $this->updateAllProperties();
56 $this->setProperties($properties);
57 $this->mountPoint
= $this->properties
["mountpoint"][0];
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 OMVUtil
::exec($cmd,$out,$res);
115 throw new OMVModuleZFSException(implode("\n", $out));
117 $this->updateProperty($newpropertyk);
122 * Get all Dataset properties from commandline and update object properties attribute
125 * @throws OMVModuleZFSException
128 private function updateAllProperties() {
129 $cmd = "zfs get -H all " . $this->name
;
130 OMVUtil
::exec($cmd,$out,$res);
132 throw new OMVModuleZFSException(implode("\n", $out));
134 unset($this->properties
);
135 foreach ($out as $line) {
136 $tmpary = preg_split('/\t+/', $line);
137 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
142 * Get single Datset property from commandline and update object property attribute
144 * @param string $property Name of the property to update
146 * @throws OMVModuleZFSException
149 private function updateProperty($property) {
150 $cmd = "zfs get -H " . $property . " " . $this->name
;
151 OMVUtil
::exec($cmd,$out,$res);
153 throw new OMVModuleZFSException(implode("\n", $out));
155 $tmpary = preg_split('/\t+/', $out[0]);
156 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
160 * Destroy the Dataset.
163 * @throws OMVModuleZFSException
166 public function destroy() {
167 $cmd = "zfs destroy " . $this->name
;
168 OMVUtil
::exec($cmd,$out,$res);
170 throw new OMVModuleZFSException(implode("\n", $out));
177 * @param string $newname New name of the Dataset
179 * @throws OMVModuleZFSException
182 public function rename($newname) {
183 $cmd = "zfs rename -p " . $this->name
. " " . $newname . " 2>&1";
184 OMVUtil
::exec($cmd,$out,$res);
186 throw new OMVModuleZFSException(implode("\n", $out));
188 $this->name
= $newname;
192 * Clears a previously set proporty and specifies that it should be
193 * inherited from it's parent.
195 * @param string $property Name of the property to inherit.
197 * @throws OMVModuleZFSException
200 public function inherit($property) {
201 $cmd = "zfs inherit " . $property . " " . $this->name
. " 2>&1";
202 OMVUtil
::exec($cmd,$out,$res);
204 throw new OMVModuleZFSException(implode("\n", $out));
206 $this->updateProperty($property);
This page took 0.117642 seconds and 6 git commands to generate.