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

Commit

Permalink
Merge pull request #59 from digitalrebar/have-sledgehammer-add-machin…
Browse files Browse the repository at this point in the history
…e-HardwareAddrs-if-missing

Have Sledgehammer populate HardwareAddrs if it is not populated.
  • Loading branch information
galthaus authored Feb 21, 2018
2 parents f4fa923 + 9abba47 commit 143b58e
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 143b58e

Please sign in to comment.