@ -8,11 +8,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
__metaclass__ = type
ANSIBLE_METADATA = {
ANSIBLE_METADATA = { ' metadata_version ' : ' 1.1 ' ,
' status ' : [ ' preview ' ] ,
' status ' : [ ' preview ' ] ,
' supported_by ' : ' community ' ,
' supported_by ' : ' community ' }
' metadata_version ' : ' 1.1 '
}
DOCUMENTATION = r '''
DOCUMENTATION = r '''
module : bigip_remote_syslog
module : bigip_remote_syslog
@ -103,10 +101,6 @@ except ImportError:
class Parameters ( AnsibleF5Parameters ) :
class Parameters ( AnsibleF5Parameters ) :
api_map = {
' remotePort ' : ' remote_port '
}
updatables = [
updatables = [
' remote_port ' , ' local_ip ' , ' remoteServers '
' remote_port ' , ' local_ip ' , ' remoteServers '
]
]
@ -199,10 +193,22 @@ class Parameters(AnsibleF5Parameters):
)
)
class Changes ( Parameters ) :
@property
def remote_port ( self ) :
return self . _values [ ' remote_port ' ]
@property
def local_ip ( self ) :
return self . _values [ ' local_ip ' ]
class Difference ( object ) :
class Difference ( object ) :
def __init__ ( self , want , have = None ) :
def __init__ ( self , want , have = None ) :
self . want = want
self . want = want
self . have = have
self . have = have
self . _local_ip = None
self . _remote_port = None
def compare ( self , param ) :
def compare ( self , param ) :
try :
try :
@ -231,9 +237,13 @@ class Difference(object):
"""
"""
changed = False
changed = False
if self . have. remoteServers is None :
if self . want. remote_host is None :
return None
return None
current_hosts = dict ( ( d [ ' host ' ] , d ) for ( i , d ) in enumerate ( self . have . remoteServers ) )
if self . have . remoteServers is None :
remote = dict ( )
else :
remote = self . have . remoteServers
current_hosts = dict ( ( d [ ' host ' ] , d ) for ( i , d ) in enumerate ( remote ) )
if self . want . state == ' absent ' :
if self . want . state == ' absent ' :
del current_hosts [ self . want . remote_host ]
del current_hosts [ self . want . remote_host ]
@ -243,12 +253,14 @@ class Difference(object):
if self . want . remote_host in current_hosts :
if self . want . remote_host in current_hosts :
item = current_hosts [ self . want . remote_host ]
item = current_hosts [ self . want . remote_host ]
if self . want . remote_port is not None :
if self . want . remote_port is not None :
if item [ ' remotePort ' ] != self . want . remote_port :
if int ( item [ ' remotePort ' ] ) != self . want . remote_port :
item [ ' remotePort ' ] = self . want . remote_port
item [ ' remotePort ' ] = self . want . remote_port
self . _remote_port = self . want . remote_port
changed = True
changed = True
if self . want . local_ip is not None :
if self . want . local_ip is not None :
if item [ ' localIp ' ] != self . want . local_ip :
if item [ ' localIp ' ] != self . want . local_ip :
item [ ' localIp ' ] = self . want . local_ip
item [ ' localIp ' ] = self . want . local_ip
self . _local_ip = self . want . local_ip
changed = True
changed = True
else :
else :
changed = True
changed = True
@ -260,11 +272,26 @@ class Difference(object):
)
)
if self . want . remote_port is not None :
if self . want . remote_port is not None :
current_hosts [ host ] [ ' remotePort ' ] = self . want . remote_port
current_hosts [ host ] [ ' remotePort ' ] = self . want . remote_port
self . _remote_port = self . want . remote_port
if self . want . local_ip is not None :
if self . want . local_ip is not None :
current_hosts [ host ] [ ' localIp ' ] = self . want . local_ip
current_hosts [ host ] [ ' localIp ' ] = self . want . local_ip
self . _local_ip = self . want . local_ip
if changed :
if changed :
result = [ v for ( k , v ) in iteritems ( current_hosts ) ]
result = [ v for ( k , v ) in iteritems ( current_hosts ) ]
return result
return result
return None
@property
def remote_port ( self ) :
_ = self . remoteServers
if self . _remote_port :
return self . _remote_port
@property
def local_ip ( self ) :
_ = self . remoteServers
if self . _local_ip :
return self . _local_ip
class ModuleManager ( object ) :
class ModuleManager ( object ) :
@ -272,7 +299,7 @@ class ModuleManager(object):
self . client = client
self . client = client
self . have = None
self . have = None
self . want = Parameters ( self . client . module . params )
self . want = Parameters ( self . client . module . params )
self . changes = Parameter s( )
self . changes = Change s( )
def _set_changed_options ( self ) :
def _set_changed_options ( self ) :
changed = { }
changed = { }
@ -280,7 +307,7 @@ class ModuleManager(object):
if getattr ( self . want , key ) is not None :
if getattr ( self . want , key ) is not None :
changed [ key ] = getattr ( self . want , key )
changed [ key ] = getattr ( self . want , key )
if changed :
if changed :
self . changes = Parameter s( changed )
self . changes = Change s( changed )
self . changes . update ( { ' remote_host ' : self . want . remote_host } )
self . changes . update ( { ' remote_host ' : self . want . remote_host } )
def _update_changed_options ( self ) :
def _update_changed_options ( self ) :
@ -292,9 +319,12 @@ class ModuleManager(object):
if change is None :
if change is None :
continue
continue
else :
else :
changed [ k ] = change
if isinstance ( change , dict ) :
changed . update ( change )
else :
changed [ k ] = change
if changed :
if changed :
self . changes = Parameters ( changed )
self . changes = Change s( changed )
self . changes . update ( { ' remote_host ' : self . want . remote_host } )
self . changes . update ( { ' remote_host ' : self . want . remote_host } )
return True
return True
return False
return False
@ -420,26 +450,38 @@ class ArgumentSpec(object):
self . f5_product_name = ' bigip '
self . f5_product_name = ' bigip '
def main( ) :
def cleanup_tokens( client ) :
try :
try :
spec = ArgumentSpec ( )
resource = client . api . shared . authz . tokens_s . token . load (
name = client . api . icrs . token
client = AnsibleF5Client (
argument_spec = spec . argument_spec ,
supports_check_mode = spec . supports_check_mode ,
f5_product_name = spec . f5_product_name
)
)
resource . delete ( )
except Exception :
pass
def main ( ) :
if not HAS_F5SDK :
raise F5ModuleError ( " The python f5-sdk module is required " )
if not HAS_NETADDR :
raise F5ModuleError ( " The python netaddr module is required " )
if not HAS_F5SDK :
spec = ArgumentSpec ( )
raise F5ModuleError ( " The python f5-sdk module is required " )
if not HAS_NETADDR :
client = AnsibleF5Client (
raise F5ModuleError ( " The python netaddr module is required " )
argument_spec = spec . argument_spec ,
supports_check_mode = spec . supports_check_mode ,
f5_product_name = spec . f5_product_name
)
try :
mm = ModuleManager ( client )
mm = ModuleManager ( client )
results = mm . exec_module ( )
results = mm . exec_module ( )
cleanup_tokens ( client )
client . module . exit_json ( * * results )
client . module . exit_json ( * * results )
except F5ModuleError as e :
except F5ModuleError as e :
cleanup_tokens ( client )
client . module . fail_json ( msg = str ( e ) )
client . module . fail_json ( msg = str ( e ) )