From 5533c9228763a491bde616aabd631c4951ee0134 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Fri, 27 Oct 2017 00:15:56 +0000 Subject: [PATCH] [updategraph] Support a special value to use empty configuration --- files/dhcp/graphserviceurl | 2 +- files/image_config/updategraph/updategraph | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/files/dhcp/graphserviceurl b/files/dhcp/graphserviceurl index f255cdff9877..5c5d801cbc8c 100644 --- a/files/dhcp/graphserviceurl +++ b/files/dhcp/graphserviceurl @@ -3,7 +3,7 @@ case $reason in if [ -n "$new_minigraph_url" ]; then echo $new_minigraph_url > /tmp/dhcp_graph_url else - echo "N/A" > /tmp/dhcp_graph_url + echo "default" > /tmp/dhcp_graph_url fi if [ -n "$new_acl_url" ]; then echo $new_acl_url > /tmp/dhcp_acl_url diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 4e9846fba024..b72bc6e2c1c8 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -20,8 +20,25 @@ if [ "$src" = "dhcp" ]; then sleep 1 done + if [ "`cat /tmp/dhcp_graph_url`" = "default" ]; then + echo "No graph_url option in DHCP response. Skipping graph update and using existing minigraph." + if [ "$dhcp_as_static" = "true" ]; then + sed -i "/enabled=/d" /etc/sonic/updategraph.conf + echo "enabled=false" >> /etc/sonic/updategraph.conf + fi + exit 0 + fi if [ "`cat /tmp/dhcp_graph_url`" = "N/A" ]; then - echo "No graph_url option in DHCP response. Skipping graph update." + echo "'N/A' found in DHCP response. Skipping graph update and generating an empty configuration." + echo '{"DEVICE_METADATA":' > /tmp/device_meta.json + sonic-cfggen -m /etc/sonic/minigraph.xml --var-json DEVICE_METADATA >> /tmp/device_meta.json + echo '}' >> /tmp/device_meta.json + if [ -f /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /tmp/device_meta.json -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json + else + cp -f /tmp/device_meta.json /etc/sonic/config_db.json + fi + if [ "$dhcp_as_static" = "true" ]; then sed -i "/enabled=/d" /etc/sonic/updategraph.conf echo "enabled=false" >> /etc/sonic/updategraph.conf @@ -29,6 +46,7 @@ if [ "$src" = "dhcp" ]; then exit 0 fi + HOSTNAME=`hostname -s` GRAPH_URL=`sonic-cfggen -t /tmp/dhcp_graph_url -a "{\"hostname\": \"$HOSTNAME\"}"` URL_REGEX='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'