Further fleshing out of hwdiscovery element

This adds support for other elements to feed into the hwdiscovery
results.

It also fixes a few bugs in the construction of the ramdisk.

It also adds support for specifying a server to POST the discovered
hardware data to, via the kernel command line

Change-Id: I163db2b1388f908880e8f458e16906fa6f9db7bc
This commit is contained in:
Chris Jones 2012-12-06 14:34:29 +00:00
parent 9243a8e3f9
commit ae1e74acd8
3 changed files with 48 additions and 1 deletions

View file

@ -1 +1,35 @@
A ramdisk to report the hardware of a machine to an inventory service.
This will collect up some basic information about the hardware it
boots on:
* CPU cores
* RAM
* Disk
* NIC mac address
This information will then be collated into a JSON document, base64
encoded and passed, via HTTP POST, to a URL that you must specify on
the kernel commandline, thus:
HW_DISCOVERY_URL=http://1.2.3.4:56/hw_script.asp
This is currently fairly fragile as there can be a huge variability in
the number of disks/NICs in servers and how they are configured.
If other elements wish to inject data into the hardware discovery data,
they can - they should be specified before hwdiscovery to the image
building script, and they should contain something like this in their
init fragment:
_vendor_hwdiscovery_data="$_vendor_hwdiscovery_data
\"some vendor key\" : \"some data you care about\",
\"some other vendor key\" : \"some other data you care about\","
Note that you are essentially feeding JSON into the main hwdiscovery
JSON.
This will allow any number of vendor specific hwdiscovery elements to
chain together their JSON fragments and maintain consistency.

View file

@ -1,3 +1,5 @@
lshw
hwinfo
dhclient
wget
base64

View file

@ -19,6 +19,7 @@ function pxe_mac() {
_dev=$(echo "${_info1}" | grep "Device File:"|awk -F':' {'print $2'}|tr -d ' ')
_mac=$(echo "${_info2}" | grep "HW Address:"|awk -F'ss:' {'print $2'}|tr -d ' ')
echo $_mac
export HW_DISCOVERY_BOOT_IFACE="$_mac"
}
function disk() {
@ -35,7 +36,7 @@ function raw_network() {
hwinfo --network
}
cat <<EOF
HW_DISCOVERY_OUTPUT=$(cat <<EOF
{
"cpu cores" : "$(cpu_cores)",
"disk size" : "$(disk)",
@ -44,9 +45,19 @@ cat <<EOF
"extra data" : {
"raw disk" : "$(raw_disk | base64)",
"raw network" : "$(raw_network | base64)",
$_vendor_hwdiscovery_data
}
}
EOF
)
# Print the resulting JSON for debugging purposes
echo $HW_DISCOVERY_OUTPUT
# Now submit the JSON
HW_DISCOVERY_DATA=$(echo ${HW_DISCOVERY_OUTPUT} | base64)
HW_DISCOVERY_URL=$(get_kernel_parameter HW_DISCOVERY_URL)
wget --post-data "hwdiscovery=true&hwdiscovery_data=${HW_DISCOVERY_DATA}" ${HW_DISCOVERY_URL}
sleep 30