def GetClientIdentifier(runtype=None):
  """Assembles the client identifier based on information collected by facter.

  Args:
    runtype: str, optional, Munki runtype. i.e. auto, custom, manual, etc.
  Returns:
    dict client identifier.
  """
  facts = GetFacterFacts()

  uuid = (facts.get('certname', None) or
          facts.get('uuid', None) or _GetMachineInfoPlistValue('MachineUUID') or
          _GetHardwareUUID())
  uuid = uuid.lower()  # normalize uuid to lowercase.

  owner = (facts.get('primary_user', None) or
           _GetMachineInfoPlistValue('Owner') or _GetPrimaryUser() or
           _GetConsoleUser())

  hostname = (facts.get('sp_local_host_name', None) or
              facts.get('hostname', None) or _GetHostname())

  config_track = facts.get('configtrack', 'BROKEN')

  simian_track = (facts.get('simiantrack', None))

  # Apple SUS integration.
  applesus = facts.get('applesus', 'true').lower() == 'true'

  site = facts.get('site', None)
  office = facts.get('location', None)

  os_version = platform.mac_ver()[0]  # tuple like: ('10.6.3', (...), 'i386')

  serial = facts.get('hardware_serialnumber', None) or _GetSerialNumber()

  # client_management_enabled facter support; defaults to enabled.
  mgmt_enabled = facts.get(
      'client_management_enabled', 'true').lower() == 'true'

  # Determine if the computer is on the corp network or not.
  on_corp = None
  on_corp_cmd = ''
  on_corp_cmd_config = '/etc/simian/on_corp_cmd'
  if not on_corp_cmd and os.path.isfile(on_corp_cmd_config):
    try:
      f = open(on_corp_cmd_config, 'r')
      on_corp_cmd = f.read()
      on_corp_cmd = on_corp_cmd.strip()
      f.close()
    except __HOLE__ as e:
      logging.exception(
          'Error reading %s: %s', on_corp_cmd_config, str(e))
  if on_corp_cmd:
    try:
      on_corp, unused_stdout, unused_stderr = Exec(
          on_corp_cmd, timeout=60, waitfor=0.5)
      # exit=0 means on corp, so reverse.
      on_corp = '%d' % (not on_corp)
    except OSError as e:
      # in this case, we don't know if on corp or not so don't log either.
      logging.exception('OSError calling on_corp_cmd: %s', str(e))
      on_corp = None

  # LastNotifiedDate comes as local time from FoundationPlist,
  # so convert to epoc timestamp then to UTC datetime.
  last_notified_datetime_str = GetPlistDateValue(
      'LastNotifiedDate', str_format=DATETIME_STR_FORMAT)

  # get uptime
  try:
    uptime = GetSystemUptime()
  except Error as e:
    uptime = 'ERROR: %s' % str(e)

  # get free space
  try:
    root_disk_free = GetDiskFree()
  except Error as e:
    root_disk_free = 'ERROR: %s' % str(e)

  # get user disk free
  user_disk_free = None
  if owner:
    try:
      # TODO(user): this may not be FileVault compatible, at least before
      # the user is logged in; investigate.
      user_dir_path = '/Users/%s/' % owner
      if os.path.isdir(user_dir_path):
        user_disk_free = GetDiskFree(user_dir_path)
    except Error as e:
      user_disk_free = 'ERROR: %s' % str(e)

  client_id = {
      'uuid': uuid,
      'owner': owner,
      'hostname': hostname,
      'serial': serial,
      'config_track': config_track,
      'track': simian_track,
      'applesus': applesus,
      'mgmt_enabled': mgmt_enabled,
      'site': site,
      'office': office,
      'os_version': os_version,
      'client_version': GetClientVersion(),
      'on_corp': on_corp,
      'last_notified_datetime': last_notified_datetime_str,
      'runtype': runtype,
      'uptime': uptime,
      'root_disk_free': root_disk_free,
      'user_disk_free': user_disk_free,
  }
  return client_id
dataset/ETHPy150Open google/simian/src/simian/mac/client/flight_common.py/GetClientIdentifier