2484a555dd8f6c39ac12f6c362740be230cca36c
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / cli / etree / EtreeInterfaceDelete.java
1 /*
2  * Copyright (c) 2016 Hewlett Packard Enterprise, Co. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netvirt.elan.cli.etree;
9
10 import javax.annotation.Nullable;
11 import org.apache.karaf.shell.commands.Argument;
12 import org.apache.karaf.shell.commands.Command;
13 import org.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.opendaylight.netvirt.elanmanager.api.IElanService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInterface;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 @Command(scope = "etreeInterface", name = "delete", description = "deleting Etree Interface")
21 public class EtreeInterfaceDelete extends OsgiCommandSupport {
22
23     @Argument(index = 0, name = "etreeName", description = "ETREE-NAME", required = true, multiValued = false)
24     private String etreeName;
25     @Argument(index = 1, name = "interfaceName", description = "InterfaceName", required = true, multiValued = false)
26     private String interfaceName;
27     private static final Logger LOG = LoggerFactory.getLogger(EtreeInterfaceDelete.class);
28     private IElanService elanProvider;
29
30     public void setElanProvider(IElanService elanServiceProvider) {
31         this.elanProvider = elanServiceProvider;
32     }
33
34     @Override
35     @Nullable
36     protected Object doExecute() {
37         LOG.debug("Deleting EtreeInterface command etreeName:{}, interfaceName:{}", etreeName, interfaceName);
38         ElanInterface existingInterface =
39                 elanProvider.getElanInterfaceByElanInterfaceName(interfaceName);
40         if (existingInterface == null || existingInterface.augmentation(EtreeInterface.class) == null) {
41             session.getConsole()
42                     .println("Etree interface doesn't exist or isn't configured as etree: " + interfaceName);
43         }
44         elanProvider.deleteEtreeInterface(interfaceName);
45         session.getConsole().println("Deleted the Etree interface succesfully");
46         return null;
47     }
48 }