blob: dabd39142e49dead3107938311d99ee0ad1cac65 [file] [log] [blame]
jccde3e92e2015-03-28 01:40:44 -07001package org.onosproject.cli.net;
2
3import java.util.Collection;
4import java.util.Iterator;
5
6import org.apache.karaf.shell.commands.Argument;
7import org.apache.karaf.shell.commands.Command;
8import org.onosproject.cli.AbstractShellCommand;
9import org.onosproject.net.DeviceId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070010import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
11import org.onosproject.incubator.net.resource.label.LabelResource;
12import org.onosproject.incubator.net.resource.label.LabelResourceService;
jccde3e92e2015-03-28 01:40:44 -070013
14@Command(scope = "onos", name = "apply-label-resource-pool",
15 description = "Apply label resource from device pool by specific device id")
16public 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}