use of org.onosproject.openstacknode.api.OpenstackNodeService in project onos by opennetworkinglab.
the class OpenstackComputeNodeCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
Set<String> hostnames = osNodeService.completeNodes(COMPUTE).stream().map(OpenstackNode::hostname).collect(Collectors.toSet());
SortedSet<String> strings = delegate.getStrings();
strings.addAll(hostnames);
return delegate.complete(session, commandLine, candidates);
}
use of org.onosproject.openstacknode.api.OpenstackNodeService in project onos by opennetworkinglab.
the class OpenstackConfigStatefulSnatCommand method syncRules.
private void syncRules() {
// All handlers in this application reacts the node complete event and
// tries to re-configure flow rules for the complete node.
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
OpenstackNodeAdminService osNodeAdminService = get(OpenstackNodeAdminService.class);
if (osNodeService == null) {
error("Failed to re-install flow rules for OpenStack networking.");
return;
}
osNodeService.completeNodes().forEach(osNode -> {
OpenstackNode updated = osNode.updateState(NodeState.INIT);
osNodeAdminService.updateNode(updated);
});
}
use of org.onosproject.openstacknode.api.OpenstackNodeService in project onos by opennetworkinglab.
the class OpenstackDiffStateCommand method doExecute.
@Override
protected void doExecute() {
OpenstackSecurityGroupAdminService osSgService = get(OpenstackSecurityGroupAdminService.class);
OpenstackNetworkAdminService osNetService = get(OpenstackNetworkAdminService.class);
OpenstackRouterAdminService osRouterService = get(OpenstackRouterAdminService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
Map<String, String> headerMap = new HashMap<>();
headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
Optional<OpenstackNode> node = osNodeService.nodes(CONTROLLER).stream().findFirst();
if (!node.isPresent()) {
error("Keystone auth info has not been configured. " + "Please specify auth info via network-cfg.json.");
return;
}
OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
if (osClient == null) {
return;
}
if (!clear) {
show = true;
}
if (show && clear) {
error("Either --show (-s) or --clear (-c) option should be specified.");
}
if (show) {
print("\nComparing OpenStack floating IPs");
} else if (clear) {
print("\nClearing OpenStack floating IPs");
}
Set<String> cachedFips = osRouterService.floatingIps().stream().map(NetFloatingIP::getId).collect(Collectors.toSet());
Set<String> osFips = osClient.headers(headerMap).networking().floatingip().list().stream().map(NetFloatingIP::getId).collect(Collectors.toSet());
print(FLOATING_IP_FORMAT, "ID", "Floating IP", "Fixed IP");
getDiff(cachedFips, osFips).forEach(fipId -> {
printFloatingIp(osRouterService.floatingIp(fipId));
if (clear) {
osRouterService.removeFloatingIp(fipId);
}
});
Set<String> cachedPorts = osNetService.ports().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osPorts = osClient.headers(headerMap).networking().port().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
if (show) {
print("\nComparing OpenStack router interfaces");
} else if (clear) {
print("\nClearing OpenStack router interfaces");
}
print(ROUTER_INTF_FORMAT, "ID", "Tenant ID", "Subnet ID");
getDiff(cachedPorts, osPorts).forEach(portId -> {
RouterInterface ri = osRouterService.routerInterface(portId);
if (ri != null) {
printRouterIntf(ri);
if (clear) {
osRouterService.removeRouterInterface(portId);
}
}
});
if (show) {
print("\nComparing OpenStack ports");
} else if (clear) {
print("\nClearing OpenStack ports");
}
print(PORT_FORMAT, "ID", "Network", "MAC", "Fixed IPs");
getDiff(cachedPorts, osPorts).forEach(portId -> {
printPort(osNetService.port(portId), osNetService);
if (clear) {
osNetService.removePort(portId);
}
});
if (show) {
print("\nComparing OpenStack routers");
} else if (clear) {
print("\nClearing OpenStack routers");
}
Set<String> cachedRouters = osRouterService.routers().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osRouters = osClient.headers(headerMap).networking().router().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(ROUTER_FORMAT, "ID", "Name", "External", "Internal");
getDiff(cachedRouters, osRouters).forEach(routerId -> {
printRouter(osRouterService.router(routerId), osNetService);
if (clear) {
osRouterService.removeRouter(routerId);
}
});
if (show) {
print("\nComparing OpenStack subnets");
} else if (clear) {
print("\nClearing OpenStack subnets");
}
Set<String> cachedSubnets = osNetService.subnets().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osSubnets = osClient.headers(headerMap).networking().subnet().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(SUBNET_FORMAT, "ID", "Network", "CIDR");
getDiff(cachedSubnets, osSubnets).forEach(subnetId -> {
printSubnet(osNetService.subnet(subnetId), osNetService);
if (clear) {
osNetService.removeSubnet(subnetId);
}
});
if (show) {
print("\nComparing OpenStack networks");
} else if (clear) {
print("\nClearing OpenStack networks");
}
Set<String> cachedNets = osNetService.networks().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osNets = osClient.headers(headerMap).networking().network().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(NETWORK_FORMAT, "ID", "Name", "VNI", "Subnets");
getDiff(cachedNets, osNets).forEach(netId -> {
printNetwork(osNetService.network(netId));
if (clear) {
osNetService.removeNetwork(netId);
}
});
if (show) {
print("\nComparing OpenStack security groups");
} else if (clear) {
print("\nClearing OpenStack security groups");
}
Set<String> cachedSgs = osSgService.securityGroups().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osSgs = osClient.headers(headerMap).networking().securitygroup().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(SECURITY_GROUP_FORMAT, "ID", "Name");
getDiff(cachedSgs, osSgs).forEach(sgId -> {
printSecurityGroup(osSgService.securityGroup(sgId));
if (clear) {
osSgService.removeSecurityGroup(sgId);
}
});
}
use of org.onosproject.openstacknode.api.OpenstackNodeService in project onos by opennetworkinglab.
the class OpenstackSyncStateCommand method doExecute.
@Override
protected void doExecute() {
OpenstackSecurityGroupAdminService osSgAdminService = get(OpenstackSecurityGroupAdminService.class);
OpenstackNetworkAdminService osNetAdminService = get(OpenstackNetworkAdminService.class);
OpenstackRouterAdminService osRouterAdminService = get(OpenstackRouterAdminService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
Map<String, String> headerMap = new HashMap<>();
headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
Optional<OpenstackNode> node = osNodeService.nodes(CONTROLLER).stream().findFirst();
if (!node.isPresent()) {
error("Keystone auth info has not been configured. " + "Please specify auth info via network-cfg.json.");
return;
}
OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
if (osClient == null) {
return;
}
print("Synchronizing OpenStack security groups");
print(SECURITY_GROUP_FORMAT, "ID", "Name");
osClient.headers(headerMap).networking().securitygroup().list().forEach(osSg -> {
if (osSgAdminService.securityGroup(osSg.getId()) != null) {
osSgAdminService.updateSecurityGroup(osSg);
} else {
osSgAdminService.createSecurityGroup(osSg);
}
printSecurityGroup(osSg);
});
print("\nSynchronizing OpenStack networks");
print(NETWORK_FORMAT, "ID", "Name", "VNI", "Subnets");
osClient.headers(headerMap).networking().network().list().forEach(osNet -> {
if (osNetAdminService.network(osNet.getId()) != null) {
osNetAdminService.updateNetwork(osNet);
} else {
osNetAdminService.createNetwork(osNet);
}
printNetwork(osNet);
});
print("\nSynchronizing OpenStack subnets");
print(SUBNET_FORMAT, "ID", "Network", "CIDR");
osClient.headers(headerMap).networking().subnet().list().forEach(osSubnet -> {
if (osNetAdminService.subnet(osSubnet.getId()) != null) {
osNetAdminService.updateSubnet(osSubnet);
} else {
osNetAdminService.createSubnet(osSubnet);
}
printSubnet(osSubnet, osNetAdminService);
});
print("\nSynchronizing OpenStack ports");
print(PORT_FORMAT, "ID", "Network", "MAC", "Fixed IPs");
osClient.headers(headerMap).networking().port().list().forEach(osPort -> {
if (osNetAdminService.port(osPort.getId()) != null) {
osNetAdminService.updatePort(osPort);
} else {
osNetAdminService.createPort(osPort);
}
printPort(osPort, osNetAdminService);
});
print("\nSynchronizing OpenStack routers");
print(ROUTER_FORMAT, "ID", "Name", "External", "Internal");
osClient.headers(headerMap).networking().router().list().forEach(osRouter -> {
if (osRouterAdminService.router(osRouter.getId()) != null) {
osRouterAdminService.updateRouter(osRouter);
} else {
osRouterAdminService.createRouter(osRouter);
}
// FIXME do we need to manage router interfaces separately?
osNetAdminService.ports().stream().filter(osPort -> Objects.equals(osPort.getDeviceId(), osRouter.getId()) && Objects.equals(osPort.getDeviceOwner(), DEVICE_OWNER_IFACE)).forEach(osPort -> addRouterIface(osPort, osRouterAdminService));
printRouter(osRouter, osNetAdminService);
});
print("\nSynchronizing OpenStack floating IPs");
print(FLOATING_IP_FORMAT, "ID", "Floating IP", "Fixed IP");
osClient.headers(headerMap).networking().floatingip().list().forEach(osFloating -> {
if (osRouterAdminService.floatingIp(osFloating.getId()) != null) {
osRouterAdminService.updateFloatingIp(osFloating);
} else {
osRouterAdminService.createFloatingIp(osFloating);
}
printFloatingIp(osFloating);
});
}
use of org.onosproject.openstacknode.api.OpenstackNodeService in project onos by opennetworkinglab.
the class OpenstackNodeCheckCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
DeviceService deviceService = get(DeviceService.class);
OpenstackNode osNode = osNodeService.node(hostname);
if (osNode == null) {
print("Cannot find %s from registered nodes", hostname);
return;
}
if (osNode.type() == CONTROLLER) {
print("[Openstack Controller Status]");
OSClient client = getConnectedClient(osNode);
if (client == null) {
error("The given keystone info is incorrect to get authorized to openstack");
print("keystoneConfig=%s", osNode.keystoneConfig());
}
if (osNode.keystoneConfig() != null) {
print("%s keystoneConfig=%s, neutronConfig=%s", osNode.state() == NodeState.COMPLETE && client != null ? MSG_OK : MSG_ERROR, osNode.keystoneConfig(), osNode.neutronConfig());
} else {
print("%s keystoneConfig is missing", MSG_ERROR);
}
} else {
print("[Integration Bridge Status]");
Device device = deviceService.getDevice(osNode.intgBridge());
Device ovsdbDevice = deviceService.getDevice(osNode.ovsdb());
if (device != null) {
print("%s OvsdbDeviceId=%s available=%s", deviceService.isAvailable(ovsdbDevice.id()) ? MSG_OK : MSG_ERROR, ovsdbDevice.id(), deviceService.isAvailable(ovsdbDevice.id()));
print("%s %s=%s available=%s %s", deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR, INTEGRATION_BRIDGE, device.id(), deviceService.isAvailable(device.id()), device.annotations());
if (osNode.dataIp() != null) {
printPortState(deviceService, osNode.intgBridge(), VXLAN_TUNNEL);
printPortState(deviceService, osNode.intgBridge(), GRE_TUNNEL);
printPortState(deviceService, osNode.intgBridge(), GENEVE_TUNNEL);
}
if (osNode.vlanIntf() != null) {
printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
}
osNode.phyIntfs().forEach(intf -> {
printPortState(deviceService, osNode.intgBridge(), structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + intf.network()));
});
if (osNode.type() == GATEWAY) {
printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
}
} else {
print("%s %s=%s is not available", MSG_ERROR, INTEGRATION_BRIDGE, osNode.intgBridge());
}
}
}
Aggregations