<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import salt . utils . validate . net <EOL> import salt . ext . six as six <EOL> def present ( name , ip ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if not isinstance ( ip , list ) : <EOL> ip = [ ip ] <EOL> comments = [ ] <EOL> for _ip in ip : <EOL> if __salt__ [ '<STR_LIT>' ] ( _ip , name ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> else : <EOL> if salt . utils . validate . net . ipv4_addr ( _ip ) or salt . utils . validate . net . ipv6_addr ( _ip ) : <EOL> if __salt__ [ '<STR_LIT>' ] ( _ip , name ) : <EOL> ret [ '<STR_LIT>' ] = { '<STR_LIT:host>' : name } <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> comments . append ( '<STR_LIT>' ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( comments ) <EOL> return ret <EOL> def absent ( name , ip ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if not isinstance ( ip , list ) : <EOL> ip = [ ip ] <EOL> comments = [ ] <EOL> for _ip in ip : <EOL> if not __salt__ [ '<STR_LIT>' ] ( _ip , name ) : <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> else : <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> else : <EOL> if __salt__ [ '<STR_LIT>' ] ( _ip , name ) : <EOL> ret [ '<STR_LIT>' ] = { '<STR_LIT:host>' : name } <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> comments . append ( '<STR_LIT>' . format ( name , _ip ) ) <EOL> else : <EOL> ret [ '<STR_LIT:result>' ] = False <EOL> comments . append ( '<STR_LIT>' ) <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( comments ) <EOL> return ret <EOL> def only ( name , hostnames ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT:result>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> if isinstance ( hostnames , six . string_types ) : <EOL> hostnames = [ hostnames ] <EOL> old = '<STR_LIT:U+0020>' . join ( __salt__ [ '<STR_LIT>' ] ( name ) ) <EOL> new = '<STR_LIT:U+0020>' . join ( ( x . strip ( ) for x in hostnames ) ) <EOL> if old == new : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> name , new ) <EOL> ret [ '<STR_LIT:result>' ] = True <EOL> return ret <EOL> if __opts__ [ '<STR_LIT:test>' ] : <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> name , old , new ) <EOL> return ret <EOL> ret [ '<STR_LIT:result>' ] = __salt__ [ '<STR_LIT>' ] ( name , new ) <EOL> if not ret [ '<STR_LIT:result>' ] : <EOL> ret [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> + '<STR_LIT>' ) . format ( name , old , new ) <EOL> return ret <EOL> ret [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> name , old , new ) <EOL> ret [ '<STR_LIT>' ] = { name : { '<STR_LIT>' : old , '<STR_LIT>' : new } } <EOL> return ret </s>
