         '--', args...
       ]
       @vbm 'guestcontrol', args, (err, stdout, stderr) =>
-        @debug "exec: #{cmd} (error: #{err?})"
         return deferred.reject err if err?
         deferred.resolve true
       deferred.promise


  # Uninstall the VM.
  uninstall: -> @ensureNotMissing().then => @ensureNotRunning().then =>
    @debug "uninstall"
    deferred = Q.defer()
    @vbm 'unregistervm', ['--delete'], (err, stdout, stderr) =>
      return deferred.reject err if err?

  _waitForStatus: (statuses, deferred, delay=1000) ->
    statuses = [].concat statuses
    statusNames = (@constructor.statusName s for s in statuses).join ', '
    @debug "_waitForStatus: #{statusNames}"
    return null if deferred.promise.isRejected()
    @status().then (status) =>
      return deferred.resolve status if status in statuses
      Q.delay(delay).then => @_waitForStatus statuses, deferred, delay

  waitForRunning: (timeout=60000, delay) ->
    @debug 'waitForRunning'
    deferred = Q.defer()
    @_waitForStatus(@constructor.status.RUNNING, deferred, delay).fail (err) ->
      deferred.reject err
    deferred.promise.timeout timeout

  waitForNotRunning: (timeout=60000, delay) ->
    @debug 'waitForNotRunning'
    deferred = Q.defer()
    @_waitForStatus([
      @constructor.status.POWEROFF
