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 org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 @Command(scope = "vpnservice", name = "dhcp-show", description = "showing parameters for DHCP Service")
24 public class DhcpShowCommand extends OsgiCommandSupport {
26 private static final Logger LOG = LoggerFactory.getLogger(DhcpShowCommand.class);
28 private DataBroker dataBroker;
29 private Integer leaseDuration = null;
30 private String defDomain = null;
32 public void setDataBroker(DataBroker broker) {
33 this.dataBroker = broker;
37 protected Object doExecute() throws Exception {
38 InstanceIdentifier<DhcpConfig> iid = InstanceIdentifier.create(DhcpConfig.class);
39 DhcpConfig dhcpConfig = SingleTransactionDataBroker.syncRead(dataBroker, CONFIGURATION, iid);
40 if (isDhcpConfigAvailable(dhcpConfig)) {
41 leaseDuration = dhcpConfig.getConfigs().get(0).getLeaseDuration();
42 defDomain = dhcpConfig.getConfigs().get(0).getDefaultDomain();
44 session.getConsole().println("DHCP Config not present");
45 LOG.error("doExecute: DHCP Config not present");
47 session.getConsole().println(
48 "Lease Duration: " + (leaseDuration != null ? leaseDuration : DhcpMConstants.DEFAULT_LEASE_TIME));
49 session.getConsole().println(
50 "Default Domain: " + (defDomain != null ? defDomain : DhcpMConstants.DEFAULT_DOMAIN_NAME));
54 private boolean isDhcpConfigAvailable(DhcpConfig dhcpConfig) {
55 return dhcpConfig != null && dhcpConfig.getConfigs() != null
56 && !dhcpConfig.getConfigs().isEmpty();