blob: 06cd8e61d4c9bb23b7d92b1d9f39b9394774abd3 [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;
10import org.onosproject.net.resource.DefaultLabelResource;
11import org.onosproject.net.resource.LabelResource;
12import org.onosproject.net.resource.LabelResourceService;
13
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}