2 * Copyright (c) 2016 Hewlett Packard Enterprise, Co. and others. All rights reserved.
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
8 package org.opendaylight.netvirt.elan.cli.etree;
10 import org.apache.karaf.shell.commands.Argument;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.netvirt.elanmanager.api.IElanService;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 @Command(scope = "etree", name = "add", description = "adding Etree Instance")
18 public class EtreeAdd extends OsgiCommandSupport {
19 private static final int MAX_LENGTH = 31;
21 @Argument(index = 0, name = "etreeName", description = "ETREE-NAME", required = true, multiValued = false)
22 private String etreeName;
23 @Argument(index = 1, name = "macTimeOut", description = "MAC Time-Out", required = false, multiValued = false)
24 private long macTimeOut = -1;
25 @Argument(index = 2, name = "elanDescr", description = "ELAN-Description", required = false, multiValued = false)
26 private String etreeDescr;
27 private static final Logger LOG = LoggerFactory.getLogger(EtreeAdd.class);
28 private IElanService elanProvider;
30 public void setElanProvider(IElanService elanServiceProvider) {
31 this.elanProvider = elanServiceProvider;
35 protected Object doExecute() throws Exception {
36 if (macTimeOut == -1) {
40 LOG.debug("Executing create EtreeInstance command" + "\t" + etreeName + "\t" + macTimeOut + "\t"
42 if (etreeName.length() <= MAX_LENGTH) {
43 boolean isSuccess = elanProvider.createEtreeInstance(etreeName, macTimeOut, etreeDescr);
45 session.getConsole().println("Etree Instance was created successfully");
48 session.getConsole().println("Failed to create Etree Instance, max length is allowed 1 .. 31");