def container_apply_status(api, container, status):
    """Apply an LXD status to a container.

    Container is an:class:`lxdapi.api.APIResult`for the container, to be able
    to compare the status with.

    Status is a string, choices are: Running, Stopped, Frozen.

    Example usage::

        container_apply_status(api, container_get('yourcontainer'), 'Running')
    """
    if status == container.metadata['status']:
        return False
    if status == 'Running':
        action = 'start'
    elif status == 'Stopped':
        action = 'stop'
    elif status == 'Frozen':
        action = 'freeze'
    else:
        raise Exception('Invalid status %s, choices are: %s' % (status, [
            'Running', 'Stopped', 'Frozen']))
    api.put('containers/%s/state' % container.metadata['name'], json=dict(
        action=action, timeout=api.default_timeout)).wait()
    return True
