我尝试在java中实现Netscaler和Vyatta Order。 当我在java中调用Verify API时,返回了以下错误。 测试代码也附在下面。如果配置丢失,请推荐我。
Netscaler:"错误":"订单缺少以下类别:NetScaler VPX。 Vyatta:Gateway Appliance必须作为子容器提交
public void orderNetscalerTest() {
// Netscaler VPX 10.5
Price net_price = new Price();
net_price.setId(17238l);
// Public Secondary StaticIP Address
Price static_price = new Price();
static_price.setId(44964l);
ArrayList<Price> prices = new ArrayList<Price>();
prices.add(net_price);
// prices.add(static_price);
Long packageID = 192l; // Netscaler package
Long quantity = 1l;
// Create Order to verify
Order packageOrder = new Order();
packageOrder.setQuantity(quantity);
packageOrder.setPackageId(packageID);
packageOrder.getPrices().addAll(prices);
try {
Order orderResult = com.softlayer.api.service.product.Order.service(client).verifyOrder(packageOrder);
System.out.println("order: netscaler successfully verified: " + orderResult);
} catch (Exception e) {
System.out.println(e);
}
}
public void orderVyattaTest() {
ArrayList<Price> prices = new ArrayList<Price>();
Price pr1 = new Price();
pr1.setId(13739l);prices.add(pr1);
Price pr2 = new Price();
pr2.setId(21010l);prices.add(pr2);
Price pr3 = new Price();
pr3.setId(36044l);prices.add(pr3);
Price pr4 = new Price();
pr4.setId(876l);prices.add(pr4);
Price pr5 = new Price();
pr5.setId(1267l);prices.add(pr5);
Price pr6 = new Price();
pr6.setId(342l);prices.add(pr6);
Price pr7 = new Price();
pr7.setId(273l);prices.add(pr7);
Price pr8 = new Price();
pr8.setId(17129l);prices.add(pr8);
Price pr9 = new Price();
pr9.setId(55l);prices.add(pr9);
Price pr10 = new Price();
pr10.setId(58l);prices.add(pr10);
Price pr11 = new Price();
pr11.setId(420l);prices.add(pr11);
Price pr12 = new Price();
pr12.setId(418l);prices.add(pr12);
Price pr13 = new Price();
pr13.setId(21l);prices.add(pr13);
Price pr14 = new Price();
pr14.setId(57l);prices.add(pr14);
Price pr15 = new Price();
pr15.setId(906l);prices.add(pr15);
Long packageID = 174l; // Vyatta pkgId
Long quantity = 1l;
Hardware newBareMetal = new Hardware();
newBareMetal.setHostname("myhost");
newBareMetal.setDomain("mydomain.com");
// Create Order to verify
Order packageOrder = new Order();
packageOrder.getHardware().add(newBareMetal);
packageOrder.getPrices().addAll(prices);
packageOrder.setQuantity(quantity);
packageOrder.setPackageId(packageID);
packageOrder.setLocation("3");
try {
Order orderResult = com.softlayer.api.service.product.Order.service(client).verifyOrder(packageOrder);
System.out.println("order: vyatta successfully verified: " + orderResult);
} catch (Exception e) {
System.out.println(e);
}
}
答案 0 :(得分:0)
您必须创建一个orderContainer对象并在其中添加packageOrder,然后在Order对象中添加orderContainer对象。见下面的例子:
import java.util.ArrayList;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Hardware;
import com.softlayer.api.service.container.product.Order;
import com.softlayer.api.service.product.item.Price;
public class OrderVyatta {
public static void main(String[] args) {
String user = "set me";
String apikey = "set me";
ApiClient client = new RestApiClient().withCredentials(user, apikey);
ArrayList<Price> prices = new ArrayList<Price>();
Price pr1 = new Price();
pr1.setId(13739l);prices.add(pr1);
Price pr2 = new Price();
pr2.setId(21010l);prices.add(pr2);
Price pr3 = new Price();
pr3.setId(36044l);prices.add(pr3);
Price pr4 = new Price();
pr4.setId(876l);prices.add(pr4);
Price pr5 = new Price();
pr5.setId(1267l);prices.add(pr5);
Price pr6 = new Price();
pr6.setId(342l);prices.add(pr6);
Price pr7 = new Price();
pr7.setId(273l);prices.add(pr7);
Price pr8 = new Price();
pr8.setId(17129l);prices.add(pr8);
Price pr9 = new Price();
pr9.setId(55l);prices.add(pr9);
Price pr10 = new Price();
pr10.setId(58l);prices.add(pr10);
Price pr11 = new Price();
pr11.setId(420l);prices.add(pr11);
Price pr12 = new Price();
pr12.setId(418l);prices.add(pr12);
Price pr13 = new Price();
pr13.setId(21l);prices.add(pr13);
Price pr14 = new Price();
pr14.setId(57l);prices.add(pr14);
Price pr15 = new Price();
pr15.setId(906l);prices.add(pr15);
Long packageID = 174l; // Vyatta pkgId
Long quantity = 1l;
Hardware newBareMetal = new Hardware();
newBareMetal.setHostname("myhost");
newBareMetal.setDomain("mydomain.com");
// Create Order to verify
Order packageOrder = new Order();
packageOrder.getHardware().add(newBareMetal);
packageOrder.getPrices().addAll(prices);
packageOrder.setQuantity(quantity);
packageOrder.setPackageId(packageID);
packageOrder.setLocation("3");
ArrayList<Order> orderContainners = new ArrayList<Order>();
orderContainners.add(packageOrder);
Order order = new Order();
order.getOrderContainers().addAll(orderContainners);
try {
Order orderResult = com.softlayer.api.service.product.Order.service(client).verifyOrder(order);
System.out.println("order: vyatta successfully verified: " + orderResult);
} catch (Exception e) {
System.out.println(e);
}
}
}
对于Netscaler,问题是订单中使用的对象。
import java.util.ArrayList;
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.network.application.delivery.Controller;
import com.softlayer.api.service.product.item.Price;
public class OrderNetxcaler {
public static void main(String[] args) {
// 44964 : netscaler price id
// 17238 : static IP price id
String user = "set me";
String apikey = "set me";
ApiClient client = new RestApiClient().withCredentials(user, apikey);
// Netscaler VPX 10.5 standard
Price net_price = new Price();
net_price.setId(44964l);
// static_price
Price static_price = new Price();
static_price.setId(17238l);
ArrayList<Price> prices = new ArrayList<Price>();
prices.add(net_price);
prices.add(static_price);
Long packageID = 192l; // Netscaler package
Long quantity = 1l;
// Create Order to verify
Controller packageOrder = new Controller();
packageOrder.setQuantity(quantity);
packageOrder.setPackageId(packageID);
packageOrder.getPrices().addAll(prices);
try {
Order orderResult = com.softlayer.api.service.product.Order.service(client).verifyOrder(packageOrder);
System.out.println("order: netscaler successfully verified: " + orderResult);
} catch (Exception e) {
System.out.println(e);
}
}
}
此致