Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ sudo cp files/dhcp/sethostname6 $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
sudo cp files/dhcp/graphserviceurl $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
sudo cp files/dhcp/vrf $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
sudo cp files/dhcp/dhcp_mgmt_interface $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/
sudo cp files/dhcp/dhcp_mgmt_conf.py $FILESYSTEM_ROOT/usr/bin/
if [ -f files/image_config/ntp/ntp ]; then
sudo cp ./files/image_config/ntp/ntp $FILESYSTEM_ROOT/etc/init.d/
fi
Expand Down
34 changes: 34 additions & 0 deletions files/dhcp/dhcp_mgmt_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python -u
# -*- coding: utf-8 -*-

import sys
import syslog
import ipaddress
from swsssdk import ConfigDBConnector

APP_MGMT_INTF_TABLE = "MGMT_INTF_TABLE"

def update_dhcp_mgmt_ip_info():
app_db = ConfigDBConnector()
app_db.db_connect('APPL_DB', wait_for_init=False, retry_on=True)
appdb_entry = {}
appdb_entry["NULL"] = "NULL"

op = sys.argv[2]
plen = ipaddress.ip_network((0, sys.argv[4])).prefixlen
key = sys.argv[1] + ":" + sys.argv[3] + "/" + str(plen)
syslog.syslog(syslog.LOG_INFO, "update_dhcp_mgmt_ip_info : op - {}, key - {}".format(op, key))
if op == "add":
app_db.set_entry(APP_MGMT_INTF_TABLE, key, appdb_entry)
elif op == "del":
app_db.delete_entry(APP_MGMT_INTF_TABLE, key)
return

if __name__ == "__main__":
if len(sys.argv) < 5:
syslog.syslog(syslog.LOG_INFO, "number of arguments not correct")
syslog.syslog(syslog.LOG_INFO, "usage:")
syslog.syslog(syslog.LOG_INFO, "dhcp_mgmt_conf.py <add/del> <interface name> <ip address> <subnet mask>")
else:
syslog.syslog(syslog.LOG_INFO, "Args : {}".format(sys.argv))
update_dhcp_mgmt_ip_info()
53 changes: 53 additions & 0 deletions files/dhcp/dhcp_mgmt_interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh
#
# DHCLIENT exit hook for ip address update in app db
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some more comments to explain why this information needs to be added in APP DB.

#


set -x

PYTHON_PATH=/usr/bin/python
SCRIPT=/usr/bin/dhcp_mgmt_conf.py


dhcp_mgmt_conf_handle() {
IF_NAME=$interface
echo "dhcp_mgmt_conf_handle, interface : $IF_NAME"

if [ "$IF_NAME" = "eth0" ]; then
echo "DHCP exit hook is called for $IF_NAME, reason : $reason"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you updated this echo "... called for $IF_NAME for updating ip addr in app db, reason : $reason" ?


case $reason in
BOUND|REBOOT|BOUND6)
if [ -n "$new_ip_address" ] && [ -n "$new_subnet_mask" ]; then

$PYTHON_PATH $SCRIPT $IF_NAME add $new_ip_address $new_subnet_mask
fi
;;
RENEW|REBIND|RENEW6|REBIND6)
if [ -n "$old_ip_address" ] && [ -n "$old_subnet_mask" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to explain where and how the old_ip_address and old_subnet_mask are updated?

$PYTHON_PATH $SCRIPT $IF_NAME del $old_ip_address $old_subnet_mask
fi

if [ -n "$new_ip_address" ] && [ -n "$new_subnet_mask" ]; then
$PYTHON_PATH $SCRIPT $IF_NAME add $new_ip_address $new_subnet_mask
fi

;;
EXPIRE|FAIL|RELEASE|STOP)
if [ -n "$new_ip_address" ] && [ -n "$new_subnet_mask" ]; then
$PYTHON_PATH $SCRIPT $IF_NAME del $new_ip_address $new_subnet_mask
fi

if [ -n "$old_ip_address" ] && [ -n "$old_subnet_mask" ]; then
$PYTHON_PATH $SCRIPT $IF_NAME del $old_ip_address $old_subnet_mask
fi
;;
TIMEOUT)
;;
esac
fi
}

echo "dhcp_mgmt_conf"
dhcp_mgmt_conf_handle
Loading