如何使用 java 在订购子网中设置 EndpointIPAddress
How to Set EndpointIPAddress in ordering subnet using java
如何在验证子网IP时设置Endpoint Vlan。
这是我验证订单的示例代码。它 returns 异常并显示需要端点 IP 的消息。
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 示例:
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);
}
}
}
更新 1.
另外,我们可以通过virtual Guest 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
问候。
这是获取 EndPoindIpAddressID 的示例代码,我已经尝试过,但它 returns 仅为空值。
private void getEndpointIP(){
Account.Service accSrv = Account.service(client);
accSrv.withMask().subnets().endPointIpAddress().id();
accSrv.withMask().ipAddresses().endpointSubnets().endPointIpAddress().id();
accSrv.withMask().publicSubnets().endPointIpAddress().id();
Account acc = accSrv.getObject();
List<Subnet> subnetList = acc.getPublicSubnets();
for(Subnet sb : subnetList){
System.out.println("EndPoint IP : " + sb.getEndPointIpAddress());
System.out.println("EndPoint IP ID : " + sb.getEndPointIpAddress().getId());
}
}
}
这是获取 EndpointIpAddressId 的替代方法。请确认这是否是有效的实施。谢谢~
private void getEndpointIP_altWay() {
Account.Service accSrv = Account.service(client);
accSrv.withMask().subnets().virtualGuests().fullyQualifiedDomainName();
accSrv.withMask().subnets().virtualGuests().primaryIpAddress().id();
accSrv.withMask().subnets().virtualGuests().status().name();
accSrv.withMask().subnets().ipAddresses().ipAddress().id();
Account acc = accSrv.getObject();
for (Subnet sub : acc.getSubnets()) {
List<Subnet> subnetList = acc.getPublicSubnets();
for (Subnet sb : subnetList) {
System.out.println("EndPoint IP : " + sb.getEndPointIpAddress());
System.out.println("EndPoint IP ID : " + sb.getEndPointIpAddress().getId());
}
List<IpAddress> ipList = sub.getIpAddresses();
List<Guest> gList = sub.getVirtualGuests();
for (Guest gt : gList) {
System.out.println(" name : " + gt.getFullyQualifiedDomainName());
System.out.println(" status : " + gt.getStatus().getName());
System.out.println(" public ip : " + gt.getPrimaryIpAddress());
for (IpAddress ip : ipList) {
if (ip.getIpAddress().equals(gt.getPrimaryIpAddress()))
System.out.println(" endpoint ip id : " + ip.getId());
}
}
}
}
如何在验证子网IP时设置Endpoint Vlan。 这是我验证订单的示例代码。它 returns 异常并显示需要端点 IP 的消息。
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 示例:
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);
}
}
}
更新 1.
另外,我们可以通过virtual Guest 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
问候。
这是获取 EndPoindIpAddressID 的示例代码,我已经尝试过,但它 returns 仅为空值。
private void getEndpointIP(){
Account.Service accSrv = Account.service(client);
accSrv.withMask().subnets().endPointIpAddress().id();
accSrv.withMask().ipAddresses().endpointSubnets().endPointIpAddress().id();
accSrv.withMask().publicSubnets().endPointIpAddress().id();
Account acc = accSrv.getObject();
List<Subnet> subnetList = acc.getPublicSubnets();
for(Subnet sb : subnetList){
System.out.println("EndPoint IP : " + sb.getEndPointIpAddress());
System.out.println("EndPoint IP ID : " + sb.getEndPointIpAddress().getId());
}
}
}
这是获取 EndpointIpAddressId 的替代方法。请确认这是否是有效的实施。谢谢~
private void getEndpointIP_altWay() {
Account.Service accSrv = Account.service(client);
accSrv.withMask().subnets().virtualGuests().fullyQualifiedDomainName();
accSrv.withMask().subnets().virtualGuests().primaryIpAddress().id();
accSrv.withMask().subnets().virtualGuests().status().name();
accSrv.withMask().subnets().ipAddresses().ipAddress().id();
Account acc = accSrv.getObject();
for (Subnet sub : acc.getSubnets()) {
List<Subnet> subnetList = acc.getPublicSubnets();
for (Subnet sb : subnetList) {
System.out.println("EndPoint IP : " + sb.getEndPointIpAddress());
System.out.println("EndPoint IP ID : " + sb.getEndPointIpAddress().getId());
}
List<IpAddress> ipList = sub.getIpAddresses();
List<Guest> gList = sub.getVirtualGuests();
for (Guest gt : gList) {
System.out.println(" name : " + gt.getFullyQualifiedDomainName());
System.out.println(" status : " + gt.getStatus().getName());
System.out.println(" public ip : " + gt.getPrimaryIpAddress());
for (IpAddress ip : ipList) {
if (ip.getIpAddress().equals(gt.getPrimaryIpAddress()))
System.out.println(" endpoint ip id : " + ip.getId());
}
}
}
}