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 | /** |
| 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") |
| 20 | public class WipeOutCommand extends ClustersListCommand { |
| 21 | |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 22 | |
| 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 | |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 29 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 30 | protected void execute() { |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 31 | 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..."); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 38 | 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'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 49 | |
| 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 | } |