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.DeviceId; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame^] | 10 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; |
| 11 | import org.onosproject.incubator.net.resource.label.LabelResource; |
| 12 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
jcc | de3e92e | 2015-03-28 01:40:44 -0700 | [diff] [blame] | 13 | |
| 14 | @Command(scope = "onos", name = "apply-label-resource-pool", |
| 15 | description = "Apply label resource from device pool by specific device id") |
| 16 | public class ApplyLabelResourceCommand extends AbstractShellCommand { |
| 17 | @Argument(index = 0, name = "deviceId", |
| 18 | description = "Device identity", |
| 19 | required = true, multiValued = false) |
| 20 | String deviceId = null; |
| 21 | @Argument(index = 1, name = "applyNum", |
| 22 | description = "Applying number means how many labels applications want to use.", |
| 23 | required = true, multiValued = false) |
| 24 | String applyNum = null; |
| 25 | |
| 26 | private static final String FMT = "deviceid=%s, labelresourceid=%s"; |
| 27 | |
| 28 | @Override |
| 29 | protected void execute() { |
| 30 | LabelResourceService lrs = get(LabelResourceService.class); |
| 31 | Collection<LabelResource> result = lrs.applyFromDevicePool(DeviceId |
| 32 | .deviceId(deviceId), Long.parseLong(applyNum)); |
| 33 | if (result.size() > 0) { |
| 34 | for (Iterator<LabelResource> iterator = result.iterator(); iterator |
| 35 | .hasNext();) { |
| 36 | DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator |
| 37 | .next(); |
| 38 | print(FMT, defaultLabelResource.deviceId().toString(), |
| 39 | defaultLabelResource.labelResourceId().toString()); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | } |