$this->server->fault('permission_denied','You do not have the permissions to access this function.');
returnfalse;
}
$server_id=intval($server_id);
if($server_id>0){
$tmp=$app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 AND server_id = $server_id LIMIT 0,1");
}else{
$tmp=$app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 LIMIT 0,1");
}
if(count($tmp)>0){
return$tmp;
}else{
$this->server->fault('no_free_ip','There is no free IP available.');
$this->server->fault('permission_denied','You do not have the permissions to access this function.');
returnfalse;
}
$template_id=intval($template_id);
$ostemplate_id=intval($ostemplate_id);
//* Verify parameters
if($template_id==0){
$this->server->fault('template_id_error','Template ID must be > 0.');
returnfalse;
}
if($ostemplate_id==0){
$this->server->fault('ostemplate_id_error','OSTemplate ID must be > 0.');
returnfalse;
}
// Verify if template and ostemplate exist
$tmp=$app->db->queryOneRecord("SELECT template_id FROM openvz_template WHERE template_id = $template_id");
if(!is_array($tmp)){
$this->server->fault('template_id_error','Template does not exist.');
returnfalse;
}
$tmp=$app->db->queryOneRecord("SELECT ostemplate_id FROM openvz_ostemplate WHERE ostemplate_id = $ostemplate_id");
if(!is_array($tmp)){
$this->server->fault('ostemplate_id_error','OSTemplate does not exist.');
returnfalse;
}
//* Get the template
$vtpl=$app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = $template_id");
//* Get the IP address and server_id
if($override_params['server_id']>0){
$vmip=$app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 AND server_id = ".$override_params['server_id']." LIMIT 0,1");
}else{
$vmip=$app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 LIMIT 0,1");
}
if(!is_array($vmip)){
$this->server->fault('vm_ip_error','Unable to get a free VM IP.');