SoftLayer API:寻找PHP示例代码来订购子网“Portable Public IPv6”和“Global IPv6”

时间:2015-11-19 22:21:13

标签: php ibm-cloud-infrastructure

  1. 我发现以下Softlayer API不会返回子网global_ipv6和global_ipv4的类别值:
  2. https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/0/getCategories

    我想知道为什么上面的查询结果不包含global_ipv6 / global_ipv4?

    1. 有人可以提供一些php示例代码来订购子网Portable Public IPv6“64_BLOCK_PORTABLE_PUBLIC_IPV6_ADDRESSES”和“GLOBAL_IPV6”设备吗?

    2. SoftLayer_Network_Vlan中有以下属性: primarySubnet primarySubnetVersion6]

    3. IPV6 Vlan在primarySubnetVersion6中是否只有属性值而不是primarySubnet?

      谢谢

1 个答案:

答案 0 :(得分:0)

订购新的全球IPv4 / IPv6子网的示例:

<?php
/**
 * Order a new Global IPv4/IPv6 subnet
 *
 * Important manual pages:
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder/
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Subnet
 * http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet
 *
 * @license <http://sldn.softlayer.com/wiki/index.php/License>
 * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 */

require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');

/**
 * Set your SoftLayer API username and key.
 */
$apiUsername = 'set me';
$apiKey = 'set me';

/**
 * Set the service to use
 */
$serviceName ='SoftLayer_Product_Order';

/**
 * The number of subnets you want to order
 *
 * @var int;
 */
$quantity = 1;

$packageId = 0;
$packageService ='SoftLayer_Product_Package';
$orderService ='SoftLayer_Product_Order';

/**
 * Create a client to the API services to use.
 */
$packageClient = SoftLayer_SoapClient::getClient($packageService, $packageId, $apiUsername, $apiKey);
$orderClient = SoftLayer_SoapClient::getClient($orderService, null, $apiUsername, $apiKey);

/**
 * Declaring an object filter to get specific subnet type to order e.g. GLOBAL_IPV6, GLOBAL_IPV4
 */
$filter = new stdClass();
$filter->itemPrices = new stdClass();
$filter->itemPrices->item = new stdClass();
$filter->itemPrices->item->keyName = new stdClass();
$filter->itemPrices->item->keyName->operation = new stdClass();
$filter->itemPrices->item->keyName->operation = "GLOBAL_IPV6";

try {

    $packageClient->setObjectFilter($filter);
    $packageResult = $packageClient->getItemPrices();
    print_r($packageResult);

    /**
     * Get the price ID
     */
    $priceId = $packageResult[0]->id;

    $orderTemplate = new stdClass();
    $orderTemplate->packageId           = $packageId;
    $orderTemplate->prices              = array();
    $orderTemplate->prices[0]           = new stdClass();
    $orderTemplate->prices[0]->id       = $priceId;
    $orderTemplate->quantity            = $quantity;

    // Create a SoftLayer API client object to the SoftLayer_Product_Order service.
    $orderClient = SoftLayer_SoapClient::getClient
        (
            'SoftLayer_Product_Order',
            null,
            $apiUsername,
            $apiKey
        );

    /**
     * Place the order for the new subnet.
     */
    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
        (
            $orderTemplate,
            SOAP_ENC_OBJECT,
            'SoftLayer_Container_Product_Order_Network_Subnet',
            'http://api.service.softlayer.com/soap/v3/'
        );

        $receipt = $orderClient->verifyOrder($orderTemplate);
        print_r($receipt);
    } catch (Exception $e) {
        echo 'Unable to place subnet order: ' . $e->getMessage();
    }

} catch (Exception $e) {
    echo 'Failed ... Unable to get the item prices: ' . $e->getMessage();
}

订购新的公共静态IPv6的示例:

<?php
/**
 * Order a new Public Static IPv6.
 *
 * Important manual pages:
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
 * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder/
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Subnet
 *
 * @license <http://sldn.softlayer.com/wiki/index.php/License>
 * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 */
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');

/**
 * Set your SoftLayer API username and key.
 */
$apiUsername = 'set me';
$apiKey = 'set me';

/**
 * Set the service to use
 */
$serviceName ='SoftLayer_Product_Order';

$priceId =  1481;

/**
 * The id of the IP address that you want to route a static subnet to.
 *
 * @var int
 */
$endPointIpAddressId = 18263116;

/**
 * The number of subnets you want to order
 *
 * @var int;
 */
$quantity = 1;

/**
 * Build a SoftLayer_Container_Product_Order_Network_Subnet object containing
 * the order you wish to place. Subnet's don't have a package, so set packageId
 * to 0. Since this order is for one item with no sub-options you only have to
 * set a single price id in this order.
 */
$orderTemplate = new stdClass();
$orderTemplate->packageId           = 0;
$orderTemplate->prices              = array();
$orderTemplate->prices[0]           = new stdClass();
$orderTemplate->prices[0]->id       = $priceId;
$orderTemplate->endPointIpAddressId = $endPointIpAddressId;
$orderTemplate->quantity            = $quantity;

/**
 * Create a client to the API service.
 */
$client = SoftLayer_SoapClient::getClient($serviceName, null, $apiUsername, $apiKey);

/**
 * Create a SoftLayer API client object to the SoftLayer_Product_Order service.
 */
$client = SoftLayer_SoapClient::getClient
    (
        'SoftLayer_Product_Order',
        null,
        $apiUsername,
        $apiKey
    );

/**
 * Place the order for the new subnet.
 */
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
    (
        $orderTemplate,
        SOAP_ENC_OBJECT,
        'SoftLayer_Container_Product_Order_Network_Subnet',
        '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
     * SoftLayer_Network_Subnet object ready to use.
     */
    $receipt = $client->verifyOrder($orderTemplate);
    print_r($receipt);
} catch (Exception $e) {
    echo 'Unable to place subnet order: ' . $e->getMessage();
}

要获得有效的商品价格ID,请执行:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/0/getItemPrices?objectMask=mask[id,item[keyName,description],locationGroupId ,pricingLocationGroup[locations[id, name, longName]]]