blob: 5fd29f234c0bad138857063dacac253e8e8e8337 [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
tom1679e182014-10-09 13:50:45 -070022 private static final String PLEASE = "please";
tom22288032014-10-07 08:16:53 -070023
tom1679e182014-10-09 13:50:45 -070024 @Argument(index = 0, name = "please", description = "Confirmation phrase",
tome2555ff2014-10-07 18:47:58 -070025 required = false, multiValued = false)
tom1679e182014-10-09 13:50:45 -070026 String please = null;
tom22288032014-10-07 08:16:53 -070027
tom89b63c52014-09-16 09:19:51 -070028 @Override
tom0872a172014-09-23 11:24:26 -070029 protected void execute() {
tom1679e182014-10-09 13:50:45 -070030 if (please == null || !please.equals(PLEASE)) {
31 print("I'm afraid I can't do that!\nSay: %s", PLEASE);
tom22288032014-10-07 08:16:53 -070032 return;
33 }
34
tome2555ff2014-10-07 18:47:58 -070035 print("Wiping devices");
tom89b63c52014-09-16 09:19:51 -070036 DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
37 DeviceService deviceService = get(DeviceService.class);
38 for (Device device : deviceService.getDevices()) {
39 deviceAdminService.removeDevice(device.id());
40 }
41
tome2555ff2014-10-07 18:47:58 -070042 print("Wiping hosts");
tom89b63c52014-09-16 09:19:51 -070043 HostAdminService hostAdminService = get(HostAdminService.class);
44 HostService hostService = get(HostService.class);
45 for (Host host : hostService.getHosts()) {
46 hostAdminService.removeHost(host.id());
47 }
Brian O'Connor958d3812014-10-03 19:46:23 -070048
tome2555ff2014-10-07 18:47:58 -070049 print("Wiping intents");
Brian O'Connor958d3812014-10-03 19:46:23 -070050 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}