PHP code example of macromindonline / xenapi

1. Go to this page and download the library: Download macromindonline/xenapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

macromindonline / xenapi example snippets


"sircamp/xenapi": "2.1"

use Sircamp\Xenapi\Xen as Xen;

$ip = "123.123.123.123";
$user = "username";
$password = "password";
$xen = new Xen($ip,$user,$password); //OK now you have an open connection to Hypervisor

$vm = $xen->getVMByNameLabel("virtual.machine.hostaname");

$vm->start(); 

$pause = true; // start VM in pause status , dafault is false
$force = true; // force the boot of VM, default is true
$vm->start($pause, $force); 

$host // this is a XenHost object istance or a string istance
$hostRef = $host;
$pause = true; // start VM in pause status , dafault is false
$force = true; // force the boot of VM, default is true
$vm->startOn($hostRef,$pause, $force); 

$vm->cleanShutdown(); 

$vm->hardShutdown(); 

$vm->cleanShutdown(); 

$vm->hardShutdown(); 

$vm->suspend(); 

$vm->resume(); 

$host // this is a XenHost object istance or a string istance
$hostRef = $host;
$vm->resumeOn($hostRef); 

$vm->pause(); 

$vm->unpause(); 

$name = "new_cloned_vm"; // name of cloned vm
$vm->cleanShudown(); // stop  vm
$vm->clonevm($name); 

$vm->getPowerState();

$vm->powerStateReset();

$vm->getUUID();

$vm->getConsoles()

$vm->getConsoleUUID($console)

$vm->getGuestMetrics()

$vm->getMetrics()

$vm->getStats()

$vm->getDiskSpace()

$format = "GB";
$vm->getDiskSpace($format);

$vm->getName()

$vm->getAll()

$optionsMap = array(
	'option1' => "option first",
	'option2' => "option second"
)
$host // this is a XenHost object istance or a string istance
$hostRef = $host;
$vm->poolMigrate($refHost, $optionsMap);

$dest // Host.migrate call result
$vdiMap //map of source VDI
$vifMap //map of source VFI
$options = array(
	'option1' => "option first",
	'option2' => "option second"
);
$live = true;
$vm->migrateSend($dest,$vdiMap,$vifMap,$options,$live)

$dest // Host.migrate call result
$vdiMap //map of source VDI
$vifMap //map of source VFI
$options = array(
	'option1' => "option first",
	'option2' => "option second"
);
$live = true;
$vm->assertCanMigrate($dest,$vdiMap,$vifMap,$options,$live)

$name = "name of snapshot";
$vm->snapshot($name)

$name = "name of snapshot";
$vm->snapshotWithQuiesce($name)

$vm->getSnapshotInfo()

$snapshotID // the snaoshot id
$vm->revert($snapshotID)

$name = "nameOfCopy";
$vm->copy($name);

$vm->destroy();

$name = "nameOfVM";
$vm->checkpoint($name);

$seconds = 5;
$vm->setStartDelay($seconds);

$seconds = 5;
$vm->setShutdownDelay($seconds);

$vm->getStartDelay();

$vm->getShutdownDelay();

$vm->getCurrentOperations();

$vm->getAllowedOperations();

$vm->getNameDescription();

$description = "description";
$vm->setNameDescription($description);

$vm->getIsATemplate();

$template = false;
$vm->setIsATemplate($template);

$vm->getResidentOn();

$vm->getPlatform();

$array = array(
	'data'=>'value',
	'data2'=>'value'
);
$vm->setPlatform($array);

$vm->getOtherConfig();

$array = array(
	'config'=>'value',
	'config2'=>'value'
);
$vm->setOtherConfig($array);

$key = "key";
$value = "value"

$vm->addToOtherConfig($key, value);

$key = "key";
$value = "value"

$vm->removeFromOtherConfig($key);

$vm->getNameLabel();

$host = $xen->getHOSTByNameLabel("host.machine.hostaname");

$host->disable()

$host->enable()

$host->shutdown()

$host->reboot()

$host->dmesg()

$host->dmesgClear()

$host->getLog()

$host->listMethods()

$file = file_get_contents("/path/license/file");
$license = base64_encode($file);
$host->licenseApply($license)

$host->assertCanEvacuate()

$host->evacuate()

$host->getServertime()

$host->getServerLocaltime()

$host->getServerCertificate()

$edition = "newedition";
$force = true;
$host->getServerCertificate()

$host->refreshPackInfo()

$srRef = "srReferID";
$host->enableLocalStorageCaching($srRef);

$host->disableLocalStorageCaching();

$networkRef = "networkRef" // shorty you can pass the obeject that map network
$features = array(
	'options1'=>"youroption",
	'options2'=>"youroption",
);
$host->migrateReceive($networkRef, $features);

$host->getUUID()

$host->getNameLabel()

$name = "server.yourname.com";
$host->setNameLabel($name);

$host->getNameDescription()

$description = "long long text";
$host->setNameDescription($description)

$description = "long long text";
$host->setNameDescription($description)

$host->getAllowedOperations()

$host->getSoftwareVersion()

$host->getOtherConfig()

$config = array(
	'config1' => "first config",
	'config2' => "second config"
);
$host->setOtherConfig($config)

$key = "config1";
$value = "first config";
$host->addOtherConfig($key,$value)

$key = "config1";
$host->removeOtherConfig($key)

$host->getSupportedBootloaders()

$host->getResidentVMs()

$host->getPatches()

$host->getHostCPUs()

$host->getCPUInfo()

$host->getHostname()

$name = "new.hostname.com"
$host->setHostname($name);

$host->getAddress()

$address = "123.123.123.123"
$host->setAddress($address);

$host->getMetrics()

$host->getLicenseParam()
php
$host->getEdition()
php
$host->getLicenseServer()
php
$license = "newlicense"
$host->setLicenseServer($license);
php
$key = "licenseName";
$value = "licenseValue";
$host->addToLicenseServer($key,$value);
php
$key = "licenseName";
$host->removeFromLicenseServer($key);
php
$host->getChipsetInfo()
php
$response = $vm->hardReboot();
$response->getValue();
php
$response = $vm->hardReboot();
$response->getStatus();
php
$console = "wrong_console";
$response = $vm->getConsolesUUID($console);
$response->getStatus(); //return Failure
$response->getErrorDescription(); // return an array with some error message
php
use Sircamp\Xenapi\Exception\XenConnectionException as XenConnectionException;