Bug 8972: dhcp-show does not display the defaults
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-shell / src / main / java / org / opendaylight / netvirt / neutronvpn / shell / DhcpShowCommand.java
index 653d7a5f9bb692ed5a2b88b2a7e15f1a0529cf91..5f96629a391b1b623c49d1d0702a52176842e093 100644 (file)
@@ -14,6 +14,7 @@ import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -38,17 +39,14 @@ public class DhcpShowCommand extends OsgiCommandSupport {
         try {
             InstanceIdentifier<DhcpConfig> iid = InstanceIdentifier.create(DhcpConfig.class);
             DhcpConfig dhcpConfig = read(iid);
-            if (dhcpConfig == null || dhcpConfig.getConfigs() == null) {
-                //TODO: Should we print the defaults?
-                session.getConsole().println("Failed to get DHCP Configuration. Try again");
-                return null;
-            }
-            if (!dhcpConfig.getConfigs().isEmpty()) {
+            if (isDhcpConfigAvailable(dhcpConfig)) {
                 leaseDuration = dhcpConfig.getConfigs().get(0).getLeaseDuration();
                 defDomain = dhcpConfig.getConfigs().get(0).getDefaultDomain();
             }
-            session.getConsole().println("Lease Duration: " + ((leaseDuration != null) ? leaseDuration : 86400));
-            session.getConsole().println("Default Domain: " + ((defDomain != null) ? defDomain : "openstacklocal"));
+            session.getConsole().println(
+                    "Lease Duration: " + ((leaseDuration != null) ? leaseDuration : DhcpMConstants.DEFAULT_LEASE_TIME));
+            session.getConsole().println(
+                    "Default Domain: " + ((defDomain != null) ? defDomain : DhcpMConstants.DEFAULT_DOMAIN_NAME));
         } catch (Exception e) {
             session.getConsole().println("Failed to fetch configuration parameters. Try again");
             LOG.error("Failed to fetch DHCP parameters",e);
@@ -56,6 +54,11 @@ public class DhcpShowCommand extends OsgiCommandSupport {
         return null;
     }
 
+    private boolean isDhcpConfigAvailable(DhcpConfig dhcpConfig) {
+        return dhcpConfig != null && dhcpConfig.getConfigs() != null
+                && !dhcpConfig.getConfigs().isEmpty();
+    }
+
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     private DhcpConfig read(InstanceIdentifier<DhcpConfig> iid) {