试试下面的 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. <sldn@softlayer.com>
*/
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