Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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.cfm.cli; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 22 | import org.onosproject.cfm.cli.completer.CfmMaNameCompleter; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 24 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 25 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 26 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 27 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService; |
| 28 | |
| 29 | /** |
| 30 | * Delete a Maintenance Association from the existing list of a Maintenance Domain. |
| 31 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 32 | @Service |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 33 | @Command(scope = "onos", name = "cfm-ma-delete", |
| 34 | description = "Delete a CFM Maintenance Association and its children.") |
| 35 | public class CfmMaDeleteCommand extends AbstractShellCommand { |
| 36 | |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 37 | private static final int MA_NAME_PARTS_COUNT = 4; |
| 38 | @Argument(name = "name", |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 39 | description = "Maintenance Domain name and type (in brackets) " + |
| 40 | "and the Maintenance Association name and type (in brackets)", |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 41 | required = true) |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 42 | @Completion(CfmMaNameCompleter.class) |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 43 | private String name = null; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 44 | |
| 45 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 46 | protected void doExecute() { |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 47 | CfmMdService service = get(CfmMdService.class); |
| 48 | |
| 49 | String[] nameParts = name.split("[()]"); |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 50 | if (nameParts.length != MA_NAME_PARTS_COUNT) { |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 51 | throw new IllegalArgumentException("Invalid name format. Must be in " + |
| 52 | "the format of <identifier(name-type)identifier(name-type)>"); |
| 53 | } |
| 54 | |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 55 | MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")"); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 56 | |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 57 | MaIdShort maId = CfmMdListMdCommand.parseMaName(nameParts[2] + "(" + nameParts[3] + ")"); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 58 | |
| 59 | try { |
| 60 | boolean deleted = service.deleteMaintenanceAssociation(mdId, maId); |
| 61 | print("Maintenance Association %s-%s is %ssuccessfully deleted.", |
| 62 | mdId, maId, deleted ? "" : "NOT "); |
| 63 | } catch (CfmConfigException e) { |
| 64 | throw new IllegalArgumentException(e); |
| 65 | } |
| 66 | } |
| 67 | } |