Skip to content

Commit

Permalink
Add usg::config-refresh to automate one of the USG - UniFi steps.
Browse files Browse the repository at this point in the history
It seems like there are quite a few transient diffs that crop up
immediately after a force provision. Vyatta gives us a way to automate
updating the config.

https://docs.vyos.io/en/latest/automation/command-scripting.html
  • Loading branch information
JeffFaer committed Nov 27, 2021
1 parent 5a5ce9f commit c7ac92c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
20 changes: 14 additions & 6 deletions usg
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
# 3. $ usg diff config.json
# 4. $ usg patch config.json default
# 5. Force provisioning in the Unifi UI
# 6. In USG:
# - configure
# - set system host-name foo
# - set system host-name <original-value>
# - commit; save; exit
# 6. $ usg config-refresh
# 7. $ usg diff config.json
# 8. The previous usg diff fields show show up again, in addition to
# unifi.mgmt.cfgversion.
#

# ssh arguments to connect to the USG and the UniFi Controller. The arguments
# should be escaped, if necessary.
Expand Down Expand Up @@ -220,6 +215,19 @@ usg::patch(){
fi
}

# usg::config-refresh refreshes the USG's config.gateway.json after a force
# provision to get rid of any transient differences that might exist (e.g.
# "123" -> 123).
usg::config-refresh() {
[[ $# == 0 ]] || die "config-refresh doesn't take any arguments."

local dir="$(dirname "${BASH_SOURCE}")"
ssh -o loglevel=ERROR ${USG_CONNECTION} -- \
"vbash -s" < "${dir}/usg_scripts/config_refresh.sh"
}

# usg::rollback rollsback the UniFi controller's config.gateway.json to its most
# recent config.gateway.json.old file.
usg::rollback() {
[[ $# == 1 ]] || die "rollback takes exactly one argument: site name"
local site="$1"
Expand Down
9 changes: 9 additions & 0 deletions usg_scripts/config_refresh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/vbash
# https://docs.vyos.io/en/latest/automation/command-scripting.html

source /opt/vyatta/etc/functions/script-template

configure
commit
save
exit

0 comments on commit c7ac92c

Please sign in to comment.