我想使用 Softlayer java API 订购每小时一次的 Bare Metal。我从https://gist.github.com/bmpotter/fe2de7f8028d73ada4e5中获得了这个想法。这是我的步骤:
Hardware hardware = new Hardware();
Order orderTemplate = new Order();
// 1. Set hostname, domain to hardware
// 2. set Preset
Preset preset = new Preset();
preset.setKeyName("S1270_8GB_2X1TBSATA_NORAID");
hardware.setFixedConfigurationPreset(preset);
// 3. Component setMaxSpeed, and added to hardware
hardware.setPrimaryNetworkComponent()
// 4. "UBUNTU_14_64"
hardware.setOperatingSystemReferenceCode()
// 1. Added Quantity to orderTemplate
// 2. Added location to orderTemplate
// 3. Added Hardware to orderTemplate
// 4. Added Container, since I am see the exception
orderTemplate.setContainerIdentifier("SoftLayer_Product_Package_Preset");
Finally tried to verify the Order.
我不断收到一般错误消息:
指定的容器无效:SoftLayer_Container_Product_Order。订购服务器或服务需要特定的容器类型,而不是通用的基本订单容器。
我究竟做错了什么?我是否需要发送priceIds
,类似于非每小时 Bare Metal Order?是否有故障排除指南来了解我的订单中缺少什么?
Pedro David Fuentes 你能帮忙吗?在弄清楚价格后,我尝试了这个:
https://[用户名]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
{
"parameters": [
{
"complexType": "SoftLayer_Container_Product_Order_Hardware_Server",
"quantity": 1,
"location": "DALLAS",
"packageId": 200,
"useHourlyPricing": 1,
"presetId": 66,
"prices": [
{
"id": 37318
},
{
"id": 34183
},
{
"id": 26737
},
{
"id": 34807
},
{
"id": 25014
}
],
"hardware": [
{
"hostname": "myhostname",
"domain": "mydomain.com"
}
]
}
]
}
{
"error": "Unable to add a Graphics Processing Unit price (178119) because it is not valid for the package (200).",
"code": "SoftLayer_Exception_Public"
}
也可以通过 JAVA 代码重现,因此也可以通过 REST 进行尝试。
带有额外日志记录的修改代码:
String username = "xxxxx";
String apiKey = "xxxxx";
Location datacenter = new Location();
datacenter.setName("seo01");
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("xxxxx_xxxxx_BM_HOURLY");
hardware.setDomain("xxxx.xxx");
hardware.setHourlyBillingFlag(true);
hardware.setFixedConfigurationPreset(preset);
List<Component> networkComponents = hardware.getNetworkComponents();
networkComponents.add(networkComponent);
hardware.setOperatingSystemReferenceCode("CENTOS_LATEST");
ApiClient client = new RestApiClient().withCredentials(username, apiKey).withLoggingEnabled();
Hardware.Service hardwareService = Hardware.service(client);
try
{
Gson gson = new Gson();
Hardware hardwarePlaced = hardwareService.createObject(hardware);
System.out.println("createObject: " + gson.toJson(hardwarePlaced));
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
我收到一个错误:在带有正文的链接上运行 POST:{"parameters":[{"complexType":"SoftLayer_Hardware","hostname":"xxxxx_xxxxx_BM_HOURLY","domain":"xxxx.xxx","fixedConfigurationPreset":{ "complexType":"SoftLayer_Product_Package_Preset","keyName":"S1270_8GB_2X1TBSATA_NORAID"},"datacenter":{"complexType":"SoftLayer_Location","name":"seo01"},"hourlyBillingFlag":true,"networkComponents":[ {"complexType":"SoftLayer_Network_Component","maxSpeed":100}],"operatingSystemReferenceCode":"CENTOS_LATEST"}]} 在与正文的链接上得到 500:{"error":"无法添加图形处理单价 (178119),因为它对包 (200) 无效。","code":"SoftLayer_Exception_Public"} 错误:com.softlayer.api.ApiException$Internal:无法添加图形处理单价 (178119),因为它对包 (200) 无效。(代码:SoftLayer_Exception_Public,状态:500)