def extract_molist_from_method_response(method_response,
                                        in_hierarchical=False):
    """
    Methods extracts mo list from response received from imc server i.e.
    external method object

    Args:
        method_response (ExternalMethod Object): response
        in_hierarchical (bool): if True, return all the hierarchical child of
                                    managed objects

    Returns:
        List of ManagedObjects

    Example:
        response = handle.query_dn("sys/rack-unit-1", need_response=True)\n
        molist = extract_molist_from_method_response(method_response=response,
                in_hierarchical=True)
    """

    mo_list = []
    if hasattr(method_response, "out_config"):
        if len(method_response.out_config.child) == 0:
            return mo_list
    else:
        if len(method_response.out_configs.child) == 0:
            return mo_list
    if in_hierarchical:
        if hasattr(method_response, "out_config"):
            current_mo_list = method_response.out_config.child
        else:
            current_mo_list = method_response.out_configs.child
        while len(current_mo_list) > 0:
            child_mo_list = []
            for mo in current_mo_list:
                mo_list.append(mo)
                while mo.child_count() > 0:
                    for child in mo.child:
                        mo.child_remove(child)
                        child.mark_clean()
                        child_mo_list.append(child)
                        break
            current_mo_list = child_mo_list
    else:
        mo_list = method_response.out_configs.child

    return mo_list