]>
Commit | Line | Data |
---|---|---|
f891182f | 1 | <?php |
b9872428 NB |
2 | require_once("Exception.php"); |
3 | require_once("openmediavault/util.inc"); | |
f891182f MR |
4 | |
5 | /** | |
6 | * XXX detailed description | |
7 | * | |
8 | * @author XXX | |
9 | * @version XXX | |
10 | * @copyright XXX | |
11 | */ | |
63617ac2 | 12 | class 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)) { | |
48 | print("Name found!!!\n"); | |
49 | $this->updateAllProperties(); | |
50 | continue; | |
51 | } | |
52 | } | |
53 | } | |
f891182f | 54 | |
b9872428 NB |
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 | } | |
f891182f | 64 | |
b9872428 NB |
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 | } | |
f891182f | 74 | |
b9872428 NB |
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 | } | |
f891182f | 101 | |
b9872428 NB |
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 | } | |
f891182f MR |
120 | } |
121 | ||
122 | ?> |