Search code examples
ibm-cloud-infrastructure

How to Set EndpointIPAddress in ordering subnet using java


How can I set EndpointVlan in verifying Subnet IP. This is my sample code to verify order. It returns Exceptions with message that Endpoint IP is required.

private void verifyStaticIp() {
    Long packageID = 0l; // ip item only (no sub-option)
    Long quantity = 1l;

    Price price = new Price();
    price.setId(12345l); // sample


    Property property = new Property(); // How to Set enpointVlanId in order template???
    property.setName("endPointVlanId");
    property.setValue("1223445");   

    // Create Order to verify
    Order packageOrder = new Order();
    packageOrder.setQuantity(quantity);
    packageOrder.setPackageId(packageID);
    packageOrder.getProperties().add(property);
    packageOrder.getPrices().add(price);

    try {
        Order order = com.softlayer.api.service.product.Order.service(client).verifyOrder(packageOrder);
        System.out.println("verify Static IP order result = " + order.getMessage());
    } catch (Exception e) {
        e.getMessage();
    }
}

Solution

  • Please try the following java example:

    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.Subnet;
    import com.softlayer.api.service.product.item.Price;
    
    /**
     * Order a new static public Subnet. 
     * 
     * Important manual pages:
     * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
     * http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder/
     * 
     * @license <http://sldn.softlayer.com/article/License>
     * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
     */
    public class createStaticPublicSubnet {
    
     /**
      * @param args
      */
     public static void main(String[] args) {
    
            // Your SoftLayer API username and key.
            String username = "set me";
            String apikey = "set me";
    
         // Declare item prices
            Long[] prices = { new Long(13983)};
    
            //The id of the IP address that you want to route a static subnet to.
            Long endPointIpAddressId = new Long(19868866);
    
            // The number of items to order
            Long quantity = new Long(1);
    
            String location = "AMSTERDAM";
    
            // The id of the SoftLayer_Product_Package you want to order.
            Long packageId = new Long(0);
    
            String containerIdentifier = "SoftLayer_Container_Product_Order_Network_Subnet";
    
            // Create a SoftLayer API client object
            ApiClient client = new RestApiClient().withCredentials(username, apikey);
    
            /*
             * Set up Order template
             */
            Subnet newOrder = new Subnet();
            newOrder.setContainerIdentifier(containerIdentifier);
            newOrder.setLocation(location);
            newOrder.setPackageId(packageId);
            newOrder.setQuantity(quantity);
            newOrder.setEndPointIpAddressId(endPointIpAddressId);
    
            // Add Item prices to list
            for (Long i : prices) {
                Price price = new Price();
                price.setId(new Long(i));
                newOrder.getPrices().add(price);
            }
    
            try 
            {
                Order orderResult = com.softlayer.api.service.product.Order.service(client).verifyOrder(newOrder);
                System.out.println("order successfully verified: " + orderResult);
    
            } catch (Exception e) {
                System.out.println(e);
            }
     }
    }
    

    Update 1.

    Also, we can find the “endPointIpAddressId” through virtual Guest id, please see the example:

    https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/[guest_id]/getObject?objectMask=mask[id, fullyQualifiedDomainName,primaryNetworkComponent[id,primaryIpAddress,primaryIpAddressRecord.id]]
    Method: GET
    

    The response should be something like this:

    {
    "fullyQualifiedDomainName": "hostnametest.test.com"
    "id": 9054111
    "primaryNetworkComponent": {
       "id": 4797111
       "primaryIpAddress": "119.81.111.111"
       "primaryIpAddressRecord": {
          "id": 24692446
      }-
    }-
    

    }

    Where the value that we need to use to order the subnet is : "id": 24692446 Regards.