mirror of
https://github.com/munki/munki.git
synced 2026-04-26 06:48:57 -05:00
Collect board-id or device-id if available and add to Condtions dict for use in conditional_items, etc
This commit is contained in:
@@ -55,6 +55,17 @@ from . import utils
|
||||
from . import FoundationPlist
|
||||
from .wrappers import unicode_or_str
|
||||
|
||||
# IOKit functions
|
||||
IOKit_bundle = NSBundle.bundleWithIdentifier_("com.apple.framework.IOKit")
|
||||
|
||||
functions = [
|
||||
("IOServiceGetMatchingService", b"II@"),
|
||||
("IOServiceMatching", b"@*"),
|
||||
("IOServiceNameMatching", b"@*"),
|
||||
("IORegistryEntryCreateCFProperty", b"@I@@I"),
|
||||
]
|
||||
objc.loadBundleFunctions(IOKit_bundle, globals(), functions)
|
||||
|
||||
try:
|
||||
_ = xrange # pylint: disable=xrange-builtin
|
||||
except NameError:
|
||||
@@ -626,14 +637,6 @@ def get_serial_number():
|
||||
# Borrowed with love from
|
||||
# https://github.com/chilcote/unearth/blob/master/artifacts/serial_number.py
|
||||
# thanks, Joe!
|
||||
IOKit_bundle = NSBundle.bundleWithIdentifier_("com.apple.framework.IOKit")
|
||||
|
||||
functions = [
|
||||
("IOServiceGetMatchingService", b"II@"),
|
||||
("IOServiceMatching", b"@*"),
|
||||
("IORegistryEntryCreateCFProperty", b"@I@@I"),
|
||||
]
|
||||
objc.loadBundleFunctions(IOKit_bundle, globals(), functions)
|
||||
|
||||
kIOMasterPortDefault = 0
|
||||
kIOPlatformSerialNumberKey = "IOPlatformSerialNumber"
|
||||
@@ -648,17 +651,9 @@ def get_serial_number():
|
||||
|
||||
return serial
|
||||
|
||||
|
||||
def product_name():
|
||||
"""Returns the product name from IORegistry"""
|
||||
IOKit_bundle = NSBundle.bundleWithIdentifier_("com.apple.framework.IOKit")
|
||||
|
||||
functions = [
|
||||
("IOServiceGetMatchingService", b"II@"),
|
||||
("IOServiceNameMatching", b"@*"),
|
||||
("IORegistryEntryCreateCFProperty", b"@I@@I"),
|
||||
]
|
||||
objc.loadBundleFunctions(IOKit_bundle, globals(), functions)
|
||||
|
||||
kIOMasterPortDefault = 0
|
||||
kCFAllocatorDefault = None
|
||||
|
||||
@@ -674,6 +669,39 @@ def product_name():
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def board_id():
|
||||
"""Returns board-id from IORegistry"""
|
||||
kIOMasterPortDefault = 0
|
||||
kCFAllocatorDefault = None
|
||||
|
||||
platformExpert = IOServiceGetMatchingService(
|
||||
kIOMasterPortDefault, IOServiceMatching(b"IOPlatformExpertDevice")
|
||||
)
|
||||
raw_data = IORegistryEntryCreateCFProperty(
|
||||
platformExpert, "board-id", kCFAllocatorDefault, 0
|
||||
)
|
||||
if raw_data:
|
||||
return raw_data.bytes().tobytes().decode("utf-8").rstrip("\x00")
|
||||
return "<none>"
|
||||
|
||||
|
||||
def device_id():
|
||||
"""Returns device id from IORegistry"""
|
||||
kIOMasterPortDefault = 0
|
||||
kCFAllocatorDefault = None
|
||||
|
||||
platformExpert = IOServiceGetMatchingService(
|
||||
kIOMasterPortDefault, IOServiceMatching(b"IOPlatformExpertDevice")
|
||||
)
|
||||
raw_data = IORegistryEntryCreateCFProperty(
|
||||
platformExpert, "target-sub-type", kCFAllocatorDefault, 0
|
||||
)
|
||||
if raw_data:
|
||||
return raw_data.bytes().tobytes().decode("utf-8").rstrip("\x00")
|
||||
return "<none>"
|
||||
|
||||
|
||||
def hardware_model():
|
||||
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c"))
|
||||
|
||||
@@ -702,6 +730,7 @@ def has_intel64support():
|
||||
|
||||
return buf.value == 1
|
||||
|
||||
|
||||
def available_disk_space(volumepath='/'):
|
||||
"""Returns available diskspace in KBytes.
|
||||
|
||||
@@ -764,6 +793,8 @@ def getMachineFacts():
|
||||
machine['x86_64_capable'] = True
|
||||
elif machine['arch'] == 'i386':
|
||||
machine['x86_64_capable'] = has_intel64support()
|
||||
machine['board-id'] = board_id()
|
||||
machine['device-id'] = device_id()
|
||||
return machine
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user