blob: f3810859155c87abd46e3fe1b2e172aa3616a275 [file] [log] [blame]
samuel7a5691a2015-05-23 00:36:32 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
samuel7a5691a2015-05-23 00:36:32 +08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
jccde3e92e2015-03-28 01:40:44 -070016package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.DeviceId;
Brian O'Connor6de2e202015-05-21 14:30:41 -070022import org.onosproject.incubator.net.resource.label.LabelResourcePool;
23import org.onosproject.incubator.net.resource.label.LabelResourceService;
jccde3e92e2015-03-28 01:40:44 -070024
samuel7a5691a2015-05-23 00:36:32 +080025@Command(scope = "onos", name = "label-pool",
jccde3e92e2015-03-28 01:40:44 -070026 description = "Gets label resource pool information by a specific device id")
samuel7a5691a2015-05-23 00:36:32 +080027public class LabelResourceCommand extends AbstractShellCommand {
jccde3e92e2015-03-28 01:40:44 -070028 @Argument(index = 0, name = "deviceId",
29 description = "Device identity", required = true, multiValued = false)
30 String deviceId = null;
31 private static final String FMT = "deviceid=%s, beginLabel=%s,"
32 + "endLabel=%s, totalNum=%s, usedNum=%s, currentUsedMaxLabelId=%s,"
33 + "releaseLabelIds=%s";
34
35 @Override
36 protected void execute() {
37 LabelResourceService lrs = get(LabelResourceService.class);
38 LabelResourcePool pool = lrs.getDeviceLabelResourcePool(DeviceId
39 .deviceId(deviceId));
40 if (pool != null) {
41 print(FMT, pool.deviceId().toString(), pool.beginLabel(),
42 pool.endLabel(), pool.totalNum(), pool.usedNum(),
43 pool.currentUsedMaxLabelId(), pool.releaseLabelId()
44 .toString());
45 } else {
46 print(FMT, deviceId, null, null, null, null, null, null);
47 }
48 }
49
50}