使用WHM/cPanel创建SoftLayer Virtual_Guest



我正在尝试在软件层上使用WHM/cPanel创建虚拟服务器

不幸的是,Softlayer API不支持代码示例,任何API调用都将在我的帐户上产生费用。

服务generateOrderTemplate将不会验证,而仅验证必需的参数。

以下代码有什么问题?

try {
$client = librariesSoftLayerSoapClient::getClient('SoftLayer_Virtual_Guest', null, $apiUsername, $apiKey);
}   catch (Exception $e) {
die('Unable to create service client: ' . $e->getMessage());
}
try {
$virtualGuest = new stdClass();
$virtualGuest->datacenter->name = 'ams01';
$virtualGuest->hostname = 'test';
$virtualGuest->domain = 'myDomain.com';
$virtualGuest->startCpus = 1;
$virtualGuest->maxMemory = 1024;
$virtualGuest->hourlyBillingFlag = false;
$virtualGuest->localDiskFlag = true;
$virtualGuest->operatingSystemReferenceCode = 'CENTOS_7_64';
$virtualGuest->softwareComponents[0]->softwareDescription->id = 46;
$virtualGuest->softwareComponents[0]->softwareDescription->controlPanel = 1;
$virtualGuest->softwareComponents[0]->softwareDescription->virtualLicense = 1;
$virtualGuest->softwareComponents[0]->softwareDescription->manufacturer = "cPanel";
$virtualGuest->blockDevices[0]->device = 0;
$virtualGuest->blockDevices[0]->diskImage->capacity = 25;
$call = $client->generateOrderTemplate($virtualGuest);
$call = $client->createObject($virtualGuest);
print_r($call);
} catch (Exception $e) {
die('Unable to create Virtual Guest: ' . $e->getMessage());
}

感谢

不幸的是,无法使用SoftLayer_Virtual_Guest::createObject设置软件组件,此方法提供了一种简化的vsi排序方式(因此它只提供了最常见的选项。换句话说,generateOrderTemplate将验证与SoftLayer_Virtual_Guest:createObject方法相同的选项),要获得适用于此方法的所有选项,您需要使用以下方法:

  • SoftLayer_Virtual_Guest::getCreateObjectOptions

如果您希望为VSI订购控制面板软件,您需要在SoftLayer_Virtual_Guest::generateOrderTemplate 的结果中添加此项目的价格

要查找控制面板软件的priceId,您可以调用SoftLayer_Product_Package::getItemPrices,我可以提供一个脚本来帮助查找该软件的价格:

<?php
/**
* Get item prices(Standard) for Control Panel Software from specific package
*
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
* @see http://sldn.softlayer.com/article/object-filters
* 
* @license <http://sldn.softlayer.com/wiki/index.php/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
require_once 'vendorautoload.php';
// Define you SoftLayer's username and apiKey
$apiUsername = 'set me';
$apiKey = 'set me';
// Define the package
$packageId = 46;
// Create a SoftLayer API client object to the "SoftLayer_Product_Package" service
$client = SoftLayerSoapClient::getClient('SoftLayer_Product_Package', $packageId, $apiUsername, $apiKey);
// Declare an object filter to get Standard - Control Panel Software item prices 
$filter = new stdClass();
$filter->itemPrices = new stdClass();
$filter->itemPrices->item = new stdClass();
$filter->itemPrices->item -> categories = new stdClass();
$filter->itemPrices->item -> categories -> name = new stdClass();
$filter->itemPrices->item -> categories -> name -> operation = 'Control Panel Software';
$filter->itemPrices -> locationGroupId = new stdClass();
$filter->itemPrices -> locationGroupId -> operation = "is null";
$client->setObjectFilter($filter);
try{
foreach($client->getItemPrices() as $price){
print_r("PriceId:  " . $price -> id . "    ItemId: ". $price -> itemId . "   Description:  " . $price -> item -> description ."n");    
}
} catch (Exception $e) {
var_dump($e -> getMessage());
}
?>

我希望它能有所帮助,如果你需要的进一步帮助,请告诉我

最新更新