blob: 6aebc272808556efee9b870792d13cc3a17067f9 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska7d693f52014-10-21 19:17:57 -070015 */
tom89b63c52014-09-16 09:19:51 -070016package org.onlab.onos.cli.net;
17
tom22288032014-10-07 08:16:53 -070018import org.apache.karaf.shell.commands.Argument;
tom89b63c52014-09-16 09:19:51 -070019import org.apache.karaf.shell.commands.Command;
20import org.onlab.onos.net.Device;
21import org.onlab.onos.net.Host;
22import org.onlab.onos.net.device.DeviceAdminService;
23import org.onlab.onos.net.device.DeviceService;
24import org.onlab.onos.net.host.HostAdminService;
25import org.onlab.onos.net.host.HostService;
Brian O'Connor958d3812014-10-03 19:46:23 -070026import org.onlab.onos.net.intent.Intent;
27import org.onlab.onos.net.intent.IntentService;
28import org.onlab.onos.net.intent.IntentState;
tom89b63c52014-09-16 09:19:51 -070029
30/**
tome2555ff2014-10-07 18:47:58 -070031 * Wipes-out the entire network information base, i.e. devices, links, hosts, intents.
tom89b63c52014-09-16 09:19:51 -070032 */
33@Command(scope = "onos", name = "wipe-out",
34 description = "Wipes-out the entire network information base, i.e. devices, links, hosts")
35public class WipeOutCommand extends ClustersListCommand {
36
tom1679e182014-10-09 13:50:45 -070037 private static final String PLEASE = "please";
tom22288032014-10-07 08:16:53 -070038
tom1679e182014-10-09 13:50:45 -070039 @Argument(index = 0, name = "please", description = "Confirmation phrase",
tome2555ff2014-10-07 18:47:58 -070040 required = false, multiValued = false)
tom1679e182014-10-09 13:50:45 -070041 String please = null;
tom22288032014-10-07 08:16:53 -070042
tom89b63c52014-09-16 09:19:51 -070043 @Override
tom0872a172014-09-23 11:24:26 -070044 protected void execute() {
tom1679e182014-10-09 13:50:45 -070045 if (please == null || !please.equals(PLEASE)) {
46 print("I'm afraid I can't do that!\nSay: %s", PLEASE);
tom22288032014-10-07 08:16:53 -070047 return;
48 }
49
tome2555ff2014-10-07 18:47:58 -070050 print("Wiping devices");
tom89b63c52014-09-16 09:19:51 -070051 DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
52 DeviceService deviceService = get(DeviceService.class);
53 for (Device device : deviceService.getDevices()) {
54 deviceAdminService.removeDevice(device.id());
55 }
56
tome2555ff2014-10-07 18:47:58 -070057 print("Wiping hosts");
tom89b63c52014-09-16 09:19:51 -070058 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'Connor958d3812014-10-03 19:46:23 -070063
tome2555ff2014-10-07 18:47:58 -070064 print("Wiping intents");
Brian O'Connor958d3812014-10-03 19:46:23 -070065 IntentService intentService = get(IntentService.class);
66 for (Intent intent : intentService.getIntents()) {
tom85258ee2014-10-07 00:10:02 -070067 if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) {
Brian O'Connor958d3812014-10-03 19:46:23 -070068 intentService.withdraw(intent);
69 }
70 }
tom89b63c52014-09-16 09:19:51 -070071 }
tom89b63c52014-09-16 09:19:51 -070072}