如何使用SoftLayer API Client for Java订购便携式子网类型

时间:2017-01-05 06:01:09

标签: java ibm-cloud-infrastructure

我尝试使用java的静态子网顺序示例执行此操作: How to Set EndpointIPAddress in ordering subnet using java

并基于python代码修改它以订购portabale子网: SoftLayer API: Ordering Subnet

但是,我得到了异常,表明订单配置错误,而且是针对静态而非预期的便携式网络:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.softlayer.api.ApiException$Internal: An endpoint IP Address is required to order a static subnet.(code: SoftLayer_Exception_Public, status: 500)
    at com.softlayer.api.ApiException.fromError(ApiException.java:16)
    at com.softlayer.api.RestApiClient$ServiceProxy.logAndHandleResponse(RestApiClient.java:258)
    at com.softlayer.api.RestApiClient$ServiceProxy.invokeService(RestApiClient.java:300)
    at com.softlayer.api.RestApiClient$ServiceProxy.invoke(RestApiClient.java:466)
    at com.sun.proxy.$Proxy29.verifyOrder(Unknown Source)
    at com.tieto.tecong.slcli.App.main(App.java:82)

这是我使用的java代码:

package com.tieto.tecong.slcli;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.container.product.Order;
import com.softlayer.api.service.container.product.order.network.Subnet;
import com.softlayer.api.service.product.item.Price;

public class App
{
    public static void main( String[] args )
    {
    ApiClient client = new RestApiClient().withCredentials("sdffds", "sdfsfd");

    Long[] prices = {13983L};
    Long quantity = 4L;
    Long vlanId = 1360265L;
    Long packageId = 0L;
    String containerIdentifier = "SoftLayer_Container_Product_Order_Network_Subnet";

    Subnet newOrder = new Subnet();
    newOrder.setContainerIdentifier(containerIdentifier);
    newOrder.setPackageId(packageId);
    newOrder.setQuantity(quantity);
    newOrder.setEndPointVlanId(vlanId);

    for (Long i : prices) {
        Price price = new Price();
        price.setId(new Long(i));
        newOrder.getPrices().add(price);
    }

    Order orderResult = com.softlayer.api.service.product.Order.service(client).verifyOrder(newOrder);
    System.out.println("order successfully verified: " + orderResult);
}

}

1 个答案:

答案 0 :(得分:0)

设置合适的价格修复了问题。 使用python客户端

执行订单时可以看到正确的ID
  

SoftLayer API: Ordering Subnet

并从验证的返回结果中检查价格ID。