def make_computer_manifest(given_serial):
'''Checks for the presence and validity of an existing manifest for this client in the repository.
Creates a new manifest if an existing one is not found or is invalid.'''
# Filesystem path for this computer's manifest:
computer_manifest_name = given_serial.upper() # if not already
computer_manifest_path = os.path.join(munki_repo.COMPUTER_MANIFESTS_PATH,computer_manifest_name)
# Control variable: should a new manifest be created?
# Assume yes, unless an existing manifest is found and is valid.
should_create_new_client_manifest = True
# Catch missing computer manifests directory:
if not os.path.exists(munki_repo.COMPUTER_MANIFESTS_PATH):
common.logging_error("Computers manifests directory not found at %s." % munki_repo.COMPUTER_MANIFESTS_PATH)
raise
# Check existing manifest for this client:
if os.path.exists(computer_manifest_path):
common.logging_info("Manifest for %s already in repository. Checking it." % computer_manifest_name)
try:
computer_manifest_dict = plistlib.readPlist(computer_manifest_path)
# Manifest already exists; do not overwrite if it's a valid dict!
if computer_manifest_dict:
should_create_new_client_manifest = False
common.logging_info("Manifest for %s should be left alone." % computer_manifest_name)
except xml.parsers.expat.ExpatError:
common.logging_error("Manifest for %s is invalid. Will recreate." % computer_manifest_name)
# Build a new client manifest if required:
if should_create_new_client_manifest:
common.logging_info("Creating new manifest for %s." % computer_manifest_name)
computer_manifest_dict = {}
computer_manifest_dict['managed_installs'] = []
computer_manifest_dict['managed_uninstalls'] = []
computer_manifest_dict['catalogs'] = munki_repo.CATALOG_ARRAY
computer_manifest_dict['included_manifests'] = ['groups/%s' % munki_repo.DEFAULT_GROUP]
try:
plistlib.writePlist(computer_manifest_dict,computer_manifest_path)
except TypeError:
common.logging_error("Failed to write manifest for %s." % computer_manifest_name)
评论列表
文章目录