/** * Returns hosts associated with a given OpenStack network. * * @param vNet openstack network * @return set of hosts */ private Set<Host> getHostsWithOpenstackNetwork(OpenstackNetwork vNet) { checkNotNull(vNet); Set<Host> hosts = openstackService .ports(vNet.id()) .stream() .filter(port -> port.deviceOwner().contains("compute")) .map( port -> hostService.getHostsByMac(port.macAddress()).stream().findFirst().orElse(null)) .collect(Collectors.toSet()); hosts.remove(null); return hosts; }
/** * Returns CordService by OpenStack network. * * @param vNet OpenStack network * @return cord service */ private CordService getCordService(OpenstackNetwork vNet) { checkNotNull(vNet); CordServiceId serviceId = CordServiceId.of(vNet.id()); OpenstackSubnet subnet = vNet.subnets().stream().findFirst().orElse(null); if (subnet == null) { log.warn("Couldn't find OpenStack subnet for service {}", serviceId); return null; } Set<CordServiceId> tServices = Sets.newHashSet(); // TODO get tenant services from XOS Map<Host, IpAddress> hosts = getHostsWithOpenstackNetwork(vNet) .stream() .collect(Collectors.toMap(host -> host, this::getTunnelIp)); return new CordService(vNet, subnet, hosts, tServices); }