Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.portloadbalancer.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.portloadbalancer.api.PortLoadBalancer; |
| 23 | import org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService; |
| 24 | import org.onosproject.portloadbalancer.api.PortLoadBalancerId; |
| 25 | import 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 ") |
| 32 | public 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 | } |