Add get_graph service to fetch minigraph automatically (#288)
- Add a functionality to get SNMP community from DHCP (option 224) - Add a functionality to get minigraph from http service instead of using default minigraph - The url for graph service is passed through DHCP option 225 - This feature is by default disabled. Modify rule/config to enable it on build time, or modify /etc/sonic/graph_service_url on run time. - Fix a bug that getting hostname from DHCP is not working correctly
This commit is contained in:
parent
2d0b41a340
commit
ea372cc7c1
@ -188,7 +188,8 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
|
||||
usbutils \
|
||||
pciutils \
|
||||
iptables-persistent \
|
||||
logrotate
|
||||
logrotate \
|
||||
curl
|
||||
|
||||
## Remove sshd host keys, and will regenerate on first sshd start
|
||||
sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key*
|
||||
@ -241,6 +242,9 @@ EOF
|
||||
|
||||
sudo cp files/dhcp/rfc3442-classless-routes $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d
|
||||
sudo cp files/dhcp/sethostname $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/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/
|
||||
|
||||
if [ -f sonic_debian_extension.sh ]; then
|
||||
./sonic_debian_extension.sh $FILESYSTEM_ROOT
|
||||
|
@ -94,6 +94,21 @@ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable interfaces-config.service
|
||||
sudo cp $IMAGE_CONFIGS/interfaces/interfaces-config.sh $FILESYSTEM_ROOT/usr/bin/
|
||||
sudo cp $IMAGE_CONFIGS/interfaces/*.j2 $FILESYSTEM_ROOT/etc/sonic/templates/
|
||||
|
||||
# Copy initial interfaces configuration file, will be overwritten on first boot
|
||||
sudo cp $IMAGE_CONFIGS/interfaces/init_interfaces $FILESYSTEM_ROOT/etc/network
|
||||
|
||||
# Copy updategraph script and service file
|
||||
sudo cp $IMAGE_CONFIGS/updategraph/updategraph.service $FILESYSTEM_ROOT/etc/systemd/system/
|
||||
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable updategraph.service
|
||||
sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/
|
||||
{% if enable_dhcp_graph_service == "y" %}
|
||||
sudo bash -c "echo enabled=true > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
||||
sudo bash -c "echo src=dhcp >> $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
||||
sudo bash -c "echo dhcp_as_static=true >> $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
||||
{% else %}
|
||||
sudo bash -c "echo enabled=false > $FILESYSTEM_ROOT/etc/sonic/updategraph.conf"
|
||||
{% endif %}
|
||||
|
||||
# Copy SNMP configuration files
|
||||
sudo cp $IMAGE_CONFIGS/snmp/snmp.yml $FILESYSTEM_ROOT/etc/sonic/
|
||||
|
||||
|
24
files/dhcp/dhclient.conf
Normal file
24
files/dhcp/dhclient.conf
Normal file
@ -0,0 +1,24 @@
|
||||
# Configuration file for /sbin/dhclient, which is included in Debian's
|
||||
# dhcp3-client package.
|
||||
#
|
||||
# This is a sample configuration file for dhclient. See dhclient.conf's
|
||||
# man page for more information about the syntax of this file
|
||||
# and a more comprehensive list of the parameters understood by
|
||||
# dhclient.
|
||||
#
|
||||
# Normally, if the DHCP server provides reasonable information and does
|
||||
# not leave anything out (like the domain name, for example), then
|
||||
# few changes must be made to this file, if any.
|
||||
#
|
||||
|
||||
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
|
||||
option snmp-community code 224 = text;
|
||||
option minigraph-url code 225 = text;
|
||||
|
||||
send host-name = gethostname();
|
||||
request subnet-mask, broadcast-address, time-offset, routers,
|
||||
domain-name, domain-name-servers, domain-search, host-name,
|
||||
dhcp6.name-servers, dhcp6.domain-search,
|
||||
netbios-name-servers, netbios-scope, interface-mtu,
|
||||
rfc3442-classless-static-routes, ntp-servers, snmp-community, minigraph-url;
|
||||
|
9
files/dhcp/graphserviceurl
Normal file
9
files/dhcp/graphserviceurl
Normal file
@ -0,0 +1,9 @@
|
||||
case $reason in
|
||||
BOUND|RENEW|REBIND|REBOOT)
|
||||
if [ -n "$new_minigraph_url" ]; then
|
||||
echo $new_minigraph_url > /tmp/dhcp_graph_url
|
||||
else
|
||||
echo "N/A" > /tmp/dhcp_graph_url
|
||||
fi
|
||||
;;
|
||||
esac
|
@ -1,20 +1,13 @@
|
||||
#!/bin/bash
|
||||
# This script is to update hostname of the system.
|
||||
|
||||
if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
|
||||
&& [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
current_host_name=`hostname -s`
|
||||
|
||||
if [ "$current_host_name" != "$new_host_name" ]
|
||||
then
|
||||
case $reason in
|
||||
BOUND|RENEW|REBIND|REBOOT)
|
||||
current_host_name=`hostname -s`
|
||||
if [ "$current_host_name" != "$new_host_name" ] && [ -n "$new_host_name" ]
|
||||
then
|
||||
echo $new_host_name > /etc/hostname
|
||||
line_to_replace=`grep 127.0.0.1.*$current_host_name /etc/hosts`
|
||||
new_line=`echo $line_to_replace | sed "s/$current_host_name/$new_host_name/"`
|
||||
sed -i "s/$line_to_replace/$new_line/" /etc/hosts
|
||||
|
||||
hostname -F /etc/hostname
|
||||
fi
|
||||
sed -i "/\s$current_host_name$/d" /etc/hosts
|
||||
echo "127.0.0.1 $new_host_name" >> /etc/hosts
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
11
files/dhcp/snmpcommunity
Normal file
11
files/dhcp/snmpcommunity
Normal file
@ -0,0 +1,11 @@
|
||||
case $reason in
|
||||
BOUND|RENEW|REBIND|REBOOT)
|
||||
if [ -n "${new_snmp_community}" ]; then
|
||||
if [ -f /etc/sonic/snmp.yml ]; then
|
||||
sed -i "s/^snmp_rocommunity:.*/snmp_rocommunity: $new_snmp_community/g" /etc/sonic/snmp.yml
|
||||
else
|
||||
echo "snmp_rocommunity: "$new_snmp_community > /etc/sonic/snmp.yml
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
11
files/image_config/interfaces/init_interfaces
Normal file
11
files/image_config/interfaces/init_interfaces
Normal file
@ -0,0 +1,11 @@
|
||||
# Initial /etc/network/interface file for first boot
|
||||
# Will be overwritten based on minigraph information by interfaces-config service
|
||||
|
||||
# The loopback network interface
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
#
|
||||
# The management network interface
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Unit]
|
||||
Description=Update interfaces configuration
|
||||
Before=network.target
|
||||
Before=database.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
|
@ -3,3 +3,6 @@
|
||||
sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/sonic/templates/interfaces.j2 >/etc/network/interfaces
|
||||
sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/sonic/templates/vlan_interfaces.j2 >/etc/network/interfaces.d/vlan_interfaces
|
||||
sonic-cfggen -m /etc/sonic/minigraph.xml -t /etc/sonic/templates/lag_interfaces.j2 >/etc/network/interfaces.d/lag_interfaces
|
||||
ifdown eth0 && ifup eth0
|
||||
ifdown lo && ifup lo
|
||||
|
||||
|
50
files/image_config/updategraph/updategraph
Executable file
50
files/image_config/updategraph/updategraph
Executable file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -f /etc/sonic/updategraph.conf ]; then
|
||||
echo "No updategraph.conf found, generating a default one."
|
||||
echo "enabled=false" >/etc/sonic/updategraph.conf
|
||||
fi
|
||||
|
||||
. /etc/sonic/updategraph.conf
|
||||
|
||||
if [ "$enabled" != "true" ]; then
|
||||
echo "Disabled in updategraph.conf. Skipping graph update."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$src" = "dhcp" ]; then
|
||||
while [ ! -f /tmp/dhcp_graph_url ]; do
|
||||
echo "Waiting for DHCP response..."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ "`cat /tmp/dhcp_graph_url`" = "N/A" ]; then
|
||||
echo "No graph_url option in DHCP response. Skipping graph update."
|
||||
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\"}"`
|
||||
if [ "$dhcp_as_static" = "true" ]; then
|
||||
sed -i "/src=d/d" /etc/sonic/updategraph.conf
|
||||
echo "src=$GRAPH_URL" >> /etc/sonic/updategraph.conf
|
||||
fi
|
||||
else
|
||||
GRAPH_URL=$src
|
||||
fi
|
||||
|
||||
if [ -f /etc/sonic/minigraph.xml ]; then
|
||||
echo "Renaming minigraph.xml to minigraph.old"
|
||||
mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.old
|
||||
fi
|
||||
|
||||
echo "Getting minigraph from $GRAPH_URL"
|
||||
|
||||
while true; do
|
||||
curl -f $GRAPH_URL -o /etc/sonic/minigraph.xml --connect-timeout 15 && break
|
||||
sleep 5
|
||||
done
|
12
files/image_config/updategraph/updategraph.service
Normal file
12
files/image_config/updategraph/updategraph.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=download minigraph from graph service
|
||||
Before=ntp-config.service
|
||||
Before=rsyslog-config.service
|
||||
Before=interfaces-config.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/updategraph
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -35,3 +35,10 @@ USERNAME = admin
|
||||
|
||||
# PASSWORD - password for installer build
|
||||
PASSWORD = YourPaSsWoRd
|
||||
|
||||
# ENABLE_DHCP_GRAPH_SERVICE - specify the source of minigraph to generate configuration file.
|
||||
# If set to y SONiC will get the minigraph from graph service. Graph service URL need to be
|
||||
# passed through DHCP option 225.
|
||||
# If not set (default behavior) the default minigraph built into the image will be used.
|
||||
# ENABLE_DHCP_GRAPH_SERVICE = y
|
||||
|
||||
|
2
slave.mk
2
slave.mk
@ -298,6 +298,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : .platform
|
||||
export sonicadmin_user="$(USERNAME)"
|
||||
export sonic_hwsku="$(CONFIGURED_SKU)"
|
||||
export sonic_asic_platform="$(CONFIGURED_PLATFORM)"
|
||||
export enable_dhcp_graph_service="$(ENABLE_DHCP_GRAPH_SERVICE)"
|
||||
|
||||
$(foreach docker, $($*_DOCKERS),\
|
||||
export docker_image="$(docker)"
|
||||
export docker_image_name="$(basename $(docker))"
|
||||
|
Loading…
Reference in New Issue
Block a user