Search in sources :

Example 6 with OpenstackNetworkAdminService

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

the class UpdateExternalPeerRouterCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkAdminService service = get(OpenstackNetworkAdminService.class);
    IpAddress externalPeerIpAddress = IpAddress.valueOf(IpAddress.Version.INET, Ip4Address.valueOf(ipAddress).toOctets());
    if (service.externalPeerRouters().isEmpty()) {
        print(NO_ELEMENT);
        return;
    } else if (service.externalPeerRouters().stream().noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
        print(NO_ELEMENT);
        return;
    }
    try {
        if (vlanId.equals(NONE)) {
            service.updateExternalPeerRouter(externalPeerIpAddress, MacAddress.valueOf(macAddress), VlanId.NONE);
        } else {
            service.updateExternalPeerRouter(externalPeerIpAddress, MacAddress.valueOf(macAddress), 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(service.externalPeerRouters());
    for (ExternalPeerRouter router : routers) {
        print(FORMAT, router.ipAddress(), router.macAddress().toString(), router.vlanId());
    }
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) VlanId(org.onlab.packet.VlanId) Argument(org.apache.karaf.shell.api.action.Argument) 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) Completion(org.apache.karaf.shell.api.action.Completion) MacAddress(org.onlab.packet.MacAddress) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)

Aggregations

OpenstackNetworkAdminService (org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)6 Command (org.apache.karaf.shell.api.action.Command)4 Service (org.apache.karaf.shell.api.action.lifecycle.Service)4 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)4 Argument (org.apache.karaf.shell.api.action.Argument)3 Completion (org.apache.karaf.shell.api.action.Completion)3 AbstractShellCommand.get (org.onosproject.cli.AbstractShellCommand.get)3 ExternalPeerRouter (org.onosproject.openstacknetworking.api.ExternalPeerRouter)3 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)3 Lists (com.google.common.collect.Lists)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 Ip4Address (org.onlab.packet.Ip4Address)2 IpAddress (org.onlab.packet.IpAddress)2 VlanId (org.onlab.packet.VlanId)2 OpenstackRouterAdminService (org.onosproject.openstacknetworking.api.OpenstackRouterAdminService)2 OpenstackSecurityGroupAdminService (org.onosproject.openstacknetworking.api.OpenstackSecurityGroupAdminService)2 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)2 OSClient (org.openstack4j.api.OSClient)2