docs: def deleteMachine(rh):
      """
      Delete a virtual machine from the user directory.
  
      Input:
         Request Handle with the following properties:
            function    - 'DELETEVM'
            subfunction - 'DIRECTORY'
            userid      - userid of the virtual machine to be deleted.
  
      Output:
         Request Handle updated with the results.
         Return code - 0: ok, non-zero: error
      """
  
      rh.printSysLog("Enter deleteVM.deleteMachine")
  
      results = {'overallRC': 0, 'rc': 0, 'rs': 0}
  
      # Is image logged on ?
      state = 'on'    # Assume 'on'.
      results = isLoggedOn(rh, rh.userid)
      if results['overallRC'] != 0:
          # Cannot determine the log on/off state.
          # Message already included.  Act as if it is 'on'.
          pass
      elif results['rs'] == 0:
          # State is powered on.
          pass
      else:
          state = 'off'
          # Reset values for rest of subfunction
          results['overallRC'] = 0
          results['rc'] = 0
          results['rs'] = 0
  
      if state == 'on':
          parms = ["-T", rh.userid, "-f IMMED"]
          results = invokeSMCLI(rh, "Image_Deactivate", parms)
          if results['overallRC'] == 0:
              pass
          elif (results['overallRC'] == 8 and results['rc'] == 200 and
              (results['rs'] == 12 or results['rs'] == 16)):
              # Tolerable error.  Machine is already in or going into the state
              # that we want it to enter.
              rh.updateResults({}, reset=1)
          else:
              # SMAPI API failed.
              rh.printLn("ES", results['response'])
              rh.updateResults(results)  # Use results returned by invokeSMCLI
  
      # Clean up the reader before delete
      if results['overallRC'] == 0:
          result = purgeReader(rh)
          if result['overallRC'] != 0:
              # Tolerable the purge failure error
              rh.updateResults({}, reset=1)
  
      if results['overallRC'] == 0:
          parms = ["-T", rh.userid, "-e", "0"]
          results = invokeSMCLI(rh, "Image_Delete_DM", parms)
          if results['overallRC'] != 0:
              # SMAPI API failed.
              rh.printLn("ES", results['response'])
              rh.updateResults(results)  # Use results returned by invokeSMCLI
  
      rh.printSysLog("Exit deleteVM.deleteMachine, rc: " +
          str(rh.results['overallRC']))
      return rh.results['overallRC']