<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def activate(rh):
 """ Activate a virtual machine. Input: Request Handle with the following properties: function - 'POWERVM' subfunction - 'ON' 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.activate, userid: " + rh.userid)

    parms = ["-T", rh.userid]
    smcliResults = invokeSMCLI(rh, "Image_Activate", parms)
    if smcliResults['overallRC'] == 0:
        pass
    elif (smcliResults['overallRC'] == 8 and
        smcliResults['rc'] == 200 and smcliResults['rs'] == 8):
        pass    # All good.  No need to change the ReqHandle results.
    else:
        # SMAPI API failed.
        rh.printLn("ES", smcliResults['response'])
        rh.updateResults(smcliResults)    # Use results from invokeSMCLI

    if rh.results['overallRC'] == 0 and 'maxQueries' in rh.parms:
        # Wait for the system to be in the desired state of:
        # OS is 'up' and reachable or VM is 'on'.
        if rh.parms['desiredState'] == 'up':
            results = waitForOSState(
                rh,
                rh.userid,
                rh.parms['desiredState'],
                maxQueries=rh.parms['maxQueries'],
                sleepSecs=rh.parms['poll'])
        else:
            results = waitForVMState(
                rh,
                rh.userid,
                rh.parms['desiredState'],
                maxQueries=rh.parms['maxQueries'],
                sleepSecs=rh.parms['poll'])

        if results['overallRC'] == 0:
            rh.printLn("N", "%s: %s" %
                (rh.userid, rh.parms['desiredState']))
        else:
            rh.updateResults(results)

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