Search code examples
phpapiibm-cloud-infrastructure

SoftLayer API: How to cancel Security_Certificate, Network_Firewall and Monitoring_agent objects


I created ssl security certificate, dedicated Vlan Firewall and Advanced monitoring using SoftLayer API complex types:

SoftLayer_Container_Product_Order_Security_Certificate
SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated
SoftLayer_Container_Product_Order_Monitoring_Package

I try to find SoftLayer API which allows me to cancel these objects once they're ordered.

I can obtain the:

SoftLayer_Security_Certificate,
SoftLayer_Network_Firewall_Module_Context_Interface,
SoftLayer_Monitoring_Agent object form SoftLayer_Account.

But there're no SoftLayer_Billing_Item data type on:

SoftLayer_Security_Certificate,
SoftLayer_Network_Firewall_Module_Context_Interface,
SoftLayer_Monitoring_Agent.

That will not allow me to use SoftLayer_Billing_Item->cancelService() to cancel them.

Can somebody please point me how I can cancel SSL certificate, Firewall and monitoring agent using SoftLayer API ? I'd be appreciated if you can provide PHP sample code them.


Solution

    1. For SoftLayer_Security_Certificate, you only need the identifier from this, you can retrieve the Security Certificates identifiers with the following method:

    Method: SoftLayer_Account::getSecurityCertificates Link: http://sldn.softlayer.com/reference/services/SoftLayer_Account/getSecurityCertificates

    Then you can delete this, using SoftLayer_Security_Certificate:deleteObject method.

    Here an example:

    <?php
    /**
     * Delete Security Certificate
     *
     * This script deletes a security certificate
     *
     * Important manual pages:
     * @see http://sldn.softlayer.com/reference/services/SoftLayer_Security_Certificate/deleteObject
     *
     * @license <http://sldn.softlayer.com/wiki/index.php/license>
     * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
     */
    require_once '\vendor\autoload.php';
    
    /**
     * Your SoftLayer API username
     * @var string
     */
    $username = "set me";
    
    /**
     * Your SoftLayer API key
     * Generate one at: https://control.softlayer.com/account/users
     * @var string
     */
    $apiKey = "set me";
    
    /**
     * Define the security certificate identifier. You can retrieve the identifiers from them using
     * SoftLayer_Account::getSecurityCertificates
     * @var int
     * @see http://sldn.softlayer.com/reference/services/SoftLayer_Account/getSecurityCertificates
     */
    $securityCertificateId = 14584;
    
    // Create a SoftLayer API client object for "SoftLayer_Security_Certificate" service
    $client = \SoftLayer\SoapClient::getClient('SoftLayer_Security_Certificate', null, $username, $apiKey);
    
    // Set init parameters
    $client -> setInitParameter($securityCertificateId);
    
    try {
        $result = $client -> deleteObject();
        print_r($result);
    } catch(Exception $e) {
        echo "Unable to delete Security Certificate " . $e -> getMessage();
    }
    
    ?>
    
    1. Regarding to SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated objects that you have in your account, you can get all of them with their billingItems with the following Rest request:

      https://$user:$apiKey@api.softlayer.com/rest/v3.1/SoftLayer_Search/advancedSearch?objectMask=mask[resource(SoftLayer_Network_Vlan_Firewall)[billingItem]]
      
      Method: Post
      
      {  
         "parameters":[  
            "_objectType:SoftLayer_Network_Vlan_Firewall _sort:[fullyQualifiedDomainName:asc]"
         ]
      }
      

    Once you got the billingItem from Firewall Dedicated, you can delete it with the following php script:

    <?php
    /**
     * This script cancels the resource or service for a billing item
     *
     * Important manual pages:
     * @see http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelService
     *
     * @license <http://sldn.softlayer.com/wiki/index.php/license>
     * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
     */
    require_once '\vendor\autoload.php';
    
    /**
     * Your SoftLayer API username
     * @var string
     */
    $username = "set me";
    
    /**
     * Your SoftLayer API key
     * Generate one at: https://control.softlayer.com/account/users
     * @var string
     */
    $apiKey = "set me";
    $endPoint = "http://stable.application.qadal0501.softlayer.local/v3.1/sldn/soap/";
    /**
     * Declare the billing item identifier from Network Protection Firewall Dedicated
     * @var int
     */
    $billingItemId = 26382998;
    
    // Create a SoftLayer API client object for "SoftLayer_Billing_Item" service
    $client = \SoftLayer\SoapClient::getClient('SoftLayer_Billing_Item', null, $username, $apiKey, $endPoint);
    
    // Set init parameters
    $client -> setInitParameter($billingItemId);
    
    try {
        $result = $client -> cancelService();
        print_r($result);
    } catch(Exception $e) {
        echo "Unable to Cancel Service: " . $e -> getMessage();
    }
    
    ?>
    

    For Monitoring package objects, the following script will help to get the monitoring package for a virtual guest and its billing item:

    <?php
    /**
     * This script retrieves a billing item of "monitoring_package" category code from a virtual guest
     *
     * Important manual pages:
     * @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Billing_Item
     * @see http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getBillingItem
     * 
     * @license <http://sldn.softlayer.com/wiki/index.php/license>
     * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
     */
    require_once '\vendor\autoload.php';
    
    /**
     * Your SoftLayer API username
     * @var string
     */
    $username = "set me";
    
    /**
     * Your SoftLayer API key
     * Generate one at: https://control.softlayer.com/account/users
     * @var string
     */
    $apiKey = "set me";
    
    // Declare the server identifier
    $serverId = 14463961;
    
    // Create a SoftLayer API client object for "SoftLayer_Account" service
    $guestService = \SoftLayer\SoapClient::getClient('SoftLayer_Virtual_Guest', $serverId, $username, $apiKey);
    
    // Declare an object mask to relational properties
    $objectMask = "mask[activeAssociatedChildren]";
    $guestService -> setObjectMask($objectMask);
    
    try {
        $billingItems = $guestService -> getBillingItem();
        foreach($billingItems -> activeAssociatedChildren as $billingItem)
        {
            if($billingItem -> categoryCode == "monitoring_package")
            {
                print_r($billingItem);
            }
        }   
    } catch(Exception $e) {
        echo "Unable to get billing item: " . $e -> getMessage();
    }
    
    ?>
    

    Once you got the billingItem from Monitoring Package, you can cancel this with SoftLayer_Billing_Item::cancelService.

    Php SoftLayer Client: https://github.com/softlayer/softlayer-api-php-client