Пример #1
1
 /** Crawl a Xen pool master and return an array of servers and their specs
 		@param	host		The hostname of the Xen pool master to crawl
 		@param	login		The username to connect to XAPI with
 		@param	password	The password to connect with. Not sent via HTTPS, so use caution.
 		@returns	Array of servers with named values of key metrics, see src for more.
 	*/
 function crawl($host, $login, $password)
 {
     // Connect to Xen
     $xenserver = new XenApi("http://" . $host, $login, $password);
     // Get a reference to each VM
     $vmRefList = $xenserver->VM_get_all();
     // Create our final array
     $vmArray = array();
     // Get the pool name
     $poolRef = $xenserver->pool_get_all();
     $vmArray['name'] = $xenserver->pool_get_name_label($poolRef[0]);
     // Query server about each VM reference
     foreach ($vmRefList as $vm) {
         $record = $xenserver->VM_get_record($vm);
         // Server is powered on, and is NOT a control domain
         if ($record['power_state'] == 'Running' && $record['is_control_domain'] == '') {
             // Create the info array
             $vmInfo = array("name" => $record['name_label'], "description" => $record['name_description'], "vmuuid" => $record['uuid']);
             // Does the record have a metrics reference?
             if (!strstr($record['guest_metrics'], "NULL")) {
                 // Get the OS version
                 $os = $xenserver->VM_guest_metrics_get_os_version($record['guest_metrics']);
                 $vmInfo['ostype'] = $os['name'];
                 // Get the IP address
                 $network = $xenserver->VM_guest_metrics_get_networks($record['guest_metrics']);
                 $vmInfo['ip'] = $network['0/ip'];
             }
             // Add it to the array
             $vmArray['virtuals'][] = $vmInfo;
         }
     }
     return $vmArray;
 }
Пример #2
0
include 'xenapi.php';
$url = "https://10.0.0.1";
/* URL of the Citrix XenSerer Xapi */
$login = "******";
/* login/user for the citrix box */
$password = "******";
/* password for the user */
/* Establish session with Xenserver */
$xenserver = new XenApi($url, $login, $password);
/* Once sucessfully logged in - any method (valid or not) is passed to the XenServer.

Replace the first period (.) of the method with a underscore (_) - because PHP doesnt like 
periods in the function names.

All the methods (other then logging in) require passing the session_id as the first parameter,
however this is done automatically - so you do not need to pass it.

For example, to do VM.get_all(session_id) and get all the vms as an array, then get/print the details of each
using VM.get_record(session_id, self) (self = VM object):
 */
$vms_array = $xenserver->VM_get_all();
foreach ($vms_array as $vm) {
    $record = $xenserver->VM_get_record($vm);
    print_r($record);
}
/*
For parameters/usage, check out:
    http://docs.vmd.citrix.com/XenServer/5.5.0/1.0/en_gb/api/docs/html/browser.html
To see how parametes are returned, print_r() is your friend :)
*/