Exemple #1
0
if (count($_SERVER['argv']) != 6) {
    echo 'Usage: php ' . $_SERVER['argv'][0] . ' <host> <username> <password> <command> <vmname>
       command      poweron, poweroff, shutdown, suspend, reboot or reset
       vmname       the name of the virtual machine
';
    exit;
}
require_once dirname(__FILE__) . '/../class_esx.php';
try {
    $esx = new esx();
    $esx->connect($_SERVER['argv'][1], $_SERVER['argv'][2], $_SERVER['argv'][3]);
    $vm = $esx->find_entity_view('VirtualMachine', null, array('config.name' => $_SERVER['argv'][5]));
    $task = null;
    switch ($_SERVER['argv'][4]) {
        case 'poweron':
            $task = $esx->PowerOnVM_Task(array('_this' => $vm));
            break;
        case 'poweroff':
            $task = $esx->PowerOffVM_Task(array('_this' => $vm));
            break;
        case 'shutdown':
            $esx->ShutdownGuest(array('_this' => $vm));
            break;
        case 'suspend':
            $task = $esx->SuspendVM_Task(array('_this' => $vm));
            break;
        case 'reboot':
            $esx->RebootGuest(array('_this' => $vm));
        case 'reset':
            $task = $esx->ResetVM_Task(array('_this' => $vm));
            break;