Skip to content

Instantly share code, notes, and snippets.

@nshalman
Last active February 19, 2016 22:13
Show Gist options
  • Save nshalman/68844e98831d37fc7483 to your computer and use it in GitHub Desktop.
Save nshalman/68844e98831d37fc7483 to your computer and use it in GitHub Desktop.
Reading Mac hardware data into salt grains
import plistlib
import subprocess
import platform
def mac_hardware_data():
'''
Get some Mac specific grains
'''
profiler_cmd = 'system_profiler SPHardwareDataType -xml'
if "Darwin" not in platform.platform():
return {}
raw_plist = subprocess.check_output(profiler_cmd, shell=True)
hardware_data = plistlib.readPlistFromString(raw_plist)[0]["_items"][0]
grains = {}
for key in hardware_data:
grains["mac_" + key] = hardware_data[key]
return grains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment