SoftLayer API:用于取消网络产品的API方法,如Netscaler,负载均衡器,IpsecVPN,子网

For the following Network devices: Netscaler, Load balancing, IPSecVPN Subnet,

which is the right Softlayer API method to cancel these devices?

Is the "SoftLayer_Billing_Item::cancelService" the right one to cancel them with billingId?

http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelService

There's also a method in SoftLayer_ticket

SoftLayer_Ticket::createCancelServerTicket http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createCancelServerTicket

Is the SoftLayer_Ticket::createCancelServerTicket only for cancelling Bare Metal server using the bare metal server Id? Or can I use SoftLayer_Ticket::createCancelServerTicket to cancel network devices by providing a network device Id ?

Thanks.

Yes, SoftLayer_Billing_Item::cancelService should be used to cancel items like: Load balancer, iPsec VPN, Netscaler, etc., even “SoftLayer_Billing_Item::cancelItem” is other option to use.

However, http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createCancelServerTicket cannot be used for services (e.g. Network products), the SLDN document says that it should be used only for servers (bar metals)

Here are some examples to cancel services:

Cancel “IpSec VPN” using “cancelService”:

<?php
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
 */
$ipSecService ='SoftLayer_Network_Tunnel_Module_Context';
$billingItemService = 'SoftLayer_Billing_Item';

$ipSecId = 77;


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

$mask = new SoftLayer_ObjectMask();
$mask = 'mask[id,billingItem.id]';
$ipSecClient->setObjectMask($mask);

try {
       $ipSecItem = $ipSecClient->getObject();
    $billingItemId = $ipSecItem->billingItem->id; 
    print_r($billingItemId);


    try {
        $billingItemClient = SoftLayer_SoapClient::getClient($billingItemService, $billingItemId, $apiUsername, $apiKey, $endpointUrl);
        $result = $billingItemClient->cancelService();
        print_r($result);

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


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

Cancel “IpSec VPN” using “cancelItem”:

<?php
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
 */
$ipSecService ='SoftLayer_Network_Tunnel_Module_Context';
$billingItemService = 'SoftLayer_Billing_Item';

$ipSecId = 77;


/**
 * Create a client to the API service.
 */
$ipSecClient = SoftLayer_SoapClient::getClient($ipSecService, $ipSecId, $apiUsername, $apiKey, $endpointUrl);
//$ipSecClient = SoftLayer_SoapClient::getClient($ipSecService, $ipSecId, $apiUsername, $apiKey);

$mask = new SoftLayer_ObjectMask();
$mask = 'mask[id,billingItem.id]';
$ipSecClient->setObjectMask($mask);

try {
    $ipSecItem = $ipSecClient->getObject();
    $billingItemId = $ipSecItem->billingItem->id; 
    print_r($billingItemId);


    try {
        $billingItemClient = SoftLayer_SoapClient::getClient($billingItemService, $billingItemId, $apiUsername, $apiKey, $endpointUrl);
        $result = $billingItemClient->cancelItem(   False,
            False,
            'No longer needed',
            'Api test');
        print_r($result);

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


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

References: http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelService http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelItem