#NEWLINE# def filter_nodes( nodes , env = '' , roles = None , virt_roles = '' ) : #NEWLINE# #INDENT# 'Returns nodes which fulfill env, roles and virt_roles criteria' #NEWLINE# retval = [ ] #NEWLINE# if ( not roles ) : #NEWLINE# #INDENT# roles = [ ] #NEWLINE# #UNINDENT# if virt_roles : #NEWLINE# #INDENT# virt_roles = virt_roles . split ( ',' ) #NEWLINE# #UNINDENT# for node in nodes : #NEWLINE# #INDENT# append = True #NEWLINE# if ( env and ( node . get ( 'chef_environment' , 'none' ) != env ) ) : #NEWLINE# #INDENT# append = False #NEWLINE# #UNINDENT# if roles : #NEWLINE# #INDENT# if ( not set . intersection ( set ( roles ) , set ( [ role . split ( '_' ) [ 0 ] for role in node [ 'roles' ] ] ) ) ) : #NEWLINE# #INDENT# append = False #NEWLINE# #UNINDENT# #UNINDENT# if virt_roles : #NEWLINE# #INDENT# virt_role = node . get ( 'virtualization' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'role' ) #NEWLINE# if ( ( not ( virt_role in virt_roles ) ) and ( not ( ( 'guest' in virt_roles ) and ( not virt_role ) ) ) ) : #NEWLINE# #INDENT# append = False #NEWLINE# #UNINDENT# #UNINDENT# if append : #NEWLINE# #INDENT# retval . append ( node ) #NEWLINE# #UNINDENT# #UNINDENT# return retval