本文介绍了如何使用Java在订购子网中设置EndpointIPAddress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在验证子网IP时设置EndpointVlan.这是我的验证订单的示例代码.它会返回异常",并带有要求提供终结点IP的消息.

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

推荐答案

请尝试以下Java示例:

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. <[email protected]>
 */
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);
        }
 }
}

更新1.

此外,我们可以通过虚拟访客ID找到"endPointIpAddressId" ,请参见示例:

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

响应应该是这样的:

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

}

在订购子网时需要使用的值为:"id":24692446 问候.

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

这篇关于如何使用Java在订购子网中设置EndpointIPAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:10