]> git.datanom.net - omvzfs.git/blob - src/Snapshot.php
Started work on Snapshot class.
[omvzfs.git] / src / Snapshot.php
1 <?php
2 require_once("Exception.php");
3 require_once("openmediavault/util.inc");
4
5 /**
6 * XXX detailed description
7 *
8 * @author XXX
9 * @version XXX
10 * @copyright XXX
11 */
12 class OMVModuleZFSSnapshot {
13 // Attributes
14 /**
15 * Name of the Snapshot
16 *
17 * @var string $name
18 * @access private
19 */
20 private $name;
21
22 /**
23 * Properties associated with the Snaphost
24 *
25 * @var array $properties
26 * @access private
27 */
28 private $properties;
29
30 // Associations
31 // Operations
32
33 /**
34 * Constructor. If the Snapshot already exists in the system the object will be updated with all
35 * associated properties from commandline.
36 *
37 * @param string $name Name of the new Snapshot
38 * @return void
39 * @access public
40 */
41 public function __construct($name) {
42 $this->name = $name;
43 $qname = preg_quote($name, '/');
44 $cmd = "zfs list -H -t snapshot";
45 $this->exec($cmd, $out, $res);
46 foreach ($out as $line) {
47 if (preg_match('/^' . $qname . '\t.*$/', $line)) {
48 print("Name found!!!\n");
49 $this->updateAllProperties();
50 continue;
51 }
52 }
53 }
54
55 /**
56 * Return name of the Snapshot
57 *
58 * @return string Nameof the Snapshot
59 * @access public
60 */
61 public function getName() {
62 return $this->name;
63 }
64
65 /**
66 * XXX
67 *
68 * @return list<Feature> XXX
69 * @access public
70 */
71 public function getFeatures() {
72 trigger_error('Not Implemented!', E_USER_WARNING);
73 }
74
75 /**
76 * XXX
77 *
78 * @param $list<Feature> XXX
79 * @return void XXX
80 * @access public
81 */
82 public function setFeatures($list) {
83 trigger_error('Not Implemented!', E_USER_WARNING);
84 }
85
86 /**
87 * Get all Snapshot properties from commandline and update object properties attribute
88 *
89 * @return void
90 * @access private
91 */
92 private function updateAllProperties() {
93 $cmd = "zfs get -H all " . $this->name;
94 $this->exec($cmd,$out,$res);
95 unset($this->properties);
96 foreach ($out as $line) {
97 $tmpary = preg_split('/\t+/', $line);
98 $this->properties["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]);
99 }
100 }
101
102 /**
103 * Helper function to execute a command and throw an exception on error
104 * (requires stderr redirected to stdout for proper exception message).
105 *
106 * @param string $cmd Command to execute
107 * @param array &$out If provided will contain output in an array
108 * @param int &$res If provided will contain Exit status of the command
109 * @return string Last line of output when executing the command
110 * @throws OMVModuleZFSException
111 * @access private
112 */
113 private function exec($cmd, &$out = null, &$res = null) {
114 $tmp = OMVUtil::exec($cmd, $out, $res);
115 if ($res) {
116 throw new OMVModuleZFSException(implode("\n", $out));
117 }
118 return $tmp;
119 }
120 }
121
122 ?>
This page took 0.086416 seconds and 6 git commands to generate.