コード例 #1
0
ファイル: reset.php プロジェクト: suzizi/xvp
function main()
{
    global $poolname, $vmname, $jsvmname, $reset;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    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 || ($vmname = xenapi_vm_get_name_label($session, $ref)) === false) {
            return;
        }
        $vm->uuid = $vm->vmname;
        $vm->vmname = $vmname;
        $jsvmname = addslashes($vmname);
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        }
    }
    if (!xvp_db_user_may_perform($vm, null, "reset")) {
        return;
    }
    if (xenapi_vm_hard_reboot($session, $ref)) {
        $reset = "true";
    }
}
コード例 #2
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;
    }
}
コード例 #3
0
ファイル: shutdown.php プロジェクト: suzizi/xvp
function main()
{
    global $poolname, $vmname, $jsvmname, $shutdown;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    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 || ($vmname = xenapi_vm_get_name_label($session, $ref)) === false) {
            return;
        }
        $vm->uuid = $vm->vmname;
        $vm->vmname = $vmname;
        $jsvmname = addslashes($vmname);
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        }
    }
    if (!xvp_db_user_may_perform($vm, null, "shutdown")) {
        return;
    }
    $always = xenapi_vm_get_ha_always_run($session, $ref);
    if ($always === true) {
        // disable HA prior to shutdown
        xenapi_vm_set_ha_always_run($session, $ref, false);
    }
    if (xenapi_vm_shutdown($session, $ref)) {
        $shutdown = "true";
    } else {
        if ($always === true) {
            xenapi_vm_set_ha_always_run($session, $ref, true);
        }
    }
}
コード例 #4
0
ファイル: resume.php プロジェクト: suzizi/xvp
function main()
{
    global $poolname, $vmname, $jsvmname, $resumed;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    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 || ($vmname = xenapi_vm_get_name_label($session, $ref)) === false) {
            return;
        }
        $vm->uuid = $vm->vmname;
        $vm->vmname = $vmname;
        $jsvmname = addslashes($vmname);
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        }
    }
    if (!xvp_db_user_may_perform($vm, null, "resume")) {
        return;
    }
    $prio = xenapi_vm_get_restart_priority($session, $ref);
    $always = xenapi_vm_get_ha_always_run($session, $ref);
    if (xenapi_vm_resume($session, $ref)) {
        $resumed = "true";
        if (strlen($prio) > 0 && $always === false) {
            // looks like HA disabled for VM on suspend, so re-enable
            xenapi_vm_set_ha_always_run($session, $ref, true);
        }
    }
}
コード例 #5
0
ファイル: console.php プロジェクト: suzizi/xvp
function main()
{
    global $xvp_multiplex_vm, $xvp_otp_ipcheck;
    // Using REQUEST not POST, for easier integration with custom web pages
    $poolname = stripslashes($_REQUEST['poolname']);
    $vmname = stripslashes($_REQUEST['vmname']);
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    if (!($pool = xvp_config_pool_by_name($poolname)) || !($vm = xvp_config_vm_by_name($pool, $vmname))) {
        return;
    }
    if (xvp_is_uuid($vmname)) {
        $vm->uuid = $vm->vmname;
    }
    if (!xvp_db_user_may_perform($vm, null, "console")) {
        return;
    }
    $kbdmouse = xvp_db_user_may_perform($vm, null, "kbdmouse");
    if ($kbdmouse) {
        $readonly = "No";
        $controls = "Yes";
        $shutdown = xvp_db_user_may_perform($vm, null, "shutdown") ? "Yes" : "No";
        $reboot = xvp_db_user_may_perform($vm, null, "reboot") ? "Yes" : "No";
        $reset = xvp_db_user_may_perform($vm, null, "reset") ? "Yes" : "No";
    } else {
        $readonly = "Yes";
        $controls = $shutdown = $reboot = $reset = "No";
    }
    if (isset($xvp_multiplex_vm)) {
        $port = $xvp_multiplex_vm->port;
    } else {
        if ($vm->port != 0) {
            $port = $vm->port;
        } else {
            return;
        }
    }
    $user = isset($_SERVER['REMOTE_USER']) ? xvp_xmlescape($_SERVER['REMOTE_USER']) : "";
    $password = xvp_password_otp($vm->password);
    if (false) {
        /*
         * Target is a sequence of UTF-8 bytes, but Java applet could be
         * expecting any encoding, we just don't know, so we could pass
         * to it as printable hex: "UTF-8:xx:xx:xx:xx....xx", which
         * would also mean we don't want to xvp_xmlescape() it.
         *
         * Although xvpviewer >= 1.8.0 supports this encoding, I've not
         * found any browser/Java combinations that actually need it, so
         * I'm leaving this code disabled for now.
         * 
         */
        $target = $poolname . ":" . $vmname;
        $xvptarget = "UTF-8";
        for ($i = 0; $i < strlen($target); $i++) {
            $xvptarget .= sprintf(":%02x", ord($target[$i]));
        }
    } else {
        $xvptarget = xvp_xmlescape($poolname . ":" . $vmname);
    }
    echo <<<EOF1
<applet code="VncViewer.class" archive="VncViewer.jar">
  <param name="port" value="{$port}" />
  <param name="open new window" value="yes" />
  <param name="offer relogin" value="no" />
  <param name="user" value="{$user}" />
  <param name="vm" value="{$xvptarget}" />
  <param name="xvppassword" value="{$password}" />
  <param name="xvpshutdown" value="{$shutdown}" />
  <param name="xvpreboot" value="{$reboot}" />
  <param name="xvpreset" value="{$reset}" />
  <param name="read only" value="{$readonly}" />
  <param name="show controls" value="{$controls}" />
EOF1;
    if ($xvp_otp_ipcheck == XVP_IPCHECK_HTTP) {
        $proxyhost = $_SERVER['SERVER_NAME'];
        $proxyport = $_SERVER['SERVER_PORT'];
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
            $factory = "HTTPSConnectSocketFactory";
        } else {
            $factory = "HTTPConnectSocketFactory";
        }
        echo <<<EOF2

  <param name="proxyhost1" value="{$proxyhost}" />
  <param name="proxyport1" value="{$proxyport}" />
  <param name="socketfactory" value="{$factory}" />
EOF2;
    }
    echo <<<EOF3

</applet>

EOF3;
}
コード例 #6
0
ファイル: properties.php プロジェクト: suzizi/xvp
function main()
{
    global $poolname, $vmname, $htvmname, $description;
    global $ha, $vm, $state, $platform, $home, $where, $cpus;
    global $current_dvd_uuid, $current_dvd_name, $possible_dvds;
    global $dvd_change, $dvd_iso, $dvd_host, $dvd_uuid, $dvd_error;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    $platform = "blank";
    if (!($pool = xvp_config_pool_by_name($poolname)) || !($vm = xvp_config_vm_by_name($pool, $vmname))) {
        return;
    }
    if (!xvp_db_user_may_perform($vm, null, "properties")) {
        exit;
    }
    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);
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        } else {
            $htvmname = htmlspecialchars($vmname);
        }
    }
    $description = xenapi_vm_get_name_description($session, $ref);
    if ($description === false) {
        $description = "";
    } else {
        $description = htmlspecialchars($description);
    }
    $dvd_iso = xvp_db_user_may_perform($vm, null, "dvdiso");
    $dvd_host = xvp_db_user_may_perform($vm, null, "dvdhost");
    $dvd_change = $dvd_iso || $dvd_host;
    $prio = xenapi_vm_get_restart_priority($session, $ref);
    // 1 in older versions of XenServer seems to have become "restart" in
    // newer versions.  Based on Christian Scheele's patch of 23/07/2012.
    switch ($prio) {
        case 1:
        case "restart":
            $ha = "protected";
            break;
        case "best-effort":
            $ha = "restart if possible";
            break;
        default:
            $ha = "do not restart";
            break;
    }
    if (($aff = xenapi_vm_get_affinity($session, $ref)) !== false) {
        $home = xenapi_host_get_name_label($session, $aff);
    }
    if (($where = xenapi_vm_get_resident_on($session, $ref)) !== false) {
        $where = xenapi_host_get_name_label($session, $where);
    }
    $cpus = xenapi_vm_get_vcpus_max($session, $ref);
    // only handle 1st usable DVD drive found
    $current_dvd_name = null;
    $current_dvd_uuid = null;
    if (($vbds = xenapi_vm_get_vbds($session, $ref)) !== false) {
        foreach ($vbds as $vbd) {
            if (($vbd_rec = xenapi_vbd_get_record($session, $vbd)) === false || $vbd_rec["type"] != "CD") {
                continue;
            }
            if ($vbd_rec["empty"]) {
                $current_dvd_name = "<empty>";
                $current_dvd_uuid = "empty";
            } else {
                $vdi = $vbd_rec["VDI"];
                if (($vdi_rec = xenapi_vdi_get_record($session, $vdi)) === false) {
                    continue;
                }
                $current_dvd_name = $vdi_rec["name_label"];
                $current_dvd_uuid = $vdi_rec["uuid"];
            }
            break;
        }
    }
    $dvd_error = "";
    if ($dvd_change && isset($dvd_uuid) && $dvd_uuid != $current_dvd_uuid) {
        if ($dvd_uuid == "empty") {
            $changed = xenapi_vbd_eject($session, $vbd);
        } else {
            if ($dvd_uuid != $current_dvd_uuid) {
                if ($current_dvd_uuid != "empty") {
                    xenapi_vbd_eject($session, $vbd);
                }
                if ($vdi = xenapi_vdi_by_uuid($session, $dvd_uuid)) {
                    $changed = xenapi_vbd_insert($session, $vbd, $vdi);
                } else {
                    $changed = false;
                }
            }
        }
        if ($changed) {
            if (($current_dvd_uuid = $dvd_uuid) == "empty") {
                $current_dvd_name = "<empty>";
            } else {
                $current_dvd_name = xenapi_vdi_get_name_label($session, $vdi);
            }
        } else {
            $dvd_error = " !";
        }
    }
    $possible_dvds = array();
    $possible_dvds["empty"] = "<empty>";
    if (($srs = xenapi_sr_get_all($session)) !== false) {
        foreach ($srs as $sr) {
            // SR needs to be an ISO Library or a physical DVD drive
            if (($sr_rec = xenapi_sr_get_record($session, $sr)) === false || !isset($sr_rec["content_type"]) || $sr_rec["content_type"] != "iso") {
                continue;
            }
            if (($sr_host = sr_get_host_name($session, $sr_rec)) !== false) {
                // If SR on one host and VM running on another, we can't use SR
                if ($where !== false && $where != $sr_host) {
                    continue;
                }
                $sr_rec["name_label"] = $sr_host;
            }
            $vdicount = 0;
            $sr_dvds = array();
            foreach ($sr_rec["VDIs"] as $vdi) {
                $vdi = $vdi->scalarval();
                if (($vdi_rec = xenapi_vdi_get_record($session, $vdi)) === false) {
                    continue;
                }
                // nasty hack for XenServer Tools, which may have unwanted VDIs
                if ($sr_rec["name_label"] == "XenServer Tools" && $vdi_rec["name_label"] != "xs-tools.iso") {
                    continue;
                }
                // Bodge physical drive naming
                $vdi_display = $sr_host === false ? $vdi_rec["name_label"] : "DVD drive {$vdicount}";
                $sr_dvds[$vdi_rec["uuid"]] = $sr_rec["name_label"] . ": {$vdi_display}";
                $vdicount++;
            }
            if ($vdicount > 0) {
                natcasesort($sr_dvds);
                $possible_dvds = array_merge($possible_dvds, $sr_dvds);
            }
        }
    }
    $state = strtolower(xenapi_vm_get_power_state($session, $ref));
    $vm->metrics = xenapi_vm_get_metrics($session, $ref);
    if ($vm->metrics !== false) {
        if (($mem = xenapi_vm_get_memory_actual($session, $vm->metrics)) > 0) {
            $mem = $mem / (1024 * 1024);
            if ($mem >= 1024) {
                $vm->memory_total = sprintf("%.1f GB", $mem / 1024);
            } else {
                $vm->memory_total = sprintf("%d MB", $mem);
            }
        }
        if ($state == "running") {
            $vm->uptime = vm_uptime(xenapi_vm_get_start_time($session, $vm->metrics));
        }
    }
    if ($state != "running") {
        return;
    }
    $vm->guest_metrics = xenapi_vm_get_guest_metrics($session, $ref);
    if ($vm->guest_metrics !== false) {
        $osversion = xenapi_vm_get_os_version($session, $vm->guest_metrics);
        if ($osversion !== false) {
            $vm->os_version = $osversion;
        }
        $toolsversion = xenapi_vm_get_pv_drivers_version($session, $vm->guest_metrics);
        if ($toolsversion == false) {
            $vm->tools_info = "not installed";
        } else {
            $toolsuptodate = xenapi_vm_get_pv_drivers_up_to_date($session, $vm->guest_metrics);
            $vm->tools_info = sprintf("%s (%sup to date)", $toolsversion, $toolsuptodate ? "" : "not ");
        }
    }
    if (vm_os_windows($vm->os_version)) {
        $platform = "windows";
    } else {
        if (vm_os_linux($vm->os_version)) {
            $platform = "linux";
        }
    }
}
コード例 #7
0
ファイル: snapshot.php プロジェクト: suzizi/xvp
function main()
{
    global $poolname, $vmname, $htvmname;
    global $vm, $reason, $snapshot, $snapshots, $message;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    if (!($pool = xvp_config_pool_by_name($poolname)) || !($vm = xvp_config_vm_by_name($pool, $vmname))) {
        return;
    }
    if (!xvp_db_user_may_perform($vm, null, "snapshot")) {
        exit;
    }
    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);
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        } else {
            $htvmname = htmlspecialchars($vmname);
        }
    }
    switch ($reason) {
        case 'init':
            $message = "";
            break;
        case 'create':
            if (xenapi_vm_snapshot($session, $ref, $snapshot) !== false) {
                $message = "Successfully created snapshot";
            } else {
                $message = "Error creating snapshot";
            }
            break;
        case 'revert':
            if (xenapi_vm_revert($session, $snapshot) !== false) {
                $message = "Successfully reverted to snapshot";
            } else {
                $message = "Error reverting to snapshot";
            }
            break;
        case 'delete':
            // destroying VM will destroy its VBDs but not the underlying VDIs
            $delete_vdis = array();
            if (($vbds = xenapi_vm_get_vbds($session, $snapshot)) !== false) {
                foreach ($vbds as $vbd) {
                    if (($vbd_rec = xenapi_vbd_get_record($session, $vbd)) === false) {
                        continue;
                    }
                    if ($vbd_rec["type"] != "Disk") {
                        continue;
                    }
                    $vdi = $vbd_rec["VDI"];
                    if (($vdi_rec = xenapi_vdi_get_record($session, $vdi)) === false) {
                        continue;
                    }
                    if ($vdi_rec["is_a_snapshot"] && count($vdi_rec["VBDs"]) == 1) {
                        $delete_vdis[] = $vdi;
                    }
                }
            }
            if ($ok = xenapi_vm_destroy($session, $snapshot)) {
                foreach ($delete_vdis as $vdi) {
                    $ok &= xenapi_vdi_destroy($session, $vdi);
                }
            }
            if ($ok) {
                $message = "Successfully deleted snapshot";
            } else {
                $message = "Error deleting snapshot";
            }
            break;
    }
    $snapshots = array();
    $snaprefs = xenapi_vm_get_snapshots($session, $ref);
    foreach ($snaprefs as $snapref) {
        $snapname = xenapi_vm_get_name_label($session, $snapref);
        if ($snapname !== false) {
            $snapshots[$snapref] = $snapname;
        }
    }
}
コード例 #8
0
ファイル: boot.php プロジェクト: suzizi/xvp
function main()
{
    global $poolname, $vmname, $jsvmname, $booted, $recovery;
    xvp_global_init();
    xvp_config_init();
    xvp_db_init();
    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 || ($vmname = xenapi_vm_get_name_label($session, $ref)) === false) {
            return;
        }
        $vm->uuid = $vm->vmname;
        $vm->vmname = $vmname;
        $jsvmname = addslashes($vmname);
    } else {
        if (($ref = xenapi_vm_by_name($session, $vmname)) === false) {
            return;
        }
    }
    if (!xvp_db_user_may_perform($vm, null, "boot")) {
        return;
    }
    if ($recovery && !xvp_db_user_may_perform($vm, null, "bootrecovery")) {
        return;
    }
    if ($recovery) {
        /*
         * A recovery boot means using HVM, even if guest is PV, and
         * setting boot device order to CD/DVD drive and then network.
         * However, we must restore original settings immediately
         * after boot completes or fails.
         */
        $policy = xenapi_vm_get_hvm_boot_policy($session, $ref);
        $params = xenapi_vm_get_hvm_boot_params($session, $ref);
        if ($policy === false || $params === false) {
            return;
        }
        if (isset($params["order"])) {
            $order = $params["order"];
        } else {
            $order = "";
        }
        $params["order"] = "dn";
        if (!xenapi_vm_set_hvm_boot_params($session, $ref, $params)) {
            return;
        }
        if (!xenapi_vm_set_hvm_boot_policy($session, $ref, "BIOS order")) {
            $params["order"] = $order;
            xenapi_vm_set_hvm_boot_params($session, $ref, $params);
            return;
        }
    }
    $prio = xenapi_vm_get_restart_priority($session, $ref);
    $always = xenapi_vm_get_ha_always_run($session, $ref);
    if (xenapi_vm_start($session, $ref)) {
        $booted = "true";
        if (strlen($prio) > 0 && $always === false) {
            // looks like HA disabled for VM on shutdown, so re-enable
            xenapi_vm_set_ha_always_run($session, $ref, true);
        }
    }
    if ($recovery) {
        /*
         * Restore original HVM/PV and boot order settings.
         */
        xenapi_vm_set_hvm_boot_policy($session, $ref, $policy);
        $params["order"] = $order;
        xenapi_vm_set_hvm_boot_params($session, $ref, $params);
    }
}