我想使用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
,类似于非小时裸金属订单?是否有故障排除指南,以了解我的订单中缺少什么?
Pedro David Fuentes你能帮忙吗?在弄清楚价格之后,我尝试了这个:
https://[username]:[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);
}
我收到错误: 在与body的链接上运行POST:{&#34;参数&#34;:[{&#34; complexType&#34;:&#34; SoftLayer_Hardware&#34;,&#34;主机名&#34;:&#34; xxxxx_xxxxx_BM_HOURLY&#34;&#34;结构域&#34;:&#34; xxxx.xxx&#34;&#34; fixedConfigurationPreset&#34; {&#34;的complexType&#34;:&#34; SoftLayer_Product_Package_Preset&# 34;,&#34;的keyName&#34;:&#34; S1270_8GB_2X1TBSATA_NORAID&#34;}&#34;数据中心&#34; {&#34;的complexType&#34;:&#34; SoftLayer_Location&#34 ;, &#34;名称&#34;:&#34; seo01&#34;}&#34; hourlyBillingFlag&#34;:真,&#34; networkComponents&#34;:[{&#34;的complexType&#34 ;: &#34; SoftLayer_Network_Component&#34;&#34; MAXSPEED&#34; 100}],&#34; operatingSystemReferenceCode&#34;:&#34; CENTOS_LATEST&#34;}]} 与正文链接得到500:{&#34;错误&#34;:&#34;无法添加图形处理单元价格(178119),因为它对包(200)无效。&#34;,& #34;代码&#34;:&#34; SoftLayer_Exception_Public&#34;} 错误:com.softlayer.api.ApiException $ Internal:无法添加图形处理单元价格(178119),因为它对包(200)无效。(代码:SoftLayer_Exception_Public,status:500)
答案 0 :(得分:0)
你可以试试这个剧本。
package SoftLayer_Java_Scripts.Examples;
import java.util.ArrayList;
import java.util.List;
import com.softlayer.api.*;
import com.softlayer.api.service.container.product.order.hardware.Server;
import com.softlayer.api.service.Hardware;
import com.softlayer.api.service.product.Order;
import com.softlayer.api.service.product.item.Price;
import com.google.gson.Gson;
/**
* Order a new server with preset configuration.
*
* The presets used to simplify ordering by eliminating the need
* for price ids when submitting orders.
* Also when the order contains a preset id, it is not possible
* to configure VLANs in the order.
*
* Important manual pages:
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Message_Queue
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
*
* @license <http://sldn.softlayer.com/article/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
* @version 1.0
*/
public class OrderPreSetBMS
{
public static void main( String[] args )
{
// Your SoftLayer API username and key.
String user = "set me";
String apiKey = "set me";
long quantity = 1;
String location = "AMSTERDAM";
long packageId = 200;
long presetId = 64;
String hostname = "test";
String domain = "example.org";
// Building a skeleton SoftLayer_Hardware_Server object to model the hostname and
// domain we want for our server. If you set quantity greater then 1 then you
// need to define one hostname/domain pair per server you wish to order.
Hardware hardware = new Hardware();
hardware.setHostname(hostname);
hardware.setDomain(domain);
// Building a skeleton SoftLayer_Product_Item_Price objects. These objects contain
// much more than ids, but SoftLayer's ordering system only needs the price's id
// to know what you want to order.
// Every item in SoftLayer's product catalog is assigned an id. Use these ids
// to tell the SoftLayer API which options you want in your new server. Use
// the getActivePackages() method in the SoftLayer_Account API service to get
// a list of available item and price options per available package.
// Note: The presets already have some preconfigured items, such as
// the server or the disks you do not need to configure the prices for those
// items.
//
// Id: 44988 -> CentOS 7.x (64 bit)
// Id: 1800 -> 0 GB Bandwidth
// Id: 273 -> 100 Mbps Public & Private Network Uplinks
// Id: 420 -> Unlimited SSL VPN Users & 1 PPTP VPN User per account
// Id: 21 -> 1 IP Address
// Id: 906 -> Reboot / KVM over IP
long[] priceIds = {44988, 1800, 273, 420, 21, 906};
List<Price> prices = new ArrayList<Price>();
for (int i = 0; i < priceIds.length; i++) {
Price p = new Price();
p.setId(priceIds[i]);
prices.add(p);
}
// Building a skeleton SoftLayer_Container_Product_Order_Hardware_Server object
// containing the order you wish to place.
Server server = new Server();
server.setQuantity(quantity);
server.setLocation(location);
server.setPackageId(packageId);
List<Price> priceList = server.getPrices();
priceList.addAll(prices);
List<Hardware> hardwareList = server.getHardware();
hardwareList.add(hardware);
server.setPresetId(presetId);
// Creating a SoftLayer API client and service objects.
ApiClient client = new RestApiClient().withCredentials(user, apiKey);
Order.Service service = Order.service(client);
try
{
// verifyOrder() will check your order for errors. Replace this with a call
// to placeOrder() when you're ready to order. Both calls return a receipt
// object that you can use for your records.
// Once your order is placed it'll go through SoftLayer's approval and
// provisioning process. When it's done you'll have a new
// SoftLayer_Hardware_Server object and server ready to use.
com.softlayer.api.service.container.product.Order verifiedOrder = service.verifyOrder(server);
Gson gson = new Gson();
System.out.println(gson.toJson(verifiedOrder));
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}
下一个REST请求检索包ID的产品项目价格。重要的是要注意这些价格是如何组织的以及它们包含哪些信息。例如,这些产品商品价格可能具有相同的商品ID,这是因为价格按位置分开。
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Product_Package/200/getItemPrices.json?objectMask=mask[id,pricingLocationGroup[locations[name]],item[id,description],categories[categoryCode]]
下一个请求使用对象过滤器和主机Ping和TCP服务监控作为搜索条件。通过此示例,可以意识到产品项目价格可以具有相同的项目ID,这意味着它们是相同的,但是应该根据订单被验证的具体位置来使用。
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Product_Package/200/getItemPrices.json?objectMask=mask[id,pricingLocationGroup[locations[name]],item[id,description],categories[categoryCode]]&objectFilter={"itemPrices":{"item":{"description":{"operation":"Host Ping and TCP Service Monitoring"}}}}
进一步阅读:
答案 1 :(得分:0)
有关订单BM服务器的文档可以帮助您http://sldn.softlayer.com/blog/bpotter/ordering-bare-metal-servers-using-softlayer-api
这是订购预设的例子:
import java.util.List;
import com.softlayer.api.*;
import com.softlayer.api.service.Hardware;
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.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("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("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);
Hardware.Service hardwareService = Hardware.service(client);
Order.Service orderService = Order.service(client);
try
{
//Change generateOrderTemplate method by createObject when you are ready to order the server.
com.softlayer.api.service.container.product.Order productOrder = hardwareService.generateOrderTemplate(hardware);
Gson gson = new Gson();
System.out.println(gson.toJson(productOrder));
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}