0

我正在尝试使用 Softlayer java API 实现修改设备配置。此过程将是与采购订单类似的过程。是否有任何特定的 API 来升级和降级设备?我为虚拟客人找到了 getUpgradeRequest()。如果您提供任何示例代码或 API 指南将有所帮助。谢谢 修改设备配置页面

        for (Guest guest :  Account.service(client).getVirtualGuests()){
            if(guest.getFullyQualifiedDomainName().equals(deviceName))  {
                Request rqt = Guest.service(client, guest.getId()).getUpgradeRequest();
                rqt.setId(id);
                rqt.setOrderId(orderId);
            }
        }
4

1 回答 1

0

下面是升级 VSI 的 Java 示例。例如:

import java.util.ArrayList;
import java.util.List;
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.Property;
import com.softlayer.api.service.product.item.Price;
import com.softlayer.api.service.virtual.Guest;
import com.softlayer.api.service.container.product.order.virtual.guest.Upgrade;

public class UpgradeVirtualGuest {

    public static void main(String[] args) {

        String username = "set me";
        String apikey = "set me";

        // Set the Virtual Guest to upgrade
        Long vsiId = new Long(11498369);

       // Declare item prices. In this case I’m updating the RAM
       // Please set the new item Price

        Long[] prices = { new Long(1641)};  

        List<Property> properties = new ArrayList<Property>();
        Property maintenance = new Property(); 
        maintenance.setName("MAINTENANCE_WINDOW");
        maintenance.setValue("2015-10-05T9:00:00-05:00");
        properties.add(maintenance);

        Guest vsi = new Guest();
        vsi.setId(vsiId);

        String containerIdentifier = "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade";

        // Create a SoftLayer API client object
        ApiClient client = new RestApiClient().withCredentials(username, apikey).withLoggingEnabled();


        /*
         * Set up Order template
         */
        Upgrade upgradeOrder = new Upgrade();

        upgradeOrder.setContainerIdentifier(containerIdentifier);
        upgradeOrder.getProperties().addAll(properties);
        upgradeOrder.getVirtualGuests().add(0, vsi);

        // Add Item prices to list
        for (Long i : prices) {
            Price price = new Price();
            price.setId(new Long(i));
            upgradeOrder.getPrices().add(price);
        }


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

        } catch (Exception e) {
            System.out.println(e);
        }

    }

}

如何获取虚拟客人升级的可用价格?执行:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/[virtual_guest_ID]/getUpgradeItemPrices

Method: GET

参考:

https://forums.softlayer.com/forum/softlayer-developer-network/general-discussion/84916-changeing-virtual-guest-maxmemory (这是一个很快就会过时的论坛,但它现在可以帮助你) https: //sldn.softlayer.com/es/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order

其他示例:

https://softlayer.github.io/php/upgrade_virtual_guest/ https://gist.github.com/underscorephil/3790139 https://github.com/softlayer/softlayer-java/blob/master/examples/src/main /java/com/softlayer/api/example/OrderVirtualServer.java https://softlayer.github.io/

问候

于 2016-02-04T19:20:34.373 回答