CLI to display Of-Port status
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / cli / TepShowOfPorts.java
1 /*
2  * Copyright (c) 2020 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.genius.itm.cli;
9
10 import java.util.Collection;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.genius.itm.api.IITMProvider;
14 import org.opendaylight.genius.itm.cache.OfTepStateCache;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.of.teps.state.OfTep;
16
17 @Command(scope = "tep", name = "show-ofports", description = "Monitors of ports")
18
19 public class TepShowOfPorts extends OsgiCommandSupport {
20
21     private final IITMProvider itmProvider;
22     private final OfTepStateCache ofTepStateCache;
23
24     public TepShowOfPorts(IITMProvider itmProvider, OfTepStateCache ofTepStateCache) {
25         this.itmProvider = itmProvider;
26         this.ofTepStateCache = ofTepStateCache;
27     }
28
29     @Override
30     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
31     protected Object doExecute() {
32         Collection<OfTep> ofPorts = ofTepStateCache.getAllPresent();
33         if (!ofPorts.isEmpty()) {
34             itmProvider.showOfPorts(ofPorts);
35         } else {
36             System.out.println("No OF ports configured on the switch");
37         }
38         return null;
39     }
40 }