直接上代码
//获取连接
OSClientV3 os=getOSClientV3(tenantid,user_id,password,region);
//获取网络服务
NetworkingService ns = os.networking();
//获取路由
List<? extends Router> routerList = ns.router().list();
//遍历路由
if(routerList != null){
for(Router r : routerList){
//通过网卡查询外部网关
ExternalGateway eg = r.getExternalGatewayInfo();
//根据路由ID查询网卡信息
PortListOptions plo = PortListOptions.create();
plo.deviceId(r.getId());
String netWorkid = eg.getNetworkId();
plo.networkId(netWorkid);
//使用此网卡的实体类型
plo.deviceOwner("network:router_gateway");
List<? extends Port> portList = ns.port().list(plo);
---todo,遍历即可获取外部网卡信息
}
}