【问题标题】:Softlayer JAVA API sample to order "Hourly/Pre-set Configuration Bare Metal Servers"Softlayer JAVA API 示例订购“每小时/预设配置裸机服务器”
【发布时间】:2017-08-29 10:00:10
【问题描述】:

我正在努力寻找一种方法来使用 Java 语言在 Softlayer(每小时)上订购带有 GPU 的 Bare Metal Server。有一些关于此的片段消息,但我找不到 Java 的完整示例。以目前的信息,我应该终于可以得到目标了,但时间会被浪费掉。 :(

我在哪里可以获得这样的 Java 示例?

【问题讨论】:

    标签: java ibm-cloud-infrastructure bare


    【解决方案1】:

    看这个例子:

    package restapp.examples;
    import java.util.ArrayList;
    import java.util.List;
    import com.softlayer.api.*;
    import com.softlayer.api.service.Hardware;
    import com.softlayer.api.service.hardware.Server;
    import com.softlayer.api.service.Location;
    import com.softlayer.api.service.network.Component;
    import com.softlayer.api.service.product.Order;
    import com.softlayer.api.service.product.item.Price;
    import com.softlayer.api.service.product.pkg.Preset;
    import com.google.gson.Gson;
    
    public class OrderPreSetBMS2
    {
      public static void main( String[] args )
      {
        String user = "set me";
        String apiKey = "set me";
    
        Location datacenter = new Location();
        datacenter.setName("ams01");
    
        Preset preset = new Preset();
        preset.setKeyName("S1270_8GB_2X1TBSATA_NORAID");
    
        Component networkComponent = new Component();
        networkComponent.setMaxSpeed(100L);
    
    
        Hardware hardware = new Hardware();
        hardware.setDatacenter(datacenter);
        hardware.setHostname("simplebmi");
        hardware.setDomain("test.com");
        hardware.setHourlyBillingFlag(true);
        hardware.setFixedConfigurationPreset(preset);
        List<Component> networkComponents = hardware.getNetworkComponents();
        networkComponents.add(networkComponent);
        hardware.setOperatingSystemReferenceCode("UBUNTU_14_64");
    
        ApiClient client = new RestApiClient().withCredentials(user, apiKey).withLoggingEnabled();
        Hardware.Service hardwareService = Hardware.service(client); 
        Order.Service orderService = Order.service(client); 
    
        try
        {
          com.softlayer.api.service.container.product.Order productOrder = hardwareService.generateOrderTemplate(hardware);
          Gson gson = new Gson();
          System.out.println(gson.toJson(productOrder));
          com.softlayer.api.service.container.product.Order order = orderService.verifyOrder(productOrder);
          Gson gson2 = new Gson();
          System.out.println(gson2.toJson(order));
        }
        catch(Exception e)
        {
            System.out.println("Error: " + e);  
        }
      }
    }
    

    基本上这就是您需要更改参数值以查看调用方法http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/getCreateObjectOptions所需的有效配置的想法

    还要查看createObject方法http://sldn.softlayer.com/reference/services/softlayer_hardware_server/createobject的文档

    【讨论】:

    • 非常感谢,这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    相关资源
    最近更新 更多