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

时间:2015-12-21 15:43:36

标签: php api ibm-cloud-infrastructure

我使用SoftLayer API复杂类型创建了ssl安全证书,专用Vlan防火墙和高级监控:

SoftLayer_Container_Product_Order_Security_Certificate
SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated
SoftLayer_Container_Product_Order_Monitoring_Package

我尝试找到SoftLayer API,允许我在订购后取消这些对象。

我可以获得:

SoftLayer_Security_Certificate,
SoftLayer_Network_Firewall_Module_Context_Interface,
SoftLayer_Monitoring_Agent object form SoftLayer_Account.

但是没有SoftLayer_Billing_Item数据类型:

SoftLayer_Security_Certificate,
SoftLayer_Network_Firewall_Module_Context_Interface,
SoftLayer_Monitoring_Agent.

这将不允许我使用SoftLayer_Billing_Item-> cancelService()来取消它们。

有人可以指点我如何使用SoftLayer API取消SSL证书,防火墙和监控代理?如果您能提供PHP示例代码,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

  1. 对于 SoftLayer_Security_Certificate ,您只需要此标识符,您可以使用以下方法检索安全证书标识符:
  2.   

    方法:SoftLayer_Account :: getSecurityCertificates   链接:http://sldn.softlayer.com/reference/services/SoftLayer_Account/getSecurityCertificates

    然后您可以使用 SoftLayer_Security_Certificate:deleteObject 方法删除它。

    这是一个例子:

    <?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. 关于您帐户中的 SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated 对象,您可以使用以下Rest请求获取所有这些对象:

      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]"
         ]
      }
      
    2. 从Firewall Dedicated获得 billingItem 后,您可以使用以下php脚本删除它:

      <?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();
      }
      
      ?>
      

      对于监控软件包对象,以下脚本将有助于获取虚拟客户及其开票项目的监控包:

      <?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();
      }
      
      ?>
      

      从监控包中获得 billingItem 后,您可以使用 SoftLayer_Billing_Item :: cancelService 取消此操作。

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