blob: 7cd07a1d35bbf597961fcf724ee55159c176dfc9 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
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 */
16package org.onosproject.cfm.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Sean Condon0e89bda2017-03-21 14:23:19 +000021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
Sean Condon0e89bda2017-03-21 14:23:19 +000023import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
24import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
25
26/**
27 * Deletes a Maintenance Domain from the existing list.
28 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070029@Service
Sean Condon0e89bda2017-03-21 14:23:19 +000030@Command(scope = "onos", name = "cfm-md-delete",
31 description = "Delete a CFM Maintenance Domain and its children.")
32public class CfmMdDeleteCommand extends AbstractShellCommand {
33
Sean Condon3a1efef2018-02-24 13:16:03 +000034 @Argument(name = "name",
Sean Condon0e89bda2017-03-21 14:23:19 +000035 description = "Maintenance Domain name and type (in brackets)",
Sean Condon3a1efef2018-02-24 13:16:03 +000036 required = true)
37 private String name = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000038
39 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070040 protected void doExecute() {
Sean Condon0e89bda2017-03-21 14:23:19 +000041 CfmMdService service = get(CfmMdService.class);
42
43 String[] nameParts = name.split("[()]");
44 if (nameParts.length != 2) {
45 throw new IllegalArgumentException("Invalid name format. " +
46 "Must be in the format of <identifier(name-type)>");
47 }
48
Sean Condon3a1efef2018-02-24 13:16:03 +000049 MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
Sean Condon0e89bda2017-03-21 14:23:19 +000050
51 try {
52 boolean deleted = service.deleteMaintenanceDomain(mdId);
53 print("Maintenance Domain %s is %ssuccessfully deleted.",
54 mdId, deleted ? "" : "NOT ");
55 } catch (CfmConfigException e) {
56 throw new IllegalArgumentException(e);
57 }
58 }
59}