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

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

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

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. 对于SoftLayer_Security_Certificate,您只需要从这里获取标识符,您可以通过以下方法检索安全证书标识符:

Method: SoftLayer_Account::getSecurityCertificates Link: 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 请求获取所有对象及其 billingItems:

    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]"
       ]
    }
    

从 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