tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 3 | import org.apache.karaf.shell.commands.Argument; |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.net.Device; |
| 6 | import org.onlab.onos.net.Host; |
| 7 | import org.onlab.onos.net.device.DeviceAdminService; |
| 8 | import org.onlab.onos.net.device.DeviceService; |
| 9 | import org.onlab.onos.net.host.HostAdminService; |
| 10 | import org.onlab.onos.net.host.HostService; |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 11 | import org.onlab.onos.net.intent.Intent; |
| 12 | import org.onlab.onos.net.intent.IntentService; |
| 13 | import org.onlab.onos.net.intent.IntentState; |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 16 | * Wipes-out the entire network information base, i.e. devices, links, hosts, intents. |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 17 | */ |
| 18 | @Command(scope = "onos", name = "wipe-out", |
| 19 | description = "Wipes-out the entire network information base, i.e. devices, links, hosts") |
| 20 | public class WipeOutCommand extends ClustersListCommand { |
| 21 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 22 | private static final String DISCLAIMER = "Delete everything please."; |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 23 | |
| 24 | @Argument(index = 0, name = "disclaimer", description = "Device ID", |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 25 | required = false, multiValued = false) |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 26 | String disclaimer = null; |
| 27 | |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 28 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 29 | protected void execute() { |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 30 | if (disclaimer == null || !disclaimer.equals(DISCLAIMER)) { |
| 31 | print("I'm afraid I can't do that!\nPlease acknowledge with phrase: '%s'", |
| 32 | DISCLAIMER); |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 33 | return; |
| 34 | } |
| 35 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 36 | print("Wiping devices"); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 37 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); |
| 38 | DeviceService deviceService = get(DeviceService.class); |
| 39 | for (Device device : deviceService.getDevices()) { |
| 40 | deviceAdminService.removeDevice(device.id()); |
| 41 | } |
| 42 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 43 | print("Wiping hosts"); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 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'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 49 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 50 | print("Wiping intents"); |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 51 | IntentService intentService = get(IntentService.class); |
| 52 | for (Intent intent : intentService.getIntents()) { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 53 | if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) { |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 54 | intentService.withdraw(intent); |
| 55 | } |
| 56 | } |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 57 | } |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 58 | } |