Request power state change

    name
        Ensure power state one of:
            * power_on -- system turn on
            * power_off -- system turn off (without waiting for OS)
            * shutdown -- request OS proper shutdown
            * reset -- reset (without waiting for OS)
            * boot -- If system is off, then 'on', else 'reset'

    wait
        wait X seconds for the job to complete before forcing.
        (defaults to 300 seconds)

    kwargs
        - api_host=localhost
        - api_user=admin
        - api_pass=
        - api_port=623
        - api_kg=None

def power(name='power_on', wait=300, **kwargs):
    '''
    Request power state change

    name
        Ensure power state one of:
            * power_on -- system turn on
            * power_off -- system turn off (without waiting for OS)
            * shutdown -- request OS proper shutdown
            * reset -- reset (without waiting for OS)
            * boot -- If system is off, then 'on', else 'reset'

    wait
        wait X seconds for the job to complete before forcing.
        (defaults to 300 seconds)

    kwargs
        - api_host=localhost
        - api_user=admin
        - api_pass=
        - api_port=623
        - api_kg=None
    '''
    ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
    org = __salt__['ipmi.get_power'](**kwargs)

    state_map = {
        'off': 'off',
        'on': 'on',
        'power_off': 'off',
        'power_on': 'on',
        'shutdown': 'off',
        'reset': 'na',
        'boot': 'na'
    }

    if org == state_map[name]:
        ret['result'] = True
        ret['comment'] = 'system already in this state'
        return ret

    if __opts__['test']:
        ret['comment'] = 'would power: {0} system'.format(name)
        ret['result'] = None
        ret['changes'] = {'old': org, 'new': name}
        return ret

    outdddd = __salt__['ipmi.set_power'](name, wait=wait, **kwargs)
    ret['comment'] = 'changed system power'
    ret['result'] = True
    ret['changes'] = {'old': org, 'new': name}
    return ret