sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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.segmentrouting.cli; |
| 17 | |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 22 | import org.onosproject.segmentrouting.PolicyHandler; |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 24 | import org.onosproject.segmentrouting.TunnelPolicy; |
| 25 | |
| 26 | /** |
sangho | 316d438 | 2015-06-24 09:37:40 -0700 | [diff] [blame] | 27 | * Command to remove a policy. |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 28 | */ |
| 29 | @Command(scope = "onos", name = "srpolicy-remove", |
| 30 | description = "Remove a policy") |
| 31 | public class PolicyRemoveCommand extends AbstractShellCommand { |
| 32 | |
| 33 | @Argument(index = 0, name = "policy ID", |
| 34 | description = "policy ID", |
| 35 | required = true, multiValued = false) |
| 36 | String policyId; |
| 37 | |
| 38 | @Override |
| 39 | protected void execute() { |
| 40 | |
| 41 | SegmentRoutingService srService = |
| 42 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 43 | |
| 44 | TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId); |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 45 | PolicyHandler.Result result = srService.removePolicy(tpb.build()); |
| 46 | if (result == PolicyHandler.Result.POLICY_NOT_FOUND) { |
| 47 | print("ERROR: the policy is not found"); |
| 48 | } |
sangho | 2eae4c6 | 2015-06-11 14:49:59 -0700 | [diff] [blame] | 49 | } |
| 50 | } |