Brian O'Connor | a4cab07 | 2014-10-03 18:46:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| 6 | import org.onlab.onos.net.intent.Intent; |
| 7 | import org.onlab.onos.net.intent.IntentId; |
| 8 | import org.onlab.onos.net.intent.IntentService; |
| 9 | |
| 10 | /** |
| 11 | * Removes host-to-host connectivity intent. |
| 12 | */ |
tom | 6db1f0a | 2014-10-07 09:12:29 -0700 | [diff] [blame] | 13 | @Command(scope = "onos", name = "remove-intent", |
| 14 | description = "Removes the specified intent") |
| 15 | public class IntentRemoveCommand extends AbstractShellCommand { |
Brian O'Connor | a4cab07 | 2014-10-03 18:46:39 -0700 | [diff] [blame] | 16 | |
| 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 | } |
| 29 | IntentId intentId = new IntentId(Long.parseLong(id, radix)); |
| 30 | |
| 31 | |
| 32 | Intent intent = service.getIntent(intentId); |
| 33 | if (intent != null) { |
| 34 | service.withdraw(intent); |
| 35 | } |
| 36 | } |
| 37 | } |