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 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
| 23 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName; |
| 24 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdMacUint; |
| 25 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdNone; |
| 26 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 27 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService; |
| 28 | |
| 29 | /** |
| 30 | * Deletes a Maintenance Domain from the existing list. |
| 31 | */ |
| 32 | @Command(scope = "onos", name = "cfm-md-delete", |
| 33 | description = "Delete a CFM Maintenance Domain and its children.") |
| 34 | public class CfmMdDeleteCommand extends AbstractShellCommand { |
| 35 | |
| 36 | @Argument(index = 0, name = "name", |
| 37 | description = "Maintenance Domain name and type (in brackets)", |
| 38 | required = true, multiValued = false) |
| 39 | String name = null; |
| 40 | |
| 41 | @Override |
| 42 | protected void execute() { |
| 43 | CfmMdService service = get(CfmMdService.class); |
| 44 | |
| 45 | String[] nameParts = name.split("[()]"); |
| 46 | if (nameParts.length != 2) { |
| 47 | throw new IllegalArgumentException("Invalid name format. " + |
| 48 | "Must be in the format of <identifier(name-type)>"); |
| 49 | } |
| 50 | |
| 51 | MdId mdId = null; |
| 52 | MdId.MdNameType nameTypeEnum = MdId.MdNameType.valueOf(nameParts[1]); |
| 53 | switch (nameTypeEnum) { |
| 54 | case DOMAINNAME: |
| 55 | mdId = MdIdDomainName.asMdId(nameParts[0]); |
| 56 | break; |
| 57 | case MACANDUINT: |
| 58 | mdId = MdIdMacUint.asMdId(nameParts[0]); |
| 59 | break; |
| 60 | case NONE: |
| 61 | mdId = MdIdNone.asMdId(); |
| 62 | break; |
| 63 | case CHARACTERSTRING: |
| 64 | default: |
| 65 | mdId = MdIdCharStr.asMdId(nameParts[0]); |
| 66 | } |
| 67 | |
| 68 | try { |
| 69 | boolean deleted = service.deleteMaintenanceDomain(mdId); |
| 70 | print("Maintenance Domain %s is %ssuccessfully deleted.", |
| 71 | mdId, deleted ? "" : "NOT "); |
| 72 | } catch (CfmConfigException e) { |
| 73 | throw new IllegalArgumentException(e); |
| 74 | } |
| 75 | } |
| 76 | } |