make netconf-get-config usable on any NETCONF device.

- removed dependency to ConfigGetter

Change-Id: I00072625efc9ece327628f5034a845b0b96526f2
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
index 90f3148..94c5a35 100644
--- a/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
@@ -16,6 +16,9 @@
 
 package org.onosproject.netconf;
 
+// TODO Revisit if we this class should be Enum.
+// According to NETCONF RFC,
+// various additional configuration datastores may be defined by capabilities.
 public enum TargetConfig {
     RUNNING("running"),
     CANDIDATE("candidate"),
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
index fd5a04c..fe1d9f9 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
@@ -15,24 +15,23 @@
  */
 package org.onosproject.netconf.cli.impl;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.io.IOException;
+
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.behaviour.ConfigGetter;
-import org.onosproject.net.driver.DriverHandler;
-import org.onosproject.net.driver.DriverService;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfSession;
+import org.onosproject.netconf.TargetConfig;
 
 /**
  * Command that gets the configuration of the specified type from the specified
  * device. If configuration cannot be retrieved it prints an error string.
- *
- * This is a temporary development tool for use until yang integration is complete.
- * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
  */
-
-//FIXME Remove dependency to ConfigGetter.
-
 @Command(scope = "onos", name = "netconf-get-config",
         description = "Gets the configuration of the specified type from the" +
                 "specified device.")
@@ -52,11 +51,30 @@
 
     @Override
     protected void execute() {
-        DriverService service = get(DriverService.class);
         deviceId = DeviceId.deviceId(uri);
-        DriverHandler h = service.createHandler(deviceId);
-        ConfigGetter config = h.behaviour(ConfigGetter.class);
-        print(config.getConfiguration(cfgType));
+
+        NetconfController controller = get(NetconfController.class);
+        checkNotNull(controller, "Netconf controller is null");
+
+        NetconfDevice device = controller.getDevicesMap().get(deviceId);
+        if (device == null) {
+            print("Netconf device object not found for %s", deviceId);
+            return;
+        }
+
+        NetconfSession session = device.getSession();
+        if (session == null) {
+            print("Netconf session not found for %s", deviceId);
+            return;
+        }
+
+        try {
+            String res = session.getConfig(TargetConfig.toTargetConfig(cfgType));
+            print("%s", res);
+        } catch (IOException e) {
+            log.error("Configuration could not be retrieved", e);
+            print("Error occured retrieving configuration");
+        }
     }
 
 }
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java
index a15cde9..b1d2315 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfSubscriptionTestCommand.java
@@ -52,7 +52,7 @@
 
         NetconfDevice netconfDevice = controller.getNetconfDevice(did);
         if (netconfDevice == null) {
-            print("%s not found or not connectoed to this node", did);
+            print("%s not found or not connected to this node", did);
             return;
         }