blob: 8d19a275b8bda547d82d34072b9068cc61e8a49d [file] [log] [blame]
Charles Chanf7b1b4b2019-01-16 15:30:39 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
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 */
16package org.onosproject.portloadbalancer.cli;
17
18import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.portloadbalancer.api.PortLoadBalancer;
23import org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService;
24import org.onosproject.portloadbalancer.api.PortLoadBalancerId;
25import org.onosproject.net.DeviceId;
26
27/**
28 * Command to remove a port load balancer.
29 */
30@Service
31@Command(scope = "onos", name = "plb-remove", description = "Remove port load balancers ")
32public class PortLoadBalancerRemoveCommand extends AbstractShellCommand {
33 @Argument(index = 0, name = "deviceId",
34 description = "Device ID",
35 required = true, multiValued = false)
36 private String deviceIdStr;
37
38 @Argument(index = 1, name = "key",
39 description = "port load balancer key",
40 required = true, multiValued = false)
41 private String keyStr;
42
43 // Operation constants
44 private static final String EXECUTED = "Executed";
45 private static final String FAILED = "Failed";
46
47 @Override
48 protected void doExecute() {
49 DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
50 int portLoadBalancerKey = Integer.parseInt(keyStr);
51
52 PortLoadBalancerAdminService portLoadBalancerAdminService = get(PortLoadBalancerAdminService.class);
53 PortLoadBalancerId portLoadBalancerId = new PortLoadBalancerId(deviceId, portLoadBalancerKey);
54 PortLoadBalancer portLoadBalancer = portLoadBalancerAdminService.remove(portLoadBalancerId);
55 print("Removal of %s %s", portLoadBalancerId, portLoadBalancer != null ? EXECUTED : FAILED);
56 }
57}