jcc | de3e92e | 2015-03-28 01:40:44 -0700 | [diff] [blame] | 1 | package org.onosproject.cli.net; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.Iterator; |
| 5 | |
| 6 | import org.apache.karaf.shell.commands.Argument; |
| 7 | import org.apache.karaf.shell.commands.Command; |
| 8 | import org.onosproject.cli.AbstractShellCommand; |
| 9 | import org.onosproject.net.resource.DefaultLabelResource; |
| 10 | import org.onosproject.net.resource.LabelResource; |
| 11 | import org.onosproject.net.resource.LabelResourceService; |
| 12 | |
| 13 | @Command(scope = "onos", name = "apply-global-label-resource-pool", |
| 14 | description = "Apply global labels from global resource pool") |
| 15 | public class ApplyGlobalLabelResourceCommand extends AbstractShellCommand { |
| 16 | @Argument(index = 0, name = "applyNum", |
| 17 | description = "Applying number means how many labels applications want to use.", |
| 18 | required = true, multiValued = false) |
| 19 | String applyNum = null; |
| 20 | |
| 21 | private static final String FMT = "deviceid=%s, labelresourceid=%s"; |
| 22 | |
| 23 | @Override |
| 24 | protected void execute() { |
| 25 | LabelResourceService lrs = get(LabelResourceService.class); |
| 26 | Collection<LabelResource> result = |
| 27 | lrs.applyFromGlobalPool(Long.parseLong(applyNum)); |
| 28 | if (result.size() > 0) { |
| 29 | for (Iterator<LabelResource> iterator = result.iterator(); iterator |
| 30 | .hasNext();) { |
| 31 | DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator |
| 32 | .next(); |
| 33 | print(FMT, defaultLabelResource.deviceId().toString(), |
| 34 | defaultLabelResource.labelResourceId().toString()); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | } |