code: def _update_pretty_hostname(new_val: str):
      
      try:
          with open('/etc/machine-info') as emi:
              contents = emi.read()
      except OSError:
          LOG.exception("Couldn't read /etc/machine-info")
          contents = ''
      new_contents = ''
      for line in contents.split('\n'):
          if not line.startswith('PRETTY_HOSTNAME'):
              new_contents += f'{line}\n'
      new_contents += f'PRETTY_HOSTNAME={new_val}\n'
      with open('/etc/machine-info', 'w') as emi:
          emi.write(new_contents)
docs: Write a new value for the pretty hostname.
  
      :raises OSError: If the new value could not be written.