pierventre | 1483e64 | 2016-06-08 18:52:29 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.sdxl2.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.sdxl2.SdxL2ConnectionPoint; |
| 23 | import org.onosproject.sdxl2.SdxL2Service; |
| 24 | import org.onosproject.sdxl2.SdxL2State; |
| 25 | |
| 26 | import java.util.Optional; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * CLI to list the SDX-L2 connection points. |
| 31 | */ |
| 32 | @Command(scope = "sdxl2", name = "sdxl2cps-list", description = "Lists " + |
| 33 | "all the sdxl2 connection points. Argument not required the name of sdxl2") |
| 34 | public class SdxL2ListCPCommand extends AbstractShellCommand { |
| 35 | |
| 36 | @Argument(index = 0, name = "sdxl2name", description = "sdxl2name", required = false, multiValued = false) |
| 37 | String sdxl2 = null; |
| 38 | |
| 39 | private static final String HEADER = "\n\u001B[1;37mStatus\t\tSDXL2 Connection Point\u001B[0m"; |
| 40 | private static final String SEPARATOR = "\u001B[1;37m-----------------------------------------------\u001B[0m"; |
| 41 | private static final String FORMAT_SDXL2CP_ONLINE = "\u001B[1;32m%s\u001B[0m\t\t\u001B[1;37m%s\u001B[0m"; |
| 42 | private static final String FORMAT_SDXL2CP_OFFLINE = "\u001B[1;31m%s\u001B[0m\t\t\u001B[1;37m%s\u001B[0m"; |
| 43 | |
| 44 | @Override |
| 45 | protected void execute() { |
| 46 | SdxL2Service sdxl2Service = get(SdxL2Service.class); |
| 47 | Optional<String> sdxl2name = Optional.ofNullable(sdxl2); |
| 48 | Set<String> result = sdxl2Service.getSdxL2ConnectionPoints(sdxl2name); |
| 49 | SdxL2ConnectionPoint sdxl2ConnectionPoint; |
| 50 | SdxL2State sdxl2cpState; |
| 51 | if (result.size() > 0) { |
| 52 | print(HEADER); |
| 53 | print(SEPARATOR); |
| 54 | for (String sdxl2cp : result) { |
| 55 | sdxl2ConnectionPoint = sdxl2Service.getSdxL2ConnectionPoint(sdxl2cp); |
| 56 | if (sdxl2ConnectionPoint == null) { |
| 57 | return; |
| 58 | } |
| 59 | sdxl2cpState = sdxl2Service.getEdgePortState(sdxl2ConnectionPoint.connectPoint()); |
| 60 | if (sdxl2cpState == SdxL2State.ONLINE) { |
| 61 | print(FORMAT_SDXL2CP_ONLINE, "ONLINE", sdxl2cp); |
| 62 | } else if (sdxl2cpState == SdxL2State.OFFLINE) { |
| 63 | print(FORMAT_SDXL2CP_OFFLINE, "OFFLINE", sdxl2cp); |
| 64 | } |
| 65 | } |
| 66 | print(""); |
| 67 | } |
| 68 | } |
| 69 | } |