gpt4 book ai didi

java - 订购 "Hourly/Pre-set Configuration Bare Metal Servers"的软层 JAVA API 示例

转载 作者:行者123 更新时间:2023-11-30 10:25:48 25 4
gpt4 key购买 nike

我正在努力寻找一种方法来使用 Java 语言在 Softlayer 上(每小时)订购带 GPU 的裸机服务器。有一些关于此的片段消息,但我找不到 Java 的完整示例。以目前的情报,我总算可以到达目标,但会浪费时间。 :(

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

最佳答案

看这个例子:

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

关于java - 订购 "Hourly/Pre-set Configuration Bare Metal Servers"的软层 JAVA API 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45936126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com