blob: 41ea5eb7aea8298b5e26d096d3256941e2909dcb [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
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 */
tom89b63c52014-09-16 09:19:51 -070019package org.onlab.onos.cli.net;
20
tom22288032014-10-07 08:16:53 -070021import org.apache.karaf.shell.commands.Argument;
tom89b63c52014-09-16 09:19:51 -070022import org.apache.karaf.shell.commands.Command;
23import org.onlab.onos.net.Device;
24import org.onlab.onos.net.Host;
25import org.onlab.onos.net.device.DeviceAdminService;
26import org.onlab.onos.net.device.DeviceService;
27import org.onlab.onos.net.host.HostAdminService;
28import org.onlab.onos.net.host.HostService;
Brian O'Connor958d3812014-10-03 19:46:23 -070029import org.onlab.onos.net.intent.Intent;
30import org.onlab.onos.net.intent.IntentService;
31import org.onlab.onos.net.intent.IntentState;
tom89b63c52014-09-16 09:19:51 -070032
33/**
tome2555ff2014-10-07 18:47:58 -070034 * Wipes-out the entire network information base, i.e. devices, links, hosts, intents.
tom89b63c52014-09-16 09:19:51 -070035 */
36@Command(scope = "onos", name = "wipe-out",
37 description = "Wipes-out the entire network information base, i.e. devices, links, hosts")
38public class WipeOutCommand extends ClustersListCommand {
39
tom1679e182014-10-09 13:50:45 -070040 private static final String PLEASE = "please";
tom22288032014-10-07 08:16:53 -070041
tom1679e182014-10-09 13:50:45 -070042 @Argument(index = 0, name = "please", description = "Confirmation phrase",
tome2555ff2014-10-07 18:47:58 -070043 required = false, multiValued = false)
tom1679e182014-10-09 13:50:45 -070044 String please = null;
tom22288032014-10-07 08:16:53 -070045
tom89b63c52014-09-16 09:19:51 -070046 @Override
tom0872a172014-09-23 11:24:26 -070047 protected void execute() {
tom1679e182014-10-09 13:50:45 -070048 if (please == null || !please.equals(PLEASE)) {
49 print("I'm afraid I can't do that!\nSay: %s", PLEASE);
tom22288032014-10-07 08:16:53 -070050 return;
51 }
52
tome2555ff2014-10-07 18:47:58 -070053 print("Wiping devices");
tom89b63c52014-09-16 09:19:51 -070054 DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
55 DeviceService deviceService = get(DeviceService.class);
56 for (Device device : deviceService.getDevices()) {
57 deviceAdminService.removeDevice(device.id());
58 }
59
tome2555ff2014-10-07 18:47:58 -070060 print("Wiping hosts");
tom89b63c52014-09-16 09:19:51 -070061 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'Connor958d3812014-10-03 19:46:23 -070066
tome2555ff2014-10-07 18:47:58 -070067 print("Wiping intents");
Brian O'Connor958d3812014-10-03 19:46:23 -070068 IntentService intentService = get(IntentService.class);
69 for (Intent intent : intentService.getIntents()) {
tom85258ee2014-10-07 00:10:02 -070070 if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) {
Brian O'Connor958d3812014-10-03 19:46:23 -070071 intentService.withdraw(intent);
72 }
73 }
tom89b63c52014-09-16 09:19:51 -070074 }
tom89b63c52014-09-16 09:19:51 -070075}