def _reached_end_state(
    operation, volume, update, elapsed_time,
    timeout=VOLUME_STATE_CHANGE_TIMEOUT
):
    state_flow = VOLUME_STATE_TABLE.table[operation]
    start_state = state_flow.start_state.value
    transient_state = state_flow.transient_state.value
    end_state = state_flow.end_state.value
    sets_attach = state_flow.sets_attach
    unsets_attach = state_flow.unsets_attach

    if elapsed_time > timeout:
        # We either:
        # 1) Timed out waiting to reach ``end_status``, or,
        # 2) Reached an unexpected status (state change resulted in error), or,
        # 3) Reached ``end_status``, but ``end_status`` comes with
        #    attach data, and we timed out waiting for attach data.
        # Raise a ``TimeoutException`` in all cases.
        raise TimeoutException(unicode(volume.id), operation, start_state,
                               transient_state, end_state, volume.state)

    try:
        update(volume)
    except ClientError as e:
        # If AWS cannot find the volume, raise ``UnknownVolume``.
        if e.response['Error']['Code'] == NOT_FOUND:
            raise UnknownVolume(volume.id)

    WAITING_FOR_VOLUME_STATUS_CHANGE(
        volume_id=volume.id, status=volume.state, target_status=end_state,
        needs_attach_data=sets_attach, wait_time=elapsed_time
    ).write()

    if volume.state not in [start_state, transient_state, end_state]:
        raise UnexpectedStateException(unicode(volume.id), operation,
                                       start_state, transient_state, end_state,
                                       volume.state)
    if volume.state != end_state:
        return False

    # If end state for the volume comes with attach data,
    # declare success only upon discovering attach data.
    if volume.attachments:
        volume_attach_data = volume.attachments[0]
    else:
        volume_attach_data = None
    if sets_attach:
        return (volume_attach_data is not None and
                (volume_attach_data['Device'] != '' and
                 volume_attach_data['InstanceId'] != ''))
    elif unsets_attach:
        return (volume_attach_data is None or
                (volume_attach_data['Device'] == '' and
                 volume_attach_data['InstanceId'] == ''))
    else:
        return True
Create a policy.
dataset/ETHPy150Open ClusterHQ/flocker/flocker/node/agents/ebs.py/_reached_end_state--crossover with--dataset/ETHPy150Open openstack/python-senlinclient/senlinclient/v1/shell.py/do_policy_create