Search code examples
ibm-cloud-infrastructure

Order Vyatta and Netscaler VPX with Java


I trying to implement Netscaler and Vyatta Order in java. When I call Verify API in java, the following errors have been returned. The tested code also attached below. please recommend me if there is any missing configuration.

Netscaler : "error":"Order is missing the following category: NetScaler VPX. Vyatta : Gateway Appliances must be submitted as child containers

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);
    }

}

Solution

  • you have to create an orderContainer object and add there your packageOrder, then add the orderContainer object in a Order object. see the example bellow:

    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);
            }
    
        }
    
    }
    

    For Netscaler the issue is the object used in the order.

    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);
            }
    
        }
    
    }
    

    Regards