doumo6356 2015-12-21 15:43
浏览 46
已采纳

SoftLayer API:如何取消Security_Certificate,Network_Firewall和Monitoring_agent对象

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.

  • 写回答

1条回答 默认 最新

  • doushifang4382 2015-12-21 23:16
    关注
    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 c语言写的8051单片机存储器mt29的模块程序
  • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
  • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。
  • ¥50 rk3588板端推理
  • ¥250 opencv怎么去掉 数字0中间的斜杠。
  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥250 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大