]>
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->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
124 * @throws OMVModuleZFSException
127 private function updateAllProperties() {
128 $cmd = "zfs get -H all " . $this->name
;
129 OMVUtil
::exec($cmd,$out,$res);
131 throw new OMVModuleZFSException(implode("\n", $out));
133 unset($this->properties
);
134 foreach ($out as $line) {
135 $tmpary = preg_split('/\t+/', $line);
136 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
141 * Get single Datset property from commandline and update object property attribute
143 * @param string $property Name of the property to update
144 * @throws OMVModuleZFSException
147 private function updateProperty($property) {
148 $cmd = "zfs get -H " . $property . " " . $this->name
;
149 OMVUtil
::exec($cmd,$out,$res);
151 throw new OMVModuleZFSException(implode("\n", $out));
153 $tmpary = preg_split('/\t+/', $out[0]);
154 $this->properties
["$tmpary[1]"] = array($tmpary[2], $tmpary[3]);
158 * Destroy the Dataset.
160 * @throws OMVModuleZFSException
163 public function destroy() {
164 $cmd = "zfs destroy " . $this->name
;
165 OMVUtil
::exec($cmd,$out,$res);
167 throw new OMVModuleZFSException(implode("\n", $out));
This page took 0.096024 seconds and 6 git commands to generate.