Search in sources :

Example 1 with REMOVE_PENDING

use of org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING in project onos by opennetworkinglab.

the class PurgeInstancePortsCommand method doExecute.

@Override
protected void doExecute() {
    InstancePortAdminService service = get(InstancePortAdminService.class);
    if ((!isAll && !isInactive && !isPending && portIds == null) || (isAll && isInactive && isPending) || (isInactive && isPending && portIds != null) || (portIds != null && isAll && isPending) || (isAll && isInactive && portIds != null)) {
        print("Please specify one of portIds, --all or --inactive or --pending options.");
        return;
    }
    if (isAll) {
        portIds = service.instancePorts().stream().map(InstancePort::portId).toArray(String[]::new);
    } else if (isInactive) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == INACTIVE).map(InstancePort::portId).toArray(String[]::new);
    } else if (isPending) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == REMOVE_PENDING).map(InstancePort::portId).toArray(String[]::new);
    }
    for (String portId : portIds) {
        service.removeInstancePort(portId);
        print("Instance port %s has been removed!", portId);
    }
    print("Done.");
}
Also used : AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) REMOVE_PENDING(org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Service(org.apache.karaf.shell.api.action.lifecycle.Service) INACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.INACTIVE) Argument(org.apache.karaf.shell.api.action.Argument) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) Command(org.apache.karaf.shell.api.action.Command) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Aggregations

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 Option (org.apache.karaf.shell.api.action.Option)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)1 INACTIVE (org.onosproject.openstacknetworking.api.InstancePort.State.INACTIVE)1 REMOVE_PENDING (org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING)1 InstancePortAdminService (org.onosproject.openstacknetworking.api.InstancePortAdminService)1