blob: 575d35f9d9da4d42ebd5ea3e2e035380f1fa4f7b [file] [log] [blame]
sangho6703da22015-06-11 14:49:59 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho6703da22015-06-11 14:49:59 -07003 *
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.segmentrouting.cli;
17
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
sangho6703da22015-06-11 14:49:59 -070022import org.onosproject.cli.AbstractShellCommand;
sangho71abe1b2015-06-29 14:58:47 -070023import org.onosproject.segmentrouting.PolicyHandler;
sangho6703da22015-06-11 14:49:59 -070024import org.onosproject.segmentrouting.SegmentRoutingService;
25import org.onosproject.segmentrouting.TunnelPolicy;
26
27/**
sangho36c9d2c2015-06-24 09:37:40 -070028 * Command to remove a policy.
sangho6703da22015-06-11 14:49:59 -070029 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070030@Service
Saurav Das59232cf2016-04-27 18:35:50 -070031@Command(scope = "onos", name = "sr-policy-remove",
sangho6703da22015-06-11 14:49:59 -070032 description = "Remove a policy")
33public class PolicyRemoveCommand extends AbstractShellCommand {
34
35 @Argument(index = 0, name = "policy ID",
36 description = "policy ID",
37 required = true, multiValued = false)
38 String policyId;
39
40 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070041 protected void doExecute() {
sangho6703da22015-06-11 14:49:59 -070042
43 SegmentRoutingService srService =
44 AbstractShellCommand.get(SegmentRoutingService.class);
45
46 TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(policyId);
sangho71abe1b2015-06-29 14:58:47 -070047 PolicyHandler.Result result = srService.removePolicy(tpb.build());
48 if (result == PolicyHandler.Result.POLICY_NOT_FOUND) {
49 print("ERROR: the policy is not found");
50 }
sangho6703da22015-06-11 14:49:59 -070051 }
52}