public void removeDuplicates(HostId hostId, HostDescription desc) { desc.ipAddress().forEach(ip -> { Set<Host> allHosts = store.getHosts(ip); allHosts.forEach(eachHost -> { if (!(eachHost.id().equals(hostId))) { log.info("Duplicate ip {} found on host {} and {}", ip, hostId.toString(), eachHost.id().toString()); store.removeIp(eachHost.id(), ip); } }); }); }
private Collection<Intent> generateIntents() { List<Host> hosts = Lists.newArrayList(hostService.getHosts()); List<Intent> fullMesh = Lists.newArrayList(); for (int i = 0; i < hosts.size(); i++) { for (int j = i + 1; j < hosts.size(); j++) { fullMesh.add(HostToHostIntent.builder() .appId(appId()) .one(hosts.get(i).id()) .two(hosts.get(j).id()) .build()); } } Collections.shuffle(fullMesh); return fullMesh.subList(0, Math.min(count, fullMesh.size())); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); HostService service = AbstractShellCommand.get(HostService.class); Iterator<Host> it = service.getHosts().iterator(); SortedSet<String> strings = delegate.getStrings(); while (it.hasNext()) { strings.add(it.next().id().toString()); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
@Override public void event(HostEvent event) { HostId id = event.subject().id(); switch (event.type()) { case HOST_ADDED: case HOST_MOVED: case HOST_REMOVED: executorService.execute(new DeviceAvailabilityHandler(id, false)); break; case HOST_UPDATED: default: // DO NOTHING break; } } }
private void wipeOutHosts() { print("Wiping hosts"); HostAdminService hostAdminService = get(HostAdminService.class); while (hostAdminService.getHostCount() > 0) { try { for (Host host : hostAdminService.getHosts()) { hostAdminService.removeHost(host.id()); } } catch (Exception e) { log.info("Unable to wipe-out hosts", e); } } }
@Override public ObjectNode encode(Host host, CodecContext context) { checkNotNull(host, "Host cannot be null"); final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class); final ObjectNode result = context.mapper().createObjectNode() .put("id", host.id().toString()) .put("mac", host.mac().toString()) .put("vlan", host.vlan().toString()) .put("innerVlan", host.innerVlan().toString()) .put("outerTpid", host.tpid().toString()) .put("configured", host.configured()); final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); for (final IpAddress ipAddress : host.ipAddresses()) { jsonIpAddresses.add(ipAddress.toString()); } result.set("ipAddresses", jsonIpAddresses); final ArrayNode jsonLocations = result.putArray("locations"); for (final HostLocation location : host.locations()) { jsonLocations.add(locationCodec.encode(location, context)); } result.set("locations", jsonLocations); return annotate(result, host, context); }
@Override public void modifyHostDetails(PropertyPanel pp, HostId hostId) { pp.title(MY_HOST_TITLE); pp.removeAllProps(); PortPairService portPairService = AbstractShellCommand.get(PortPairService.class); VirtualPortService virtualPortService = AbstractShellCommand.get(VirtualPortService.class); HostService hostService = AbstractShellCommand.get(HostService.class); Iterable<PortPair> portPairs = portPairService.getPortPairs(); for (PortPair portPair : portPairs) { VirtualPort vPort = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())); MacAddress dstMacAddress = vPort.macAddress(); Host host = hostService.getHost(HostId.hostId(dstMacAddress)); if (hostId.toString().equals(host.id().toString())) { pp.addProp("SF Name", portPair.name()); pp.addProp("SF Ip", vPort.fixedIps().iterator().next().ip()); } } pp.addProp("SF host Address", hostId.toString()); }
/** * Prints information about a host. * * @param host end-station host */ protected void printHost(Host host) { if (shortOnly) { print(FMT_SHORT, host.id(), host.mac(), host.locations(), host.vlan(), host.ipAddresses()); } else { print(FMT, host.id(), host.mac(), host.locations(), host.vlan(), host.ipAddresses(), annotations(host.annotations()), host.innerVlan(), host.tpid().toString(), host.providerId().scheme(), host.providerId().id(), host.configured()); } } }
HostHighlight hSrc = new HostHighlight(srcHost.id().toString()); hSrc.setBadge(NodeBadge.text("SRC")); String sfcPath = "SRC -> "; HostHighlight hhDst = new HostHighlight(host.id().toString()); hhDst.setBadge(NodeBadge.text(portPair.name())); sfcPath = sfcPath + portPair.name() + "(" + vPort.fixedIps().iterator().next().ip() + ") -> "; .macAddress(); Host hostSrc = hostService.getHost(HostId.hostId(srcMacAddress)); HostHighlight hhSrc = new HostHighlight(hostSrc.id().toString()); hhSrc.setBadge(NodeBadge.text(portPair.name())); highlights.add(hhSrc); HostHighlight hDst = new HostHighlight(dstHost.id().toString()); hDst.setBadge(NodeBadge.text("DST")); sfcPath = sfcPath + "DST";