use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.
the class OpenstackDirectPortAddCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
DeviceService deviceService = get(DeviceService.class);
Port port = osNetService.port(portId);
if (port == null) {
log.error("There's no port that matches the port ID {}", portId);
return;
}
Optional<OpenstackNode> osNode = osNodeService.completeNodes(COMPUTE).stream().filter(node -> node.hostname().equals(port.getHostId())).findAny();
if (!osNode.isPresent()) {
log.error("There's no openstackNode that matches hostname {}", port.getHostId());
return;
}
String intfName = getIntfNameFromPciAddress(port);
if (intfName == null) {
log.error("Failed to retrieve interface name from a port {}", portId);
return;
} else if (intfName.equals(UNSUPPORTED_VENDOR)) {
return;
}
if (OpenstackNetworkingUtil.hasIntfAleadyInDevice(osNode.get().intgBridge(), intfName, deviceService)) {
log.error("Interface {} is already added to the device {}", osNode.get().intgBridge());
return;
}
log.info("Adding interface {} to the device {}..", intfName, osNode.get().intgBridge());
osNodeService.addVfPort(osNode.get(), intfName);
}
use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.
the class OpenstackDirectPortListCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService service = get(OpenstackNetworkService.class);
List<Port> ports = service.ports().stream().filter(port -> port.getvNicType().equals(DIRECT)).collect(Collectors.toList());
print(FORMAT, "ID", "Network", "MAC", "FIXED IPs", "PCI Slot", "Interface");
for (Port port : ports) {
List<String> fixedIps = port.getFixedIps().stream().map(IP::getIpAddress).collect(Collectors.toList());
Network osNet = service.network(port.getNetworkId());
if (port.getVifType().equals(UNBOUND)) {
print(FORMAT, port.getId(), deriveResourceName(osNet), port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps, UNBOUND, UNBOUND);
} else {
print(FORMAT, port.getId(), deriveResourceName(osNet), port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps, port.getProfile().containsKey(PCISLOT) ? port.getProfile().get(PCISLOT).toString() : "", getIntfNameFromPciAddress(port));
}
}
}
use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.
the class OpenstackPortListCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService service = get(OpenstackNetworkService.class);
List<Port> ports = Lists.newArrayList(service.ports());
ports.sort(Comparator.comparing(Port::getNetworkId));
if (!Strings.isNullOrEmpty(networkId)) {
ports.removeIf(port -> !port.getNetworkId().equals(networkId));
}
if (outputJson()) {
print("%s", json(ports));
} else {
print(FORMAT, "ID", "Network", "MAC", "Fixed IPs");
for (Port port : ports) {
List<String> fixedIps = port.getFixedIps().stream().map(IP::getIpAddress).collect(Collectors.toList());
Network osNet = service.network(port.getNetworkId());
String netName = osNet == null ? "N/A" : deriveResourceName(osNet);
print(FORMAT, port.getId(), netName, port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps);
}
}
}
use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.
the class OpenstackRecoverPortsCommand method doExecute.
@Override
protected void doExecute() {
OvsdbController controller = get(OvsdbController.class);
OpenstackNodeService nodeService = get(OpenstackNodeService.class);
OpenstackNetworkService networkService = get(OpenstackNetworkService.class);
DeviceService deviceService = get(DeviceService.class);
if (isAll) {
hostnames = nodeService.completeNodes().stream().map(OpenstackNode::hostname).toArray(String[]::new);
}
if (hostnames == null) {
print("Please specify one of hostname or --all options.");
return;
}
for (String hostname : hostnames) {
networkService.ports().forEach(p -> {
if (hostname.equals(p.getHostId())) {
OpenstackNode osNode = nodeService.node(p.getHostId());
if (osNode != null) {
Set<String> recoveredPortNames = recoverOvsPort(controller, OVS_DB_PORT, osNode, p, deviceService.getPorts(osNode.intgBridge()));
recoveredPortNames.forEach(pn -> print(pn + " is recovered!"));
}
}
});
}
}
use of org.onosproject.openstacknetworking.api.OpenstackNetworkService in project onos by opennetworkinglab.
the class OpenstackVmStatsCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
InstancePortService osInstanceService = get(InstancePortService.class);
DeviceService deviceService = get(DeviceService.class);
Set<Port> ports = osNetService.ports().stream().filter(port -> port.getDeviceId().equals(vmDeviceId)).collect(Collectors.toSet());
if (ports.isEmpty()) {
print(NO_PORTS);
return;
}
Set<InstancePort> instancePorts = getInstancePortFromNeutronPortList(ports, osInstanceService);
if (instancePorts.isEmpty()) {
print(NO_INSTANCE_PORTS);
return;
}
Set<PortNumber> portNumbers = instancePorts.stream().map(InstancePort::portNumber).collect(Collectors.toSet());
instancePorts.stream().findAny().ifPresent(instancePort -> {
DeviceId deviceId = instancePort.deviceId();
if (delta) {
printPortStatsDelta(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
if (table) {
printPortStatsDeltaTable(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
}
} else {
printPortStats(vmDeviceId, deviceService.getPortStatistics(deviceId), portNumbers);
}
});
}
Aggregations