示例#1
0
文件: booton.php 项目: suzizi/xvp
function setup()
{
    global $poolname, $vmname, $jsvmname;
    global $stage, $hostname, $htvmname, $home, $hosts, $bootrecovery;
    global $session, $ref, $href;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    $hosts = $ref = $href = false;
    if (!($pool = xvp_config_pool_by_name($poolname)) || !($vm = xvp_config_vm_by_name($pool, $vmname))) {
        return;
    }
    if (($session = xenapi_login($pool, $master_ref)) === false) {
        return;
    }
    if (xvp_is_uuid($vmname)) {
        if (($ref = xenapi_vm_by_uuid($session, $vmname)) === false || ($label = xenapi_vm_get_name_label($session, $ref)) === false) {
            return;
        }
        $vm->uuid = $vm->vmname;
        $htvmname = htmlspecialchars($label);
        if ($stage == 2) {
            $jsvmname = addslashes($label);
        }
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        } else {
            $htvmname = htmlspecialchars($vmname);
        }
    }
    if (!xvp_db_user_may_perform($vm, null, "booton")) {
        return;
    }
    $bootrecovery = xvp_db_user_may_perform($vm, null, "bootrecovery");
    switch ($stage) {
        case 1:
            if (($aff = xenapi_vm_get_affinity($session, $ref)) !== false) {
                $home = xenapi_host_get_name_label($session, $aff);
            } else {
                $home = "";
            }
            if (($ph = xenapi_vm_get_possible_hosts($session, $ref)) === false) {
                return;
            }
            $hosts = array();
            foreach ($ph as $href) {
                $name = xenapi_host_get_name_label($session, $href);
                if ($name !== false) {
                    $hosts[$href] = $name;
                }
            }
            asort($hosts);
            break;
        case 2:
            $href = xenapi_host_by_name($session, $hostname);
            break;
    }
}
示例#2
0
文件: update.php 项目: suzizi/xvp
function host_update($pool, $host, $session, $master_ref)
{
    if ($host->address !== false) {
        $shortname = $host->hostname;
        $longname = $shortname . $pool->domainname;
    } else {
        if ($host->hostname_is_ip) {
            if (($longname = gethostbyaddr($host->hostname)) == $host->hostname) {
                $shortname = $longname;
            } else {
                if (strstr($longname, $pool->domainname)) {
                    $shortname = str_replace($pool->domainname, "", $longname);
                } else {
                    if (strstr($longname, ".")) {
                        $shortname = $longname;
                    } else {
                        $shortname = $longname;
                        $longname .= $pool->domainname;
                    }
                }
            }
        } else {
            $shortname = $host->hostname;
            $longname = $shortname . $pool->domainname;
        }
    }
    // try both FQDN and non-FQDN host names
    if (($ref = xenapi_host_by_name($session, $longname)) === false && ($shortname == $longname || ($ref = xenapi_host_by_name($session, $shortname)) === false)) {
        return;
    }
    if (!xenapi_host_get_enabled($session, $ref)) {
        return;
    }
    if (($mem = xenapi_host_compute_free_memory($session, $ref)) === false) {
        return;
    }
    $host->memory_free = sprintf("%.1f", $mem / (1024 * 1024 * 1024));
    if (($host->metrics = xenapi_host_get_metrics($session, $ref)) === false) {
        return;
    }
    if (($mem = xenapi_host_get_memory_total($session, $host->metrics)) > 0) {
        $host->memory_total = sprintf("%.1f", $mem / (1024 * 1024 * 1024));
    }
    if ($ref == $master_ref) {
        $host->is_master = true;
    }
    $osversion = xenapi_host_get_software_version($session, $ref);
    if ($osversion !== false) {
        $host->os_version = $osversion;
    }
    $host->state = "Running";
}