<s> import eventlet <EOL> from pyVmomi import vim <EOL> from vmwarelib import inventory <EOL> from vmwarelib import checkinputs <EOL> from vmwarelib . actions import BaseAction <EOL> class VMApplyPowerState ( BaseAction ) : <EOL> def run ( self , vm_id , vm_name , power_onoff ) : <EOL> checkinputs . one_of_two_strings ( vm_id , vm_name , "<STR_LIT>" ) <EOL> vm = inventory . get_virtualmachine ( self . si_content , <EOL> moid = vm_id , name = vm_name ) <EOL> if not vm : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if power_onoff == "<STR_LIT>" : <EOL> task = vm . PowerOffVM_Task ( ) <EOL> elif power_onoff == "<STR_LIT>" : <EOL> task = vm . PowerOnVM_Task ( ) <EOL> while task . info . state == vim . TaskInfo . State . running : <EOL> eventlet . sleep ( <NUM_LIT:1> ) <EOL> return { '<STR_LIT:state>' : str ( task . info . state ) } </s>
