答案 0 :(得分:0)
下面的代码将列出所有VLAN,然后您需要过滤数据。您将注意到以下对象掩码mask[primaryRouter[datacenter[groups]], networkSpace]
“networkSpace”指定VLAN是公共VLAN还是私有VLAN,因此使用过滤器来获取所有私有VLAN。
掩码primaryRouter[datacenter[groups]
将返回VLAN可用的数据中心,因此根据所选区域或数据中心,您需要过滤数据以显示对该区域或数据中心有效的VLAN。
您可以使用此方法获取数据中心及其组http://sldn.softlayer.com/reference/services/SoftLayer_Location/getDatacenters
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Account;
import com.google.gson.Gson;
public class VlanScale {
private static String user = "set me";
private static String apiKey = "set me";
private static ApiClient client = new RestApiClient().withCredentials(user, apiKey);
public static void main(String[] args) {
// Declare the API client
ApiClient client = new RestApiClient().withCredentials(user, apiKey);
Account.Service accountService = Account.service(client);
accountService.setMask("mask[primaryRouter[datacenter[groups]], networkSpace]");
// Send the request to get the VLANs and print the result
try {
Gson gson = new Gson();
System.out.println(gson.toJson(accountService.getNetworkVlans()));
} catch (Exception e) {
System.out.println("Unable to retrieve the VLANs. "
+ e.getMessage());
}
}
}
此致