0
當我添加包含選項的組時,如何設置網絡組件以實現「跨多個VLAN的平衡」和「在縮小尺寸時跨VLAN保持平衡」。我無法找到網絡組件的配置字段。 用於SL中自動縮放的網絡配置
當我添加包含選項的組時,如何設置網絡組件以實現「跨多個VLAN的平衡」和「在縮小尺寸時跨VLAN保持平衡」。我無法找到網絡組件的配置字段。 用於SL中自動縮放的網絡配置
那麼第一個選項:平衡跨多個VLAN。如果您通過Control Portal啓用此選項,它將加載購買的vlans。所以這不是一面旗幟。我們可以通過API來模擬這個功能,但它取決於很多因素。我會試着爲此建立一個腳本,我會讓你知道任何關於它的消息。
關於到保留餘額的跨VLAN對下限值,這是balancedTerminationFlag,你應該在你的代碼一樣設置該屬性:
templateObject.setBalancedTerminationFlag(真);
更新
package com.softlayer.api.ScaleGroup;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Account;
import com.softlayer.api.service.Location;
import com.softlayer.api.service.network.Vlan;
import com.softlayer.api.service.scale.Group;
import java.util.ArrayList;
import java.util.List;
/**
* This script Get Vlans as Control Portal does
*
* Important Manual Pages:
* http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkVlans
*
* @license <http://sldn.softlayer.com/article/License>
* @authon SoftLayer Technologies, Inc. <[email protected]>
* @version 0.2.2 (master branch)
*/
public class GetVlans {
List<Vlan> publicVlans = new ArrayList<Vlan>();
List<Vlan> privateVlans = new ArrayList<Vlan>();
public GetVlans()
{
// Define your SoftLayer's username and apiKey
String username = "set me";
String apiKey = "set me";
/**
* Define Region as Control Portal and datacenter name
* e.g. for datacenter: dal05, dal06, dal09, lon02 or First Available (This option get all vlans from datacenter from the region)
*/
String region = "na-usa-central-1";
String datacenter = "First Available";
// Set privateNetworkOnly and preserverBalanceAcrossVLANsOnDownscale flags
boolean privateNetworkOnly = false;
boolean preserverBalanceAcrossVLANsOnDownscale = false;
// Create client and services
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
Account.Service accountService = Account.service(client);
Group.Service groupService = Group.service(client);
com.softlayer.api.service.location.Group.Service locationService;
// Define Object Masks to get additional properties
accountService.withMask().networkVlans().subnets();
accountService.withMask().networkVlans().billingItem();
accountService.withMask().networkVlans().networkSpace();
accountService.withMask().networkVlans().primaryRouter();
accountService.withMask().networkVlans().primaryRouter().datacenter();
accountService.withMask().networkVlans().primaryRouter().datacenter().groups();
accountService.withMask().networkVlans().localDiskStorageCapabilityFlag();
accountService.withMask().networkVlans().sanStorageCapabilityFlag();
// Define init parameter for locationService
locationService = com.softlayer.api.service.location.Group.service(client, getRegionalGroupId(groupService, region));
try {
/**
* Getting Vlans
*/
if(datacenter == "First Available")
{
for(Location location : locationService.getLocations())
{
getVlans(accountService, groupService, region, preserverBalanceAcrossVLANsOnDownscale, location.getName());
printVlans(privateNetworkOnly);
}
}else{
getVlans(accountService, groupService, region, preserverBalanceAcrossVLANsOnDownscale, datacenter);
printVlans(privateNetworkOnly);
}
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
/**
* Retrieves rion identifier
* @param region string
* @return region identifier
*/
public Long getRegionalGroupId(Group.Service groupService, String region)
{
Long regionId = new Long(0);
for(com.softlayer.api.service.location.Group regionalGroup : groupService.getAvailableRegionalGroups())
{
if(regionalGroup.getName().equals(region))
{
regionId = regionalGroup.getId();
}
}
return regionId;
}
/**
*
* @param accountService Account Service
* @param groupService Group Service
* @param region Define the region for the vlans
* @param preserverBalanceAcrossVLANsOnDownscale Flag to get own vlans
* @param location The location to get vlans
*/
public void getVlans(Account.Service accountService, Group.Service groupService, String region, boolean preserverBalanceAcrossVLANsOnDownscale, String location)
{
publicVlans = new ArrayList<Vlan>();
privateVlans = new ArrayList<Vlan>();
System.out.println("Datacenter: " + location);
for(Vlan vlan : accountService.getObject().getNetworkVlans()) {
if (vlan.getPrimaryRouter().getDatacenter().getName().equals(location)) {
for (com.softlayer.api.service.location.Group group : vlan.getPrimaryRouter().getDatacenter().getGroups()) {
if (group.getId() == getRegionalGroupId(groupService, region)) {
if (vlan.getNetworkSpace().equals("PUBLIC")) {
if (preserverBalanceAcrossVLANsOnDownscale) {
if (vlan.getBillingItem() != null) {
publicVlans.add(vlan);
}
} else {
publicVlans.add(vlan);
}
} else {
if (vlan.getBillingItem() != null) {
privateVlans.add(vlan);
} else {
privateVlans.add(vlan);
}
}
}
}
}
}
}
/**
* Print Vlans
* @param privateNetworkOnly PrivateNetworkOnly flag, to get only private vlans
*/
public void printVlans(boolean privateNetworkOnly)
{
if(!privateNetworkOnly)
{
System.out.println("PUBLIC");
for(Vlan vlan : publicVlans)
{
System.out.println("Id: " + vlan.getId() + " Vlan Number: " + vlan.getVlanNumber() + " Router: " + vlan.getPrimaryRouter().getHostname() +
" SAN: " + vlan.getSanStorageCapabilityFlag() + " LOCAL: " + vlan.getLocalDiskStorageCapabilityFlag());
}
}
System.out.println("PRIVATE");
for(Vlan vlan : privateVlans)
{
System.out.println("Id: " + vlan.getId() + " Vlan Number: " + vlan.getVlanNumber() + " Router: " + vlan.getPrimaryRouter().getHostname() +
" SAN: " + vlan.getSanStorageCapabilityFlag() + " LOCAL: " + vlan.getLocalDiskStorageCapabilityFlag());
}
}
public static void main(String []args)
{
new GetVlans();
}
}
我連着Java腳本獲得VLAN以作爲控制門戶做,因爲我認爲你正在試圖自動縮放組。我希望它有幫助。
我附上了一個腳本來獲取vlans –