使用WHM / cPanel创建SoftLayer Virtual_Guest

时间:2017-01-24 18:49:55

标签: ibm-cloud-infrastructure

我正在尝试使用Softlayer上的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());
    }

由于

1 个答案:

答案 0 :(得分:0)

遗憾的是,无法使用SoftLayer_Virtual_Guest::createObject设置 softwareComponents ,此方法提供了一种简单的方式来订购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. <sldn@softlayer.com>
 */
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());
}

?>

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