Softlayer API:需要php示例才能验证高级监控(Nimsoft)的订单

时间:2015-12-18 15:21:48

标签: php api ibm-cloud-infrastructure

有人可以提供PHP示例代码来订购高级监控包 - 高级应用程序吗?

感谢。

1 个答案:

答案 0 :(得分:1)

这是订购监控的示例

<?php
/**
 * Example to order a portal monitoring
 *
 * Important manual pages:
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Monitoring_Package
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
 *
 * License <http://sldn.softlayer.com/article/License>
 * Author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 *
 */
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');

# Your SoftLayer API username and key.
$username = 'set me';
$key = 'set me';


$prices = array
(
    # This is the price for Monitoring Package - Premium Application
    2304,
);

# Converting our item list into an array of skeleton
# SoftLayer_Product_Item_Price objects. These objects contain much more than
# ids, but SoftLayer's ordering system only needs the price's id to know what
# you want to order.
$orderPrices = array();

foreach ($prices as $priceId){
    $price = new stdClass();
    $price->id = $priceId;
    $orderPrices[] = $price;
}


$packageId = 0;  # The packageId for order monitoring packages is 0
$quantity = 0;   
$sendQuoteEmailFlag = false;
$useHourlyPricing = true;


# Building a skeleton SoftLayer_Virtual_Guest object to model the Id
# of the virtual guest where you want add the monitoring package
$virtualGuests = new stdClass();
$virtualGuests->id = 13106845;
$orderVirtualGuest = array
(
    $virtualGuests
);

$configurationTemplateGroups = new stdClass();
$configurationTemplateGroups->id = 41; # Premiun Monitoring Package - Linux
$orderConfigurationTemplateGroups = array
(
    $configurationTemplateGroups
);



# Build a SoftLayer_Container_Product_Order_Monitoring_Package object containing
# the order you wish to place.
$orderContainer = new stdClass();
$orderContainer->packageId          = $packageId;
$orderContainer->prices             = $orderPrices;
$orderContainer->quantity           = $quantity;
$orderContainer->sendQuoteEmailFlag = $sendQuoteEmailFlag;
$orderContainer->useHourlyPricing   = $useHourlyPricing;
$orderContainer->virtualGuests      = $orderVirtualGuest;
$orderContainer->configurationTemplateGroups      = $orderConfigurationTemplateGroups;

# Create a SoftLayer API client object
$softLayer_product_order = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $key);

# Place the order for the new server.
try {
    # Re-declare the order template as a SOAP variable, so the SoftLayer
    # ordering system knows what type of order you're placing.
    $orderTemplate = new SoapVar
    (
        $orderContainer,
        SOAP_ENC_OBJECT,
        'SoftLayer_Container_Product_Order_Monitoring_Package',
        'http://api.service.softlayer.com/soap/v3/'
    );

    /**
     * verifyOrder() will check your order for errors. Replace this with a call
     * to placeOrder() when you're ready to order. Both calls return a receipt
     * object that you can use for your records.
     *
     * Once your order is placed it'll go through SoftLayer's approval and
     * provisioning process. When it's done you'll have a new
     * item ready to use.
     */
    $receipt = $softLayer_product_order->verifyOrder($orderTemplate);
    print_r($receipt);
} catch (Exception $e) {
    echo 'Unable to place monitoring order: ' . $e->getMessage();
}

要获得有效的商品价格ID,以下REST请求可以为您提供帮助:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/0/getItemPrices?objectMask=mask[id,categories,locationGroupId,item[id,keyName,description],pricingLocationGroup[locations[id, name, longName]]]&objectFilter={   "itemPrices": {     "categories": {       "categoryCode": {         "operation": "monitoring_package"       }     }   } }