blob: 73ba59ae738599beefc509761caa8a61b81b0120 [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 */
Brian O'Connora4cab072014-10-03 18:46:39 -070016package org.onlab.onos.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.onos.cli.AbstractShellCommand;
21import org.onlab.onos.net.intent.Intent;
22import org.onlab.onos.net.intent.IntentId;
23import org.onlab.onos.net.intent.IntentService;
24
Thomas Vachuska4926c1b2014-10-21 00:44:10 -070025import java.math.BigInteger;
26
Brian O'Connora4cab072014-10-03 18:46:39 -070027/**
28 * Removes host-to-host connectivity intent.
29 */
tom6db1f0a2014-10-07 09:12:29 -070030@Command(scope = "onos", name = "remove-intent",
31 description = "Removes the specified intent")
32public class IntentRemoveCommand extends AbstractShellCommand {
Brian O'Connora4cab072014-10-03 18:46:39 -070033
34 @Argument(index = 0, name = "id", description = "Intent ID",
35 required = true, multiValued = false)
36 String id = null;
37
38 @Override
39 protected void execute() {
40 IntentService service = get(IntentService.class);
41
Thomas Vachuska4926c1b2014-10-21 00:44:10 -070042 if (id.startsWith("0x")) {
Brian O'Connora4cab072014-10-03 18:46:39 -070043 id = id.replaceFirst("0x", "");
44 }
Brian O'Connora4cab072014-10-03 18:46:39 -070045
Thomas Vachuska4926c1b2014-10-21 00:44:10 -070046 IntentId intentId = IntentId.valueOf(new BigInteger(id, 16).longValue());
Brian O'Connora4cab072014-10-03 18:46:39 -070047 Intent intent = service.getIntent(intentId);
48 if (intent != null) {
49 service.withdraw(intent);
50 }
51 }
52}