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