2017-01-24 32 views
1

我試圖創建WHM /的cPanel對SoftLayer的虛擬服務器,創建的SoftLayer Virtual_Guest與WHM /的cPanel

不幸的是,SoftLayer的API不支持代碼示例和任何API調用會招致我的帳戶收費。

而服務generateOrderTemplate不會驗證,但只需要參數。

下面的代碼有什麼問題?

try { 
     $client = \libraries\SoftLayer\SoapClient::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()); 
    } 

感謝

回答

0

不幸的是,這是不可能的設置softwareComponents使用SoftLayer_Virtual_Guest::createObject,這種方法提供了一種簡化的方式來訂購VSI(所以它僅提供了最常用的選項吧。換句話說意味着generateOrderTemplate將驗證與SoftLayer_Virtual_Guest :: createObject方法相同的選項),以獲取適用於此方法的所有選項,您需要使用以下方法:

如果您想訂購控制面板軟件爲您的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. <[email protected]> 
*/ 
require_once '\vendor\autoload.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 = \SoftLayer\SoapClient::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()); 
} 

?> 

我希望它可以幫助,讓我知道如果您需要進一步的幫助

+0

感謝親,我會嘗試它(y) –