From 9abba47c947e4285d9c84c63b7b2ea9c3e681e19 Mon Sep 17 00:00:00 2001 From: Victor Lowther Date: Wed, 21 Feb 2018 09:24:08 -0600 Subject: [PATCH] Have Sledgehammer populate HardwareAddrs if it is not populated. --- content/bootenvs/discovery.yml | 5 +++-- content/bootenvs/sledgehammer.yml | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/content/bootenvs/discovery.yml b/content/bootenvs/discovery.yml index b9e8b104..e1bc445b 100644 --- a/content/bootenvs/discovery.yml +++ b/content/bootenvs/discovery.yml @@ -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 @@ -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. diff --git a/content/bootenvs/sledgehammer.yml b/content/bootenvs/sledgehammer.yml index b171029d..0035ce39 100644 --- a/content/bootenvs/sledgehammer.yml +++ b/content/bootenvs/sledgehammer.yml @@ -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" .}}