blob: fe18ba0720552fba9905566efdb8bf899bb76b02 [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/**
tome2555ff2014-10-07 18:47:58 -070016 * Wipes-out the entire network information base, i.e. devices, links, hosts, intents.
tom89b63c52014-09-16 09:19:51 -070017 */
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
tome2555ff2014-10-07 18:47:58 -070022 private static final String DISCLAIMER = "Delete everything please.";
tom22288032014-10-07 08:16:53 -070023
24 @Argument(index = 0, name = "disclaimer", description = "Device ID",
tome2555ff2014-10-07 18:47:58 -070025 required = false, multiValued = false)
tom22288032014-10-07 08:16:53 -070026 String disclaimer = null;
27
tom89b63c52014-09-16 09:19:51 -070028 @Override
tom0872a172014-09-23 11:24:26 -070029 protected void execute() {
tome2555ff2014-10-07 18:47:58 -070030 if (disclaimer == null || !disclaimer.equals(DISCLAIMER)) {
31 print("I'm afraid I can't do that!\nPlease acknowledge with phrase: '%s'",
32 DISCLAIMER);
tom22288032014-10-07 08:16:53 -070033 return;
34 }
35
tome2555ff2014-10-07 18:47:58 -070036 print("Wiping devices");
tom89b63c52014-09-16 09:19:51 -070037 DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
38 DeviceService deviceService = get(DeviceService.class);
39 for (Device device : deviceService.getDevices()) {
40 deviceAdminService.removeDevice(device.id());
41 }
42
tome2555ff2014-10-07 18:47:58 -070043 print("Wiping hosts");
tom89b63c52014-09-16 09:19:51 -070044 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
tome2555ff2014-10-07 18:47:58 -070050 print("Wiping intents");
Brian O'Connor958d3812014-10-03 19:46:23 -070051 IntentService intentService = get(IntentService.class);
52 for (Intent intent : intentService.getIntents()) {
tom85258ee2014-10-07 00:10:02 -070053 if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) {
Brian O'Connor958d3812014-10-03 19:46:23 -070054 intentService.withdraw(intent);
55 }
56 }
tom89b63c52014-09-16 09:19:51 -070057 }
tom89b63c52014-09-16 09:19:51 -070058}