blob: b2cef880b781d2fa7cd152dd133fdf28f59d23ef [file] [log] [blame]
Brian O'Connora4cab072014-10-03 18:46:39 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Argument;
4import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.cli.AbstractShellCommand;
6import org.onlab.onos.net.intent.Intent;
7import org.onlab.onos.net.intent.IntentId;
8import org.onlab.onos.net.intent.IntentService;
9
10/**
11 * Removes host-to-host connectivity intent.
12 */
tom6db1f0a2014-10-07 09:12:29 -070013@Command(scope = "onos", name = "remove-intent",
14 description = "Removes the specified intent")
15public class IntentRemoveCommand extends AbstractShellCommand {
Brian O'Connora4cab072014-10-03 18:46:39 -070016
17 @Argument(index = 0, name = "id", description = "Intent ID",
18 required = true, multiValued = false)
19 String id = null;
20
21 @Override
22 protected void execute() {
23 IntentService service = get(IntentService.class);
24
25 int radix = id.startsWith("0x") ? 16 : 10;
26 if (radix == 16) {
27 id = id.replaceFirst("0x", "");
28 }
Brian O'Connora4cab072014-10-03 18:46:39 -070029
Thomas Vachuskab97cf282014-10-20 23:31:12 -070030 IntentId intentId = IntentId.valueOf(Long.parseLong(id, radix));
Brian O'Connora4cab072014-10-03 18:46:39 -070031 Intent intent = service.getIntent(intentId);
32 if (intent != null) {
33 service.withdraw(intent);
34 }
35 }
36}