Last active
February 19, 2016 22:13
-
-
Save nshalman/68844e98831d37fc7483 to your computer and use it in GitHub Desktop.
Reading Mac hardware data into salt grains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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