e8d5dc712e5d7c0ac7bc7391b3d73ae8df92bf8f
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / cli / etree / EtreeAdd.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.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 @Command(scope = "etree", name = "add", description = "adding Etree Instance")
19 public class EtreeAdd extends OsgiCommandSupport {
20     private static final int MAX_LENGTH = 31;
21
22     @Argument(index = 0, name = "etreeName", description = "ETREE-NAME", required = true, multiValued = false)
23     private String etreeName;
24     @Argument(index = 1, name = "macTimeOut", description = "MAC Time-Out", required = false, multiValued = false)
25     private long macTimeOut = -1;
26     @Argument(index = 2, name = "elanDescr", description = "ELAN-Description", required = false, multiValued = false)
27     private String etreeDescr;
28     private static final Logger LOG = LoggerFactory.getLogger(EtreeAdd.class);
29     private IElanService elanProvider;
30
31     public void setElanProvider(IElanService elanServiceProvider) {
32         this.elanProvider = elanServiceProvider;
33     }
34
35     @Override
36     @Nullable
37     protected Object doExecute() {
38         if (macTimeOut == -1) {
39             macTimeOut = 30;
40         }
41
42         LOG.debug("Executing create EtreeInstance command etreeName:{}, macTimeOut:{}, etreeDescr:{}",
43                 etreeName, macTimeOut, etreeDescr);
44         if (etreeName.length() <= MAX_LENGTH) {
45             boolean isSuccess = elanProvider.createEtreeInstance(etreeName, macTimeOut, etreeDescr);
46             if (isSuccess) {
47                 session.getConsole().println("Etree Instance was created successfully");
48             }
49         } else {
50             session.getConsole().println("Failed to create Etree Instance, max length is allowed 1 .. 31");
51         }
52         return null;
53     }
54 }