Skip to content
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

[updategraph] Support a special value to use empty configuration #1086

Merged
merged 1 commit into from
Oct 28, 2017
Merged
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: 1 addition & 1 deletion files/dhcp/graphserviceurl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion files/image_config/updategraph/updategraph
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@ 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
fi
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\+&@#/%=~_|]$'
Expand Down