2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.netvirt.neutronvpn.shell;
11 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
13 import java.util.ArrayList;
14 import org.apache.karaf.shell.commands.Command;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.Configs;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 @Command(scope = "vpnservice", name = "dhcp-show", description = "showing parameters for DHCP Service")
26 public class DhcpShowCommand extends OsgiCommandSupport {
28 private static final Logger LOG = LoggerFactory.getLogger(DhcpShowCommand.class);
30 private DataBroker dataBroker;
31 private Integer leaseDuration = null;
32 private String defDomain = null;
34 public void setDataBroker(DataBroker broker) {
35 this.dataBroker = broker;
39 protected Object doExecute() throws Exception {
40 InstanceIdentifier<DhcpConfig> iid = InstanceIdentifier.create(DhcpConfig.class);
41 DhcpConfig dhcpConfig = SingleTransactionDataBroker.syncRead(dataBroker, CONFIGURATION, iid);
42 if (isDhcpConfigAvailable(dhcpConfig)) {
43 leaseDuration = new ArrayList<Configs>(dhcpConfig.getConfigs().values()).get(0).getLeaseDuration();
44 defDomain = new ArrayList<Configs>(dhcpConfig.getConfigs().values()).get(0).getDefaultDomain();
46 session.getConsole().println("DHCP Config not present");
47 LOG.error("doExecute: DHCP Config not present");
49 session.getConsole().println(
50 "Lease Duration: " + (leaseDuration != null ? leaseDuration : DhcpMConstants.DEFAULT_LEASE_TIME));
51 session.getConsole().println(
52 "Default Domain: " + (defDomain != null ? defDomain : DhcpMConstants.DEFAULT_DOMAIN_NAME));
56 private boolean isDhcpConfigAvailable(DhcpConfig dhcpConfig) {
57 return dhcpConfig != null && dhcpConfig.getConfigs() != null
58 && !dhcpConfig.getConfigs().isEmpty();