def filter_nodes(nodes, env='', roles=None, virt_roles=''):
    retval = []
    if not roles:
        roles = []
    if virt_roles:
        virt_roles = virt_roles.split(',')
    for node in nodes:
        append = True
        if env and node.get('chef_environment', 'none') != env:
            append = False
        if roles:
            if not set.intersection(
                    set(roles),
                    set([role.split("_")[0] for role in node['roles']])):
                append = False
        if virt_roles:
            # Exclude node in two cases:
            #   * the virtualization role is not in the desired virt_roles
            #   * the virtualization role is not defined for the node AND
            #     'guest' is a desired virt_role
            virt_role = node.get('virtualization', {}).get('role')
            if not virt_role in virt_roles and \
                    not ('guest' in virt_roles and not virt_role):
                append = False
        if append:
            retval.append(node)
    return retval
Returns nodes which fulfill env, roles and virt_roles criteria
dataset/ETHPy150Open edelight/kitchen/kitchen/backends/lchef.py/filter_nodes