[ONOS-7554] Option in DeviceSetControllersCommand CLI to remove controllers configuration from device

Change-Id: Ib5fb7eb71d8322ffdd556f472c299fc10251c4b7
diff --git a/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java b/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java
index 2ee0674..af66ae0 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java
@@ -18,6 +18,7 @@
 
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
 import org.onlab.packet.IpAddress;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.Annotations;
@@ -45,17 +46,26 @@
 
     @Argument(index = 1, name = "controllersListStrings", description = "list of " +
             "controllers to set for the specified device",
-            required = true, multiValued = true)
+            required = false, multiValued = true)
     String[] controllersListStrings = null;
 
+    @Option(name = "--remove",
+            description = "Remove specified controllers configuration")
+    private boolean removeCont = false;
+
+    @Option(name = "--remove-all",
+            description = "Remove all controllers configuration, " +
+                    "does not require any input")
+    private boolean removeAll = false;
+
     private DeviceId deviceId;
-    private List<ControllerInfo> newControllers = new ArrayList<>();
+    private List<ControllerInfo> controllers = new ArrayList<>();
 
     @Override
     protected void execute() {
 
         Arrays.asList(controllersListStrings).forEach(
-                cInfoString -> newControllers.add(parseCInfoString(cInfoString)));
+                cInfoString -> controllers.add(parseCInfoString(cInfoString)));
         DriverService service = get(DriverService.class);
         deviceId = DeviceId.deviceId(uri);
         DriverHandler h = service.createHandler(deviceId);
@@ -63,7 +73,27 @@
         print("before:");
         config.getControllers().forEach(c -> print(c.target()));
         try {
-            config.setControllers(newControllers);
+            if (removeAll) {
+                if (!controllers.isEmpty()) {
+                    print("Controllers list should be empty to remove all controllers");
+                } else {
+                    List<ControllerInfo> controllersToRemove = config.getControllers();
+                    controllersToRemove.forEach(c -> print("Will remove " + c.target()));
+                    config.removeControllers(controllersToRemove);
+                }
+            } else {
+                if (controllers.isEmpty()) {
+                    print("Controllers list is empty, cannot set/remove empty controllers");
+                } else {
+                    if (removeCont) {
+                        print("Will remove specified controllers");
+                        config.removeControllers(controllers);
+                    } else {
+                        print("Will add specified controllers");
+                        config.setControllers(controllers);
+                    }
+                }
+            }
         } catch (NullPointerException e) {
             print("No Device with requested parameters {} ", uri);
         }