Search in sources :

Example 1 with OpenstackRouterService

use of org.onosproject.openstacknetworking.api.OpenstackRouterService in project onos by opennetworkinglab.

the class OpenstackFloatingIpListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackRouterService service = get(OpenstackRouterService.class);
    List<NetFloatingIP> floatingIps = Lists.newArrayList(service.floatingIps());
    floatingIps.sort(Comparator.comparing(NetFloatingIP::getFloatingIpAddress));
    if (outputJson()) {
        print("%s", json(floatingIps));
    } else {
        print(FORMAT, "ID", "Floating IP", "Fixed IP");
        for (NetFloatingIP floatingIp : floatingIps) {
            print(FORMAT, floatingIp.getId(), floatingIp.getFloatingIpAddress(), Strings.isNullOrEmpty(floatingIp.getFixedIpAddress()) ? "" : floatingIp.getFixedIpAddress());
        }
    }
}
Also used : NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService)

Example 2 with OpenstackRouterService

use of org.onosproject.openstacknetworking.api.OpenstackRouterService in project onos by opennetworkinglab.

the class UpdateExternalPeerRouterVlanCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkAdminService osNetAdminService = get(OpenstackNetworkAdminService.class);
    OpenstackRouterService osRouterService = get(OpenstackRouterService.class);
    IpAddress externalPeerIpAddress = IpAddress.valueOf(IpAddress.Version.INET, Ip4Address.valueOf(ipAddress).toOctets());
    if (osNetAdminService.externalPeerRouters().isEmpty()) {
        print(NO_ELEMENT);
        return;
    } else if (osNetAdminService.externalPeerRouters().stream().noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
        print(NO_ELEMENT);
        return;
    }
    Subnet subnet = osNetAdminService.subnets().stream().filter(s -> s.getGateway().equals(ipAddress)).findAny().orElse(null);
    if (subnet == null) {
        return;
    }
    Network network = osNetAdminService.network(subnet.getNetworkId());
    if (network == null) {
        return;
    }
    Router router = osRouterService.routers().stream().filter(r -> r.getExternalGatewayInfo().getNetworkId().equals(network.getId())).findAny().orElse(null);
    if (router == null) {
        return;
    }
    try {
        if (vlanId.equals(NONE)) {
            osNetAdminService.updateExternalPeerRouterVlan(externalPeerIpAddress, VlanId.NONE);
            osNetAdminService.deriveExternalPeerRouterMac(router.getExternalGatewayInfo(), router, VlanId.NONE);
        } else {
            osNetAdminService.updateExternalPeerRouterVlan(externalPeerIpAddress, VlanId.vlanId(vlanId));
            osNetAdminService.deriveExternalPeerRouterMac(router.getExternalGatewayInfo(), router, VlanId.vlanId(vlanId));
        }
    } catch (IllegalArgumentException e) {
        log.error("Exception occurred because of {}", e.toString());
    }
    print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
    List<ExternalPeerRouter> routers = Lists.newArrayList(osNetAdminService.externalPeerRouters());
    for (ExternalPeerRouter r : routers) {
        print(FORMAT, r.ipAddress(), r.macAddress().toString(), r.vlanId());
    }
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) Network(org.openstack4j.model.network.Network) VlanId(org.onlab.packet.VlanId) Argument(org.apache.karaf.shell.api.action.Argument) Subnet(org.openstack4j.model.network.Subnet) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists(com.google.common.collect.Lists) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Router(org.openstack4j.model.network.Router) Completion(org.apache.karaf.shell.api.action.Completion) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Network(org.openstack4j.model.network.Network) Router(org.openstack4j.model.network.Router) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) Subnet(org.openstack4j.model.network.Subnet) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService)

Aggregations

OpenstackRouterService (org.onosproject.openstacknetworking.api.OpenstackRouterService)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Completion (org.apache.karaf.shell.api.action.Completion)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 Ip4Address (org.onlab.packet.Ip4Address)1 IpAddress (org.onlab.packet.IpAddress)1 VlanId (org.onlab.packet.VlanId)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 AbstractShellCommand.get (org.onosproject.cli.AbstractShellCommand.get)1 ExternalPeerRouter (org.onosproject.openstacknetworking.api.ExternalPeerRouter)1 OpenstackNetworkAdminService (org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)1 NetFloatingIP (org.openstack4j.model.network.NetFloatingIP)1 Network (org.openstack4j.model.network.Network)1 Router (org.openstack4j.model.network.Router)1 Subnet (org.openstack4j.model.network.Subnet)1