Search in sources :

Example 1 with DhcpConfigBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfigBuilder in project netvirt by opendaylight.

the class DhcpConfigureCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (defaultDomain == null && leaseDuration == null) {
        session.getConsole().println(getHelp());
        return null;
    }
    Integer currLeaseDuration = DhcpMConstants.DEFAULT_LEASE_TIME;
    String currDefDomain = DhcpMConstants.DEFAULT_DOMAIN_NAME;
    ConfigsBuilder dccBuilder = new ConfigsBuilder();
    InstanceIdentifier<DhcpConfig> iid = InstanceIdentifier.create(DhcpConfig.class);
    DhcpConfig currentConfig = SingleTransactionDataBroker.syncRead(dataBroker, CONFIGURATION, iid);
    if (currentConfig != null && currentConfig.getConfigs() != null && !currentConfig.getConfigs().isEmpty()) {
        Configs dhcpConfig = currentConfig.getConfigs().get(0);
        if (dhcpConfig.getLeaseDuration() != null) {
            currLeaseDuration = dhcpConfig.getLeaseDuration();
        }
        if (dhcpConfig.getDefaultDomain() != null) {
            currDefDomain = dhcpConfig.getDefaultDomain();
        }
    }
    dccBuilder.setLeaseDuration(leaseDuration == null ? currLeaseDuration : leaseDuration);
    dccBuilder.setDefaultDomain(defaultDomain == null ? currDefDomain : defaultDomain);
    List<Configs> configList = Collections.singletonList(dccBuilder.build());
    DhcpConfigBuilder dcBuilder = new DhcpConfigBuilder();
    dcBuilder.setConfigs(configList);
    SingleTransactionDataBroker.syncWrite(dataBroker, CONFIGURATION, iid, dcBuilder.build());
    return null;
}
Also used : ConfigsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.ConfigsBuilder) DhcpConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig) Configs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.Configs) DhcpConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfigBuilder)

Aggregations

DhcpConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig)1 DhcpConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfigBuilder)1 Configs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.Configs)1 ConfigsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.ConfigsBuilder)1