def reboot(rh):
    """
    Reboot a virtual machine.

    Input:
       Request Handle with the following properties:
          function    - 'POWERVM'
          subfunction - 'REBOOT'
          userid      - userid of the virtual machine
          parms['desiredState']   - Desired state. Optional, unless
                                    'maxQueries' is specified.
          parms['maxQueries']     - Maximum number of queries to issue.
                                    Optional.
          parms['maxWait']        - Maximum time to wait in seconds. Optional,
                                    unless 'maxQueries' is specified.
          parms['poll']           - Polling interval in seconds. Optional,
                                    unless 'maxQueries' is specified.

    Output:
       Request Handle updated with the results.
       Return code - 0: ok, non-zero: error
    """

    rh.printSysLog("Enter powerVM.reboot, userid: " + rh.userid)

    strCmd = "shutdown -r now"
    results = execCmdThruIUCV(rh, rh.userid, strCmd)
    if results['overallRC'] != 0:
        # Command failed to execute using IUCV.
        rh.printLn("ES", results['response'])
        rh.updateResults(results)

    if rh.results['overallRC'] == 0:
        # Wait for the OS to go down
        results = waitForOSState(rh, rh.userid, "down",
            maxQueries=30, sleepSecs=10)
        if results['overallRC'] == 0:
            rh.printLn("N", rh.userid + ": down (interim state)")

    if rh.results['overallRC'] == 0 and 'maxQueries' in rh.parms:
        results = waitForOSState(rh,
                                  rh.userid,
                                  'up',
                                  maxQueries=rh.parms['maxQueries'],
                                  sleepSecs=rh.parms['poll'])
        if results['overallRC'] == 0:
            rh.printLn("N", rh.userid + ": up")
        else:
            rh.updateResults(results)

    rh.printSysLog("Exit powerVM.reboot, rc: " +
        str(rh.results['overallRC']))
    return rh.results['overallRC']