use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.
the class OpenstackRouterListCommand method getRouterIfaceIp.
private String getRouterIfaceIp(RouterInterface iface) {
Port osPort = netService.port(iface.getPortId());
IP ipAddr = osPort.getFixedIps().stream().filter(ip -> ip.getSubnetId().equals(iface.getSubnetId())).findAny().orElse(null);
return ipAddr == null ? "" : ipAddr.getIpAddress();
}
use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.
the class OpenstackRouterListCommand method doExecute.
@Override
protected void doExecute() {
List<Router> routers = Lists.newArrayList(routerService.routers());
routers.sort(Comparator.comparing(Router::getId));
if (outputJson()) {
print("%s", json(routers));
} else {
print(FORMAT, "ID", "Name", "External", "Internal");
for (Router router : routers) {
String exNetId = router.getExternalGatewayInfo() != null ? router.getExternalGatewayInfo().getNetworkId() : null;
List<String> externals = Lists.newArrayList();
if (exNetId != null) {
// FIXME fix openstack4j to provide external gateway ip info
externals = netService.ports(exNetId).stream().filter(port -> Objects.equals(port.getDeviceId(), router.getId())).flatMap(port -> port.getFixedIps().stream()).map(IP::getIpAddress).collect(Collectors.toList());
}
List<String> internals = Lists.newArrayList();
routerService.routerInterfaces(router.getId()).forEach(iface -> {
internals.add(getRouterIfaceIp(iface));
});
print(FORMAT, router.getId(), deriveResourceName(router), externals, internals);
}
}
}
use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.
the class OpenstackNetworkManager method getExternalGatewaySourceIp.
private IpAddress getExternalGatewaySourceIp(ExternalGateway externalGateway, Router router) {
Port exGatewayPort = ports(externalGateway.getNetworkId()).stream().filter(port -> Objects.equals(port.getDeviceId(), router.getId())).findAny().orElse(null);
if (exGatewayPort == null) {
log.warn("no external gateway port for router({})", deriveResourceName(router));
return null;
}
IP ipAddress = exGatewayPort.getFixedIps().stream().findFirst().orElse(null);
return ipAddress == null ? null : IpAddress.valueOf(ipAddress.getIpAddress());
}
use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.
the class OpenstackNetworkManager method gatewayIp.
@Override
public String gatewayIp(String portId) {
checkNotNull(portId);
Port port = port(portId);
checkNotNull(port);
IpAddress ipAddress = port.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).findAny().orElse(null);
checkNotNull(ipAddress);
Network network = network(port.getNetworkId());
checkNotNull(network);
return subnets(network.getId()).stream().filter(s -> IpPrefix.valueOf(s.getCidr()).contains(ipAddress)).map(Subnet::getGateway).findAny().orElse(null);
}
use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.
the class OpenstackNetworkManager method ipPrefix.
@Override
public IpPrefix ipPrefix(String portId) {
checkNotNull(portId);
Port port = port(portId);
checkNotNull(port);
IpAddress ipAddress = port.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).findAny().orElse(null);
checkNotNull(ipAddress);
Network network = network(port.getNetworkId());
checkNotNull(network);
return subnets(network.getId()).stream().map(s -> IpPrefix.valueOf(s.getCidr())).filter(prefix -> prefix.contains(ipAddress)).findAny().orElse(null);
}
Aggregations