|
4 | 4 | set -e |
5 | 5 |
|
6 | 6 | # When run inside a container, re-exec in the host namespaces so the |
7 | | -# reset calls below act on the host. |
| 7 | +# config/systemctl/reboot calls below act on the host. |
8 | 8 | if [ -z "$FABRIC_ON_HOST" ]; then |
9 | 9 | export FABRIC_ON_HOST=1 |
10 | 10 | exec nsenter --target 1 --mount --net --pid bash "$0" |
11 | 11 | fi |
12 | 12 |
|
13 | 13 | # Reset script for node {{ .Node }}, rendered by the fabric cell runtime. |
14 | | -# TODO: reset the configuration of the device to a clean state. |
15 | | -echo "Resetting the device is not implemented yet" |
16 | | -exit 0 |
| 14 | +# Undoes what the cell script applied: server VLANs, loopback IPs, port |
| 15 | +# state and the FRR/BGP config. Everything is read from the running |
| 16 | +# CONFIG_DB, so this also works on a partially provisioned device (failed |
| 17 | +# cells). Deliberately kept: hostname, management config, link-local and |
| 18 | +# the physical port parameters (mtu/fec/speed). |
| 19 | + |
| 20 | +CONFIG_DB=/etc/sonic/config_db.json |
| 21 | + |
| 22 | +# Remove the loopback addresses handed down by the cell |
| 23 | +for ENTRY in $(jq -r '.LOOPBACK_INTERFACE // {} | keys[] | select(contains("|"))' "$CONFIG_DB"); do |
| 24 | + config interface ip remove "${ENTRY%%|*}" "${ENTRY#*|}" |
| 25 | +done |
| 26 | + |
| 27 | +# Remove the VLANs the cell's server peers created, in dependency order: |
| 28 | +# DHCP relay, interface IPs, members, then the VLAN itself |
| 29 | +for VLAN in $(jq -r '.VLAN // {} | keys[]' "$CONFIG_DB"); do |
| 30 | + VLAN_ID="${VLAN#Vlan}" |
| 31 | + for SERVER in $(jq -r --arg v "$VLAN" '.DHCP_RELAY[$v] // {} | .dhcpv6_servers // .dhcp_servers // [] | .[]' "$CONFIG_DB"); do |
| 32 | + config vlan dhcp_relay del "$VLAN_ID" "$SERVER" |
| 33 | + done |
| 34 | + for ENTRY in $(jq -r --arg v "$VLAN" '.VLAN_INTERFACE // {} | keys[] | select(startswith($v + "|"))' "$CONFIG_DB"); do |
| 35 | + config interface ip remove "$VLAN" "${ENTRY#*|}" |
| 36 | + done |
| 37 | + for MEMBER in $(jq -r --arg v "$VLAN" '.VLAN_MEMBER // {} | keys[] | select(startswith($v + "|"))' "$CONFIG_DB"); do |
| 38 | + config vlan member del "$VLAN_ID" "${MEMBER#*|}" |
| 39 | + done |
| 40 | + config vlan del "$VLAN_ID" |
| 41 | +done |
| 42 | + |
| 43 | +# Shut down every front panel port the cell script started up |
| 44 | +for PORT in $(jq -r '.PORT // {} | to_entries[] | select(.value.admin_status == "up") | .key' "$CONFIG_DB"); do |
| 45 | + config interface shutdown "$PORT" |
| 46 | +done |
| 47 | + |
| 48 | +config save -y |
| 49 | + |
| 50 | +# Return FRR to an empty config: no BGP peering |
| 51 | +cat <<EOF >/etc/sonic/frr/frr.conf |
| 52 | +frr version 8.1 |
| 53 | +frr defaults traditional |
| 54 | +hostname $(hostname) |
| 55 | +log syslog informational |
| 56 | +service integrated-vtysh-config |
| 57 | +EOF |
| 58 | + |
| 59 | +systemctl restart bgp |
| 60 | + |
| 61 | +# Mark the device as unprovisioned, let the fabriclet expire the cell |
| 62 | +rm -f /etc/sonic/fabric-cell.done |
| 63 | + |
| 64 | +reboot |
0 commit comments