Add kubevirt API config service, expose it via REST API and CLI

Change-Id: I45a867ad54622656475758e7b4af38c19e551790
diff --git a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtApiConfigListCommand.java b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtApiConfigListCommand.java
new file mode 100644
index 0000000..d88cd0d
--- /dev/null
+++ b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/cli/KubevirtApiConfigListCommand.java
@@ -0,0 +1,57 @@
+/*
+ * 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.kubevirtnode.cli;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfig;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfigService;
+
+import static org.onosproject.kubevirtnode.util.KubevirtNodeUtil.prettyJson;
+
+/**
+ * Lists all KubeVirt API server configs registered to the service.
+ */
+@Service
+@Command(scope = "onos", name = "kubevirt-api-configs",
+        description = "Lists all KubeVirt API server configs registered to the service")
+public class KubevirtApiConfigListCommand extends AbstractShellCommand {
+
+    private static final String FORMAT = "%-10s%-25s%-10s%-10s";
+
+    @Override
+    protected void doExecute() throws Exception {
+        KubevirtApiConfigService service = get(KubevirtApiConfigService.class);
+        KubevirtApiConfig config = service.apiConfig();
+
+        if (outputJson()) {
+            print("%s", json(config));
+        } else {
+            print(FORMAT, "Scheme", "IpAddress", "Port", "State");
+            print(FORMAT, config.scheme().name(), config.ipAddress().toString(),
+                    config.port(), config.state().name());
+        }
+    }
+
+    private String json(KubevirtApiConfig config) {
+        ObjectMapper mapper = new ObjectMapper();
+        ObjectNode node = jsonForEntity(config, KubevirtApiConfig.class);
+        return prettyJson(mapper, node.toString());
+    }
+}