3e9e784f8f3812406df9a170ddb6dbee93ab1c2c
[netvirt.git] / vpnservice / dhcpservice / dhcpservice-impl / src / main / java / org / opendaylight / netvirt / dhcpservice / jobs / DhcpAllocationPoolRemoveJob.java
1 /*
2  * Copyright (c) 2017 Hewlett Packard Enterprise, Co. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.dhcpservice.jobs;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
17
18 public class DhcpAllocationPoolRemoveJob implements Callable<List<ListenableFuture<Void>>> {
19
20     private final DataBroker dataBroker;
21     private final String interfaceName;
22
23     public DhcpAllocationPoolRemoveJob(DataBroker dataBroker, String interfaceName) {
24         super();
25         this.dataBroker = dataBroker;
26         this.interfaceName = interfaceName;
27     }
28
29     @Override
30     public List<ListenableFuture<Void>> call() throws Exception {
31         return unInstallDhcpEntries(interfaceName);
32     }
33
34     private List<ListenableFuture<Void>> unInstallDhcpEntries(String interfaceName) {
35         WriteTransaction unbindServiceTx = dataBroker.newWriteOnlyTransaction();
36         DhcpServiceUtils.unbindDhcpService(interfaceName, unbindServiceTx);
37         return Collections.singletonList(unbindServiceTx.submit());
38     }
39
40 }