]> git.datanom.net - omvzfs.git/blob - src/Dataset.php
Removed size from Dataset. Implemented setFeatures and destroy methods to Dataset.
[omvzfs.git] / src / Dataset.php
1 <?php
2 require_once("Exception.php");
3
4 /**
5 * XXX detailed description
6 *
7 * @author XXX
8 * @version XXX
9 * @copyright XXX
10 */
11 class OMVModuleZFSDataset {
12 // Attributes
13 /**
14 * Name of Dataset
15 *
16 * @var string $name
17 * @access private
18 */
19 private $name;
20 /**
21 * Mountpoint of the Dataset
22 *
23 * @var string $mountPoint
24 * @access private
25 */
26 private $mountPoint;
27
28 /**
29 * List of features assigned to the Dataset
30 *
31 * @var array $features
32 * @access private
33 */
34 private $features;
35
36 // Associations
37 // Operations
38
39 /**
40 * Constructor
41 *
42 * @param string $name Name of the new Dataset
43 * @param array $features An array of features (strings) in the form <key>=<value> to set when creating the Dataset
44 * @throws OMVModuleZFSException
45 *
46 */
47 public function __construct($name, array $features = null) {
48 $cmd = "zfs create ";
49 if (isset($features)) {
50 foreach ($features as $feature) {
51 $cmd .= "-o " . $feature . " ";
52 }
53 }
54 $cmd .= $name . " 2>&1";
55 exec($cmd,$out,$res);
56 if ($res == 1) {
57 throw new OMVModuleZFSException(implode("\n", $out));
58 }
59 unset($res);
60 $this->name = $name;
61 if (isset($features)) {
62 $this->features = $features;
63 foreach ($features as $feature) {
64 if (preg_match('/^mountpoint\=(.*)$/', $feature, $res)) {
65 $this->mountPoint = $res[1];
66 continue;
67 }
68 }
69 } else {
70 $this->features = array();
71 $this->mountPoint = "/" . $name;
72 }
73 }
74
75 /**
76 * Return name of the Dataset
77 *
78 * @return string $name
79 * @access public
80 */
81 public function getName() {
82 return $this->name;
83 }
84
85 /**
86 * Get the mountpoint of the Dataset
87 *
88 * @return string $mountPoint
89 * @access public
90 */
91 public function getMountPoint() {
92 return $this->mountPoint;
93 }
94
95 /**
96 * Get an array of features associated with the Dataset
97 *
98 * @return array $features
99 * @access public
100 */
101 public function getFeatures() {
102 return $this->features;
103 }
104
105 /**
106 * Sets a number of Dataset properties. If a property is already set it will be updated with the new value.
107 *
108 * @param array $features An array of strings in format <key>=<value>
109 * @return void
110 * @access public
111 */
112 public function setFeatures($features) {
113 foreach ($features as $newfeature) {
114 $cmd = "zfs set " . $newfeature . " " . $this->name;
115 exec($cmd,$out,$res);
116 if ($res == 1) {
117 throw new OMVModuleZFSException(implode("\n", $out));
118 }
119 $tmp = explode("=", $newfeature);
120 $newfeaturek = $tmp[0];
121 $found = false;
122 for ($i=0; $i<count($this->features); $i++) {
123 $tmp = explode("=", $this->features[$i]);
124 $oldfeaturek = $tmp[0];
125 if (strcmp($newfeaturek, $oldfeaturek) == 0) {
126 $this->features[$i] = $newfeature;
127 $found = true;
128 continue;
129 }
130 }
131 if (!$found) {
132 array_push($this->features, $newfeature);
133 }
134 }
135 }
136
137 /**
138 * Destroy the Dataset.
139 *
140 */
141 public function destroy() {
142 $cmd = "zfs destroy " . $this->name;
143 exec($cmd,$out,$res);
144 if ($res == 1) {
145 throw new OMVModuleZFSException(implode("\n", $out));
146 }
147 }
148
149 }
150
151 ?>
This page took 0.151705 seconds and 6 git commands to generate.