Print out tenant network bridge information of kubevirt via CLI

Change-Id: If2d90d39831210c5ae22883496eb11a395c2aab9
(cherry picked from commit c5a0d74fa9cd9c8079f501facb6bd6c27bceb904)
diff --git a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtCheckNodeCommand.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtCheckNodeCommand.java
similarity index 78%
rename from apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtCheckNodeCommand.java
rename to apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtCheckNodeCommand.java
index 975da59..a00967f 100644
--- a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtCheckNodeCommand.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtCheckNodeCommand.java
@@ -13,13 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.kubevirtnode.cli;
+package org.onosproject.kubevirtnetworking.cli;
 
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetwork;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetworkService;
 import org.onosproject.kubevirtnode.api.KubevirtNode;
 import org.onosproject.kubevirtnode.api.KubevirtNodeService;
 import org.onosproject.kubevirtnode.api.KubevirtPhyInterface;
@@ -28,12 +30,16 @@
 import org.onosproject.net.Port;
 import org.onosproject.net.device.DeviceService;
 
+import java.util.Set;
+import java.util.stream.Collectors;
+
 import static org.onosproject.kubevirtnode.api.Constants.GENEVE;
 import static org.onosproject.kubevirtnode.api.Constants.GRE;
 import static org.onosproject.kubevirtnode.api.Constants.INTEGRATION_BRIDGE;
 import static org.onosproject.kubevirtnode.api.Constants.STT;
 import static org.onosproject.kubevirtnode.api.Constants.TUNNEL_BRIDGE;
 import static org.onosproject.kubevirtnode.api.Constants.VXLAN;
+import static org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER;
 import static org.onosproject.net.AnnotationKeys.PORT_NAME;
 
 /**
@@ -57,6 +63,7 @@
     @Override
     protected void doExecute() throws Exception {
         KubevirtNodeService nodeService = get(KubevirtNodeService.class);
+        KubevirtNetworkService networkService = get(KubevirtNetworkService.class);
         DeviceService deviceService = get(DeviceService.class);
 
         KubevirtNode node = nodeService.node(hostname);
@@ -111,6 +118,27 @@
                 }
             }
         }
+
+        Set<KubevirtNetwork> networks = networkService.networks().stream()
+                .filter(n -> n.type() == KubevirtNetwork.Type.VXLAN ||
+                        n.type() == KubevirtNetwork.Type.GRE ||
+                        n.type() == KubevirtNetwork.Type.GENEVE ||
+                        n.type() == KubevirtNetwork.Type.STT).collect(Collectors.toSet());
+        if (networks.size() > 0 && node.type() == WORKER) {
+            print("");
+            print("[Tenant Network Bridge Status]");
+            for (KubevirtNetwork network : networks) {
+                Device tenantBridge = deviceService.getDevice(network.tenantDeviceId(node.hostname()));
+                if (tenantBridge != null) {
+                    print("%s %s=%s available=%s %s",
+                            deviceService.isAvailable(tenantBridge.id()) ? MSG_PASS : MSG_FAIL,
+                            network.tenantBridgeName(),
+                            tenantBridge.id(),
+                            deviceService.isAvailable(tenantBridge.id()),
+                            tenantBridge.annotations());
+                }
+            }
+        }
     }
 
     private void printPortState(DeviceService deviceService,
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtHostnameCompleter.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtHostnameCompleter.java
new file mode 100644
index 0000000..ce1b685
--- /dev/null
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtHostnameCompleter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kubevirtnetworking.cli;
+
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.onosproject.kubevirtnode.api.KubevirtNode;
+import org.onosproject.kubevirtnode.api.KubevirtNodeService;
+
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.stream.Collectors;
+
+import static org.onosproject.cli.AbstractShellCommand.get;
+
+/**
+ * Kubevirt host completer.
+ */
+@Service
+public class KubevirtHostnameCompleter implements Completer {
+    @Override
+    public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+        StringsCompleter delegate = new StringsCompleter();
+        KubevirtNodeService nodeService = get(KubevirtNodeService.class);
+
+        Set<String> hostnames = nodeService.nodes().stream()
+                .map(KubevirtNode::hostname)
+                .collect(Collectors.toSet());
+        SortedSet<String> strings = delegate.getStrings();
+
+        strings.addAll(hostnames);
+
+        return delegate.complete(session, commandLine, candidates);
+    }
+}