Correct deletion of reservations
This commit is contained in:
parent
a72978e33d
commit
d1ef073a8e
|
@ -504,7 +504,7 @@ def add_dhcp_reservation(zk_conn, network, ipaddress, macaddress, hostname):
|
||||||
|
|
||||||
return True, 'DHCP reservation "{}" added successfully!'.format(macaddress)
|
return True, 'DHCP reservation "{}" added successfully!'.format(macaddress)
|
||||||
|
|
||||||
def remove_dhcp_lease(zk_conn, network, lease):
|
def remove_dhcp_reservation(zk_conn, network, reservation):
|
||||||
# Validate and obtain standard passed value
|
# Validate and obtain standard passed value
|
||||||
net_vni = getNetworkVNI(zk_conn, network)
|
net_vni = getNetworkVNI(zk_conn, network)
|
||||||
if net_vni == None:
|
if net_vni == None:
|
||||||
|
@ -513,23 +513,23 @@ def remove_dhcp_lease(zk_conn, network, lease):
|
||||||
match_description = ''
|
match_description = ''
|
||||||
|
|
||||||
# Check if the reservation matches a description, a mac, or an IP address currently in the database
|
# Check if the reservation matches a description, a mac, or an IP address currently in the database
|
||||||
dhcp_leases_list = zk_conn.get_children('/networks/{}/dhcp_leases'.format(net_vni))
|
dhcp_reservations_list = zk_conn.get_children('/networks/{}/dhcp_reservations'.format(net_vni))
|
||||||
for macaddr in dhcp_leases_list:
|
for macaddr in dhcp_reservations_list:
|
||||||
hostname = zkhandler.readdata(zk_conn, '/networks/{}/dhcp_leases/{}/hostname'.format(net_vni, macaddr))
|
hostname = zkhandler.readdata(zk_conn, '/networks/{}/dhcp_reservations/{}/hostname'.format(net_vni, macaddr))
|
||||||
ipaddress = zkhandler.readdata(zk_conn, '/networks/{}/dhcp_leases/{}/ipaddr'.format(net_vni, macaddr))
|
ipaddress = zkhandler.readdata(zk_conn, '/networks/{}/dhcp_reservations/{}/ipaddr'.format(net_vni, macaddr))
|
||||||
if lease == macaddr or lease == hostname or lease == ipaddress:
|
if reservation == macaddr or reservation == hostname or reservation == ipaddress:
|
||||||
match_description = macaddr
|
match_description = macaddr
|
||||||
|
|
||||||
if not match_description:
|
if not match_description:
|
||||||
return False, 'ERROR: No DHCP lease exists matching "{}"!'.format(reservation)
|
return False, 'ERROR: No DHCP reservation exists matching "{}"!'.format(reservation)
|
||||||
|
|
||||||
# Remove the entry from zookeeper
|
# Remove the entry from zookeeper
|
||||||
try:
|
try:
|
||||||
zk_conn.delete('/networks/{}/dhcp_leases/{}'.format(net_vni, match_description), recursive=True)
|
zk_conn.delete('/networks/{}/dhcp_reservations/{}'.format(net_vni, match_description), recursive=True)
|
||||||
except:
|
except:
|
||||||
return False, 'ERROR: Failed to write to Zookeeper!'
|
return False, 'ERROR: Failed to write to Zookeeper!'
|
||||||
|
|
||||||
return True, 'DHCP lease "{}" removed successfully!'.format(match_description)
|
return True, 'DHCP reservation "{}" removed successfully!'.format(match_description)
|
||||||
|
|
||||||
def get_info(zk_conn, network, long_output):
|
def get_info(zk_conn, network, long_output):
|
||||||
# Validate and obtain alternate passed value
|
# Validate and obtain alternate passed value
|
||||||
|
|
Loading…
Reference in New Issue