Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Have Sledgehammer populate HardwareAddrs if it is not populated.
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorLowther committed Feb 21, 2018
1 parent f4fa923 commit 9abba47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions content/bootenvs/discovery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Templates:
[[ -f $nic/type && -f $nic/address && $(cat "$nic/type") == 1 ]] || continue
maclist="$maclist,\"$(cat "$nic/address")\""
done
printf '[%s]', "${maclist#,}"
printf '[%s]' "${maclist#,}"
}
# Stuff from sledgehammer file that makes this command debuggable
Expand Down Expand Up @@ -111,9 +111,10 @@ Templates:
# See if we have already been created.
if [[ $(cat /proc/cmdline) =~ $host_re ]]; then
RS_UUID="${BASH_REMATCH[1]}"
json="$(drpcli machines show "$RS_UUID")"
# If we did not get a hostname from DHCP, get it from DigitalRebar Provision.
if [[ ! $HOSTNAME ]]; then
HOSTNAME="$(drpcli machines show "$RS_UUID" |jq -r '.Name')"
HOSTNAME="$(jq -r '.Name' <<< "$json")"
fi
else
# If we did not get a hostname from DHCP, generate one for ourselves.
Expand Down
18 changes: 18 additions & 0 deletions content/bootenvs/sledgehammer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ Templates:
# used below. Reset the token to the longer machine token.
export RS_TOKEN="{{.GenerateToken}}"
# If we do not have hardware addresses set on the machine, set them now.
get_macs() {
local maclist=""
local nic=""
for nic in /sys/class/net/*; do
[[ -f $nic/type && -f $nic/address && $(cat "$nic/type") == 1 ]] || continue
maclist="$maclist,\"$(cat "$nic/address")\""
done
printf '[%s]' "${maclist#,}"
}
json="$(drpcli machines show "$RS_UUID")"
# The machine does not have hardware addresses set, so set them
if [[ "$(jq '.HardwareAddrs | length' <<< "$json")" = 0 ]]; then
drpcli machines update "$RS_UUID" "{\"HardwareAddrs\": $(get_macs)}"
fi
unset get_macs json
{{template "reset-workflow.tmpl" .}}
{{template "runner.tmpl" .}}
Expand Down

0 comments on commit 9abba47

Please sign in to comment.