試試下面的PHP腳本,它可以幫助我們得到可用的軟件包及其物品的圖像模板,
<?php
/**
* Get packages and items from an image template
*
* This script retrieves packages in which the image template could be used,
* also It retrieves the items available for the image per package.
*
* Important manual pages:
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getAvailablePackagesForImageTemplate
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemsFromImageTemplate
*
* License: http://sldn.softlayer.com/article/License
* Author: SoftLayer Technologies, Inc. <[email protected]>
*/
require_once __DIR__."SoapClient.php";
# Your SoftLayer username and apikey
$username = "set me";
$apiKey = "set me";
# The image template which you wish more details
$imageTemplateId = 429428;
# Creating a SoftLayer API client object
$packageService = \SoftLayer\SoapClient::getClient("SoftLayer_Product_Package", null, $username, $apiKey);
/*
* Build a skeleton SoftLayer_Virtual_Guest_Block_Device_Template_Group object to define the image template id
*/
$imageTemplate = new \stdClass();
$imageTemplate -> id = $imageTemplateId;
try {
// Get available packages for the image template
$packages = $packageService -> getAvailablePackagesForImageTemplate($imageTemplate);
foreach ($packages as $package)
{
// Set init parameters per available package
$packageService -> setInitParameter($package->id);
// Print available package
print_r("**** PACKAGE: " . $package->id . " ****\n");
// Get items per package
$items = $packageService -> getItemsFromImageTemplate($imageTemplate);
print_r($items);
}
} catch (Exception $e) {
die("Unable to get packages and items for the image template. " . $e->getMessage());
}
?>
參考文獻: 的SoftLayer API PHP客戶端:https://github.com/softlayer/softlayer-api-php-client
作爲一個例子,假設我有一個帶有1GB內存,20GB磁盤空間和Ubuntu操作系統的虛擬服務器。我從中創建了一個圖像模板。 當我嘗試使用此映像模板來訂購虛擬服務器時,應將虛擬服務器選項預設爲1GB RAM,20GB磁盤空間和Ubuntu OS。 而這些配置信息必須存儲在圖像模板中的某些地方。 那麼我可以使用哪些API來告訴我圖像模板的所有配置信息,如 1GB內存,20GB磁盤空間,Ubuntu操作系統等。 – KHP