-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zfs.php
121 lines (102 loc) · 3.74 KB
/
Zfs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
class Zfs {
public $zfs_user;
public $zfs_hostname;
function __construct($zfs_user, $zfs_hostname) {
$this->zfs_user = $zfs_user;
$this->zfs_hostname = $zfs_hostname;
}
public function create_vm($vm_name, $template_name, $vm_ip) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname virtzfs create vm -n $vm_name -t $template_name -a $vm_ip -i 1";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
}
public function delete_vm($vm_name) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname virtzfs delete vm -v $vm_name";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
}
public function snapshot_vm($vm_name, $snapshot_name) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname virtzfs snapshot vm -v $vm_name -n $snapshot_name";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
}
public function rollback_vm($vm_name, $snapshot_name, $vm_power) {
global $error;
if ($vm_power != 'off') {
$error->set_msg("Virtual Machine must be Power OFF first to rollback.");
return(ERROR);
}
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname virtzfs rollback vm -v $vm_name -s $snapshot_name";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
}
public function get_template_list() {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname virtzfs list template";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
return($array_output);
}
public function get_snapshot_list($vm_name) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname virtzfs list snapshot -v $vm_name";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
return($array_output);
}
public function get_dedicated_nfs($vm_name) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname zfs get -H quota " . ZFS_DEDICATED_NFS_PATH . "/$vm_name | awk '{ print $3 }'";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
return($array_output[0]);
}
public function update_dedicated_nfs_size($vm_name, $size) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname zfs set quota=" . $size . "G " . ZFS_DEDICATED_NFS_PATH . "/$vm_name";
exec($cmd, $array_output, $return);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
}
public function get_zpool_detail($zfs_zpool) {
global $error;
$cmd = "ssh -l $this->zfs_user $this->zfs_hostname zpool list -H $zfs_zpool | awk '{ print $2\",\"$5 }'";
exec($cmd, $array_output, $return);
$array_zpool = explode(",", $array_output[0]);
if ($return != 0) {
$error->set_msg($array_output[0]);
return(ERROR);
}
$zpool['space_total'] = $array_zpool[0];
$zpool['space_usage'] = $array_zpool[1];
return($zpool);
}
}
?>