softlayer api:如何升级块存储卷大小

时间:2018-02-12 01:42:30

标签: api storage block ibm-cloud-infrastructure

我尝试通过API升级块(性能)存储卷和IOP。

测试代码返回错误消息:

“错误:com.softlayer.api.ApiException $ Internal:订单容器上提供的无效价格块存储(189443)。(代码:SoftLayer_Exception_Order_Item_Invalid,status:500)”

我正在使用placeOrder和verifyOrder方法进行订购。

在哪里可以找到升级存储卷的示例代码?

public void test03() throws Exception {
    System.out.println("\nStorage Upgrade Test Start !!\n");

    ApiClient client = new RestApiClient().withCredentials(username, apiKey);

    com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade storage = new com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade();

    Storage.Service service = Storage.service(client, 38366457L);
    service.withMask().accountId();
    service.withMask().id();
    service.withMask().bytesUsed();
    service.withMask().osTypeId();
    service.withMask().iops();
    service.withMask().username();
    service.withMask().allowedIpAddresses();
    service.withMask().replicationStatus();
    service.withMask().parentVolume();
    service.withMask().parentVolume().volumeStatus();
    service.withMask().serviceResourceBackendIpAddress();
    service.withMask().serviceResource().datacenter();
    service.withMask().allowedHardware().allowedHost().credential().username().password();
    service.withMask().allowedSubnets();
    service.withMask().allowedVirtualGuests().allowedHost().credential().username().password();
    service.withMask().allowedIpAddresses().allowedHost().credential().username().password();
    service.withMask().snapshotCapacityGb();
    service.withMask().snapshotSizeBytes();
    service.withMask().snapshotSpaceAvailable();
    service.withMask().parentVolume().snapshotSizeBytes();
    service.withMask().parentVolume().snapshotSpaceAvailable();
    service.withMask().properties().type();
    service.withMask().billingItem();
    service.withMask().billingItem().children().activeFlag();
    service.withMask().billingItem().children().item();
    service.withMask().properties().volume();
    service.withMask().capacityGb();
    service.withMask().nasType();

    Storage storage1 = service.getObject();

    Order order = null;

    try {
        // 1. Storage volume
        storage.setVolumeSize(80L);
        storage.setIops(400L);

        storage1.setUpgradableFlag(true);
        storage.setVolume(storage1);

        order = storage;

        // Set SoftLayer Package Id
        order.setPackageId(759L);

        order.setUseHourlyPricing(true);

        // Set Data Center Location
        order.setLocation("1854895");

        List<Price> S_prices = new ArrayList<Price>();

        //International Services
        Price price1 = new Price();
        price1.setId(189433L);

        // 2. Block/File Storage
        Price price2 = new Price();
        price2.setId(189443L); //Block Storage

        //Storage Space
        Price price3 = new Price();
        price3.setId(189753L);

        //IOPS
        Price price4 = new Price();
        price4.setId(189813L);

        S_prices.add(price1);
        S_prices.add(price2);
        S_prices.add(price3);
        S_prices.add(price4);

        // Set Item Prices
        order.getPrices().addAll(S_prices);

        Order baseContainer = new Order();
        baseContainer.getOrderContainers().add(order);

        // verify
        Order verifiedOrder = com.softlayer.api.service.product.Order.service(client).verifyOrder(baseContainer);

        // placeorder
        com.softlayer.api.service.container.product.order.Receipt receipt = com.softlayer.api.service.product.Order.service(client).placeOrder(baseContainer, false);
    } catch (Exception e) {
        System.out.println("Error: " + e);
    } finally {
        System.out.println("\nTest End !!\n");
    }
}

2 个答案:

答案 0 :(得分:0)

尝试删除此价格:

 // 2. Block/File Storage
        Price price2 = new Price();
        price2.setId(189443L); //Block Storage

当您升级&#34; storage_as_a_service&#34;你只需要那个价格(189433)以及体积大小和IOPS的价格

这是我使用的RESTFul请求:

POST https://$USERNAME:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Order/placeOrder

{

    "parameters": [{

        "complexType": "SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade",

        "packageId": 759,

        "volume": {
            "id": 38740447
        },

        "volumeSize": 2000,

        "iops": 1000,

        "useHourlyPricing": true,

        "prices": [{
            "id": 190233
        }, {
            "id": 190293
        }, {
            "id": 189433
        }],

        "quantity": 1

    }]

}

所以我建议你:

1.-尝试使用控制门户升级您的块存储,这可能是您的帐户或块存储的问题。

2.-尝试使用RESTFul请求进行升级,也许java客户端发送错误请求。

3.-尝试Looging您的Java代码,看看您的Java代码发送的RESTFul请求是否与我发布的RESTFUL请求类似:

  

日志记录可以通过以下方式记录请求和对stdout的响应   在RestApiClient上调用withLoggingEnabled。为了记录   在其他地方,只需使用自己的RestApiClient实现   logRequest和logResponse被覆盖。

e.g。

ApiClient client = new RestApiClient().withCredentials(username, apiKey).withLoggingEnabled();

此致

答案 1 :(得分:0)

我解决了一个问题。

我的代码有两个问题。

首先,在升级存储(块/文件)的情况下,类型不是

// 2. Block/File Storage
Price price2 = new Price();
price2.setId(189443L); //Block Storage

二,升级容器的包装顺序不是

因为升级存储,ComplexType必须是&#34; SoftLayer_Container_Product_Order_Network_Storage_AsAService_Upgrade&#34;

但订单的ComplexType是&#34; SoftLayer_Container_Product_Order&#34;

Order baseContainer = new Order(); <-- ComplextType : SoftLayer_Container_Product_Order
baseContainer.getOrderContainers().add(order);

所以我删除了它们,并将verifyOrder和placeOrder参数修改为订单变量。

Order verifiedOrder = com.softlayer.api.service.product.Order.service(client).verifyOrder(order);

    // placeorder
com.softlayer.api.service.container.product.order.Receipt receipt = com.softlayer.api.service.product.Order.service(client).placeOrder(order, false);

这是最终代码

public void test03() throws Exception {
System.out.println("\nStorage Upgrade Test Start !!\n");

ApiClient client = new RestApiClient().withCredentials(username, apiKey);

com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade storage = new com.softlayer.api.service.container.product.order.network.storage.asaservice.Upgrade();

Storage.Service service = Storage.service(client, 38366457L);
service.withMask().id();

Storage storage1 = service.getObject();

Order order = null;

try {
    // 1. Storage volume
    storage.setVolumeSize(80L);
    storage.setIops(400L);

    storage1.setUpgradableFlag(true);
    storage.setVolume(storage1);

    order = storage;

    // Set SoftLayer Package Id
    order.setPackageId(759L);

    order.setUseHourlyPricing(true);

    // Set Data Center Location
    order.setLocation("1854895");

    List<Price> S_prices = new ArrayList<Price>();

    //International Services
    Price price1 = new Price();
    price1.setId(189433L);

    //Storage Space
    Price price3 = new Price();
    price3.setId(189753L);

    //IOPS
    Price price4 = new Price();
    price4.setId(189813L);

    S_prices.add(price1);
    S_prices.add(price3);
    S_prices.add(price4);

    // Set Item Prices
    order.getPrices().addAll(S_prices);

    // verify
    Order verifiedOrder = com.softlayer.api.service.product.Order.service(client).verifyOrder(order);

    // placeorder
    com.softlayer.api.service.container.product.order.Receipt receipt = com.softlayer.api.service.product.Order.service(client).placeOrder(order, false);
} catch (Exception e) {
    System.out.println("Error: " + e);
} finally {
    System.out.println("\nTest End !!\n");
}

}