SoftLayer API:订购带宽池

时间:2016-02-01 06:57:50

标签: bandwidth ibm-cloud-infrastructure

对于N / W Part,当我们尝试“添加”新的带宽池时,安装费用为25美元。 但我没有找到API来拨打这笔费用。 即使没有身份证也需要25美元的安装费。

我必须使用什么来调整安装费?

我想知道如何编码, “在Java中添加带宽池”。

感谢。

1 个答案:

答案 0 :(得分:0)

查看以下Java脚本:

1。要获得加入Vdr会员/安装的Bandwidhth Pool费用:

package SoftLayer.api_java;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.account.Attribute;
import com.softlayer.api.service.Account;

/** 
 * This script retrieves a Vdr Member Price
 * 
 * Important pages:
 * http://sldn.softlayer.com/reference/services/SoftLayer_Account/getAttributeByType
 * http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account_Attribute
 */
public class GetVdrMemberPrice {

    public GetVdrMemberPrice() {
        // Declare your SoftLayer username and apiKey
        String user = "set me";
        String apikey = "set me";
        // Declare API Client
        ApiClient client = new RestApiClient().withCredentials(user, apikey);
        // Declare the type of account attribute you wish to retrieve
        String attributeType = "VDR_MEMBER_PRICE";
        try {
            Attribute result = Account.service(client).getAttributeByType(attributeType);
            System.out.println("Value: " + result.getValue());
        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
    }

    public static void main(String[] args) {
        new GetVdrMemberPrice();
    }
}

2. 添加带宽池

package SoftLayer.api_java;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.network.bandwidth.version1.Allotment;

/**
 * Add a Bandwidth Pool
 * 
 * Important pages:
 * http://sldn.softlayer.com/reference/services/SoftLayer_Network_Bandwidth_Version1_Allotment
 * http://sldn.softlayer.com/reference/services/SoftLayer_Network_Bandwidth_Version1_Allotment/createObject
 */
public class AddingBandwidthPool {

    public AddingBandwidthPool() {
        // Declare your SoftLayer username and apiKey
        String user = "set me";
        String apikey = "set me";
        // Define your account Id (set me)
        Long accountId = new Long(123456);
        // Define an identifier marking this allotment as a virtual private rack (1) or a bandwidth pooling(2).
        Long bandwidthAllotmentTypeId = new Long(2);
        // Define the region. You can get available regions using SoftLayer_Location_Group::getAllObjects method
        // http://sldn.softlayer.com/reference/services/SoftLayer_Location_Group/getAllObjects
        Long locationGroupId = new Long(1); 
        // Define text a virtual rack's name.
        String name = "set me";
        // Declare API Client
        ApiClient client = new RestApiClient().withCredentials(user, apikey);
        // Build a SoftLayer_Network_Bandwidth_Version1_Allotment object that you wish to create
        Allotment templateObject = new Allotment();
        templateObject.setAccountId(accountId);
        templateObject.setBandwidthAllotmentTypeId(bandwidthAllotmentTypeId);
        templateObject.setLocationGroupId(locationGroupId);;
        templateObject.setName(name);

        try {
            boolean result = Allotment.service(client).createObject(templateObject);
            System.out.println(result);
        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
    }

    public static void main(String[] args) {
        new AddingBandwidthPool();
    }
}

注意::SoftLayer_Network_Bandwidth_Version1_Allotment :: createObject的返回值存在问题,因为根据wsdl,它返回一个布尔值,但它返回一个SoftLayer_Network_Bandwidth_Version1_Allotment对象。但是,已成功添加带宽池。

参考文献: GetVdrMemberPrice CreateBandwidthPool