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 | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame^] | 22 | private static final String PLEASE = "please"; |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 23 | |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame^] | 24 | @Argument(index = 0, name = "please", description = "Confirmation phrase", |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 25 | required = false, multiValued = false) |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame^] | 26 | String please = null; |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 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 | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame^] | 30 | if (please == null || !please.equals(PLEASE)) { |
| 31 | print("I'm afraid I can't do that!\nSay: %s", PLEASE); |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 32 | return; |
| 33 | } |
| 34 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 35 | print("Wiping devices"); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 36 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); |
| 37 | DeviceService deviceService = get(DeviceService.class); |
| 38 | for (Device device : deviceService.getDevices()) { |
| 39 | deviceAdminService.removeDevice(device.id()); |
| 40 | } |
| 41 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 42 | print("Wiping hosts"); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 43 | 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'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 48 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 49 | print("Wiping intents"); |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 50 | IntentService intentService = get(IntentService.class); |
| 51 | for (Intent intent : intentService.getIntents()) { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 52 | if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) { |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 53 | intentService.withdraw(intent); |
| 54 | } |
| 55 | } |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 56 | } |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 57 | } |