-
Notifications
You must be signed in to change notification settings - Fork 1.8k
hostcfgd service enhancements to support Management interface config handling in SONiC #4546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() |
| 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 | ||
| # | ||
|
|
||
|
|
||
| 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" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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.