function send_unsuspension_email($var)
{
    $server = $var["params"]["domain"];
    lg_info("Sent unsuspension mail to " . $var["params"]["clientsdetails"]);
    $command = "sendemail";
    $adminuser = "******";
    $values["customtype"] = "product";
    $values["customsubject"] = "Service reactivated successfully";
    $values["custommessage"] = "Dear Customer,\n\nyour server {$server} has just been reactivated successfully.\n\nRegards,\nYour Support Team";
    $values["id"] = $var["params"]["serviceid"];
    $results = localAPI($command, $values, $adminuser);
}
function nocprovisioning_UnsuspendAccount($params)
{
    global $nocps_password;
    $q = mysql_query("UPDATE tblhosting set domainstatus=\"Active\" WHERE id=\"" . $params['serviceid'] . "\"");
    $query = mysql_result($q);
    $ip = nocprovisioning_getServerIPblub($params['serviceid']);
    $api = nocprovisioning_api($params);
    $mac = $api->getServerByIP($ip);
    $result = "";
    $password = "******";
    $method = "auto";
    $result = $api->powercontrol($mac, 'on', $password, $method);
    lg_info("Server {$ip} unsuspended(powered on)");
    nocprovisioning_log("Power management action 'on' - {$result} - MAC {$mac}", $params);
    return "success";
}
function nocps_define_citrix_vm($nocps_api, $vm_name, $vm_description, $ram_amount, $disk_size, $vcore_count)
{
    # ram_mount = needed ram in MB
    # disk_size = needed disk_size in MB
    $servers = nocps_get_citrix_servers($nocps_api);
    $target_server = "";
    foreach ($servers as $index => $data) {
        $free_ram = nocps_get_free_ram($nocps_api, $data["id"], $data["servername"], $data["address"]);
        $free_disk_space = nocps_get_free_disk_space($nocps_api, $data["id"], $data["servername"], $data["address"]);
        $total_cores = nocps_get_core_count($nocps_api, $data["id"], $data["servername"], $data["address"]);
        lg_debug("free_ram        of server: {$free_ram}        reqd ram:        {$ram_amount}");
        lg_debug("free_disk space of server: {$free_disk_space} reqd disk space: {$disk_size}");
        if ($free_ram >= $ram_amount and $free_disk_space >= $disk_size and $total_cores >= $vcore_count) {
            lg_info("Got Server " . $data["servername"] . " for new VM {$vm_name} with {$ram_amount} MB RAM, {$disk_size} MB Disk size and {$vcore_count} VCores");
            $target_server = $data;
            break;
        }
    }
    if ($target_server) {
        $ip = nocps_get_free_ip_address($nocps_api);
        if ($ip[0] == "No IPs avalable") {
            lg_err("No IPs available in NOC-PS");
            return "No IPs available";
        } else {
            $subnet = $ip[1];
            $ip = $ip[0];
            lg_info("Got new IP address {$ip}");
            lg_debug("Creating new VM");
            lg_debug2("Subnet: {$subnet}");
            lg_debug2("ip: {$ip}");
            lg_debug2("vm_name: {$vm_name}");
            lg_debug2("vm_description: {$vm_description}");
            lg_debug2("module: " . $target_server["id"]);
            lg_debug2("memory: {$ram_amount}");
            lg_debug2("disk_size: {$disk_size}");
            lg_debug2("network: " . nocps_get_citrix_first_nic($nocps_api, $target_server["id"]));
            try {
                $result = $nocps_api->addVM(array("subnet" => $subnet, "ip" => $ip, "numips" => 1, "hostname" => $vm_name, "description" => $vm_description, "module" => $target_server["id"], "memory" => $ram_amount, "disk" => $disk_size, "diskstore" => "Local storage", "network" => nocps_get_citrix_first_nic($nocps_api, $target_server["id"])));
            } catch (exception $e) {
                lg_err("Error from XenServer while creating new VM, Please check xensource.log");
                return "Error: from XenServer while Creating VM";
            }
        }
        if (is_array($result) and $result["success"] == "1") {
            $mac = $result["mac"];
            lg_info("VM-Setup Phase 1 - successful");
            if ($vcore_count > 1) {
                citrix_set_vcore_count($target_server["servername"], $vm_name, $vcore_count);
            }
            return "NEWIP {$ip}";
        } else {
            lg_err("VM-Setup failed, unknown error");
            lg_err("success: " . $result["success"]);
            $lines = print_r($result, true);
            if (is_array($lines)) {
                foreach ($lines as $ind => $text) {
                    lg_info($ind . " " . $text);
                }
            }
            return "Error: VM Setup Failed, unknown Error";
        }
    } else {
        lg_err("VM-Setup failed, No Server with enough resources for this VM available");
        return "Error: No Server has enough resources for this VM";
    }
}