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