Newer
Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
$params['create_dns'] = 'n';
$params['capability'] = '';
return $this->insertQuery('../vm/form/openvz_vm.tform.php',$client_id,$params,'vm:openvz_vm:on_after_insert');
}
//* Update openvz vm record
public function openvz_vm_update($session_id, $client_id, $vm_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../vm/form/openvz_vm.tform.php',$client_id,$vm_id,$params,'vm:openvz_vm:on_after_update');
return $affected_rows;
}
//* Delete openvz vm record
public function openvz_vm_delete($session_id, $vm_id)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../vm/form/openvz_vm.tform.php',$vm_id,'vm:openvz_vm:on_after_delete');
return $affected_rows;
}
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
//* Start VM
public function openvz_vm_start($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
$vm = $app->remoting_lib->getDataRecord($vm_id);
if(!is_array($vm)) {
$this->server->fault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
$this->server->fault('action_pending', 'VM is not in active state.');
return false;
}
$action = 'openvz_start_vm';
$tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
WHERE server_id = '".$vm['server_id']."'
AND action_type = '$action'
AND action_param = '".$vm['veid']."'
AND action_state = 'pending'");
if($tmp['actions'] > 0) {
$this->server->fault('action_pending', 'There is already a action pending for this VM.');
return false;
} else {
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (".
(int)$vm['server_id'] . ", ".
time() . ", ".
"'".$action."', ".
$vm['veid'].", ".
"'pending', ".
"''".
")";
$app->db->query($sql);
}
}
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
//* Stop VM
public function openvz_vm_stop($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
$vm = $app->remoting_lib->getDataRecord($vm_id);
if(!is_array($vm)) {
$this->server->fault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
$this->server->fault('action_pending', 'VM is not in active state.');
return false;
}
$action = 'openvz_stop_vm';
$tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
WHERE server_id = '".$vm['server_id']."'
AND action_type = '$action'
AND action_param = '".$vm['veid']."'
AND action_state = 'pending'");
if($tmp['actions'] > 0) {
$this->server->fault('action_pending', 'There is already a action pending for this VM.');
return false;
} else {
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (".
(int)$vm['server_id'] . ", ".
time() . ", ".
"'".$action."', ".
$vm['veid'].", ".
"'pending', ".
"''".
")";
$app->db->query($sql);
}
}
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
//* Restart VM
public function openvz_vm_restart($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
$vm = $app->remoting_lib->getDataRecord($vm_id);
if(!is_array($vm)) {
$this->server->fault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
$this->server->fault('action_pending', 'VM is not in active state.');
return false;
}
$action = 'openvz_restart_vm';
$tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
WHERE server_id = '".$vm['server_id']."'
AND action_type = '$action'
AND action_param = '".$vm['veid']."'
AND action_state = 'pending'");
if($tmp['actions'] > 0) {
$this->server->fault('action_pending', 'There is already a action pending for this VM.');
return false;
} else {
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (".
(int)$vm['server_id'] . ", ".
time() . ", ".
"'".$action."', ".
$vm['veid'].", ".
"'pending', ".
"''".
")";
$app->db->query($sql);
}
}