Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame^] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 17 | |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.commands.Argument; |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.Device; |
| 21 | import org.onosproject.net.Host; |
| 22 | import org.onosproject.net.device.DeviceAdminService; |
| 23 | import org.onosproject.net.device.DeviceService; |
| 24 | import org.onosproject.net.host.HostAdminService; |
| 25 | import org.onosproject.net.host.HostService; |
| 26 | import org.onosproject.net.intent.Intent; |
| 27 | import org.onosproject.net.intent.IntentService; |
| 28 | import org.onosproject.net.intent.IntentState; |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 31 | * Wipes-out the entire network information base, i.e. devices, links, hosts, intents. |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 32 | */ |
| 33 | @Command(scope = "onos", name = "wipe-out", |
| 34 | description = "Wipes-out the entire network information base, i.e. devices, links, hosts") |
| 35 | public class WipeOutCommand extends ClustersListCommand { |
| 36 | |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 37 | private static final String PLEASE = "please"; |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 38 | |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 39 | @Argument(index = 0, name = "please", description = "Confirmation phrase", |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 40 | required = false, multiValued = false) |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 41 | String please = null; |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 42 | |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 43 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 44 | protected void execute() { |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 45 | if (please == null || !please.equals(PLEASE)) { |
| 46 | print("I'm afraid I can't do that!\nSay: %s", PLEASE); |
tom | 2228803 | 2014-10-07 08:16:53 -0700 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 50 | print("Wiping devices"); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 51 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); |
| 52 | DeviceService deviceService = get(DeviceService.class); |
| 53 | for (Device device : deviceService.getDevices()) { |
| 54 | deviceAdminService.removeDevice(device.id()); |
| 55 | } |
| 56 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 57 | print("Wiping hosts"); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 58 | HostAdminService hostAdminService = get(HostAdminService.class); |
| 59 | HostService hostService = get(HostService.class); |
| 60 | for (Host host : hostService.getHosts()) { |
| 61 | hostAdminService.removeHost(host.id()); |
| 62 | } |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 63 | |
tom | e2555ff | 2014-10-07 18:47:58 -0700 | [diff] [blame] | 64 | print("Wiping intents"); |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 65 | IntentService intentService = get(IntentService.class); |
| 66 | for (Intent intent : intentService.getIntents()) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 67 | if (intentService.getIntentState(intent.key()) == IntentState.INSTALLED) { |
Brian O'Connor | 958d381 | 2014-10-03 19:46:23 -0700 | [diff] [blame] | 68 | intentService.withdraw(intent); |
| 69 | } |
| 70 | } |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 71 | } |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 72 | } |