blob: e62f85093c77dca81b43011672273cfc7a161061 [file] [log] [blame]
tom89b63c52014-09-16 09:19:51 -07001package org.onlab.onos.cli.net;
2
tom22288032014-10-07 08:16:53 -07003import org.apache.karaf.shell.commands.Argument;
tom89b63c52014-09-16 09:19:51 -07004import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.net.Device;
6import org.onlab.onos.net.Host;
7import org.onlab.onos.net.device.DeviceAdminService;
8import org.onlab.onos.net.device.DeviceService;
9import org.onlab.onos.net.host.HostAdminService;
10import org.onlab.onos.net.host.HostService;
Brian O'Connor958d3812014-10-03 19:46:23 -070011import org.onlab.onos.net.intent.Intent;
12import org.onlab.onos.net.intent.IntentService;
13import org.onlab.onos.net.intent.IntentState;
tom89b63c52014-09-16 09:19:51 -070014
15/**
16 * Wipes-out the entire network information base, i.e. devices, links, hosts.
17 */
18@Command(scope = "onos", name = "wipe-out",
19 description = "Wipes-out the entire network information base, i.e. devices, links, hosts")
20public class WipeOutCommand extends ClustersListCommand {
21
tom22288032014-10-07 08:16:53 -070022
23 private static final String DISCLAIMER = "Yes, I know it will delete everything!";
24
25 @Argument(index = 0, name = "disclaimer", description = "Device ID",
26 required = true, multiValued = false)
27 String disclaimer = null;
28
tom89b63c52014-09-16 09:19:51 -070029 @Override
tom0872a172014-09-23 11:24:26 -070030 protected void execute() {
tom22288032014-10-07 08:16:53 -070031 if (!disclaimer.equals(DISCLAIMER)) {
32 print("I'm afraid I can't do that...");
33 print("You have to acknowledge by: " + DISCLAIMER);
34 return;
35 }
36
37 print("Good bye...");
tom89b63c52014-09-16 09:19:51 -070038 DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
39 DeviceService deviceService = get(DeviceService.class);
40 for (Device device : deviceService.getDevices()) {
41 deviceAdminService.removeDevice(device.id());
42 }
43
44 HostAdminService hostAdminService = get(HostAdminService.class);
45 HostService hostService = get(HostService.class);
46 for (Host host : hostService.getHosts()) {
47 hostAdminService.removeHost(host.id());
48 }
Brian O'Connor958d3812014-10-03 19:46:23 -070049
50 IntentService intentService = get(IntentService.class);
51 for (Intent intent : intentService.getIntents()) {
tom85258ee2014-10-07 00:10:02 -070052 if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) {
Brian O'Connor958d3812014-10-03 19:46:23 -070053 intentService.withdraw(intent);
54 }
55 }
tom89b63c52014-09-16 09:19:51 -070056 }
tom89b63c52014-09-16 09:19:51 -070057}