@ -147,19 +147,22 @@ class StorageConnectionModule(BaseModule):
vfs_type = self . param ( ' vfs_type ' ) ,
)
def post_present ( self , entity_id ) :
if self . param ( ' storage ' ) :
def _get_storage_domain_service ( self ) :
sds_service = self . _connection . system_service ( ) . storage_domains_service ( )
sd = search_by_name ( sds_service , self . param ( ' storage ' ) )
if sd is None :
raise Exception (
" Storage ' %s ' was not found. " % self . param ( ' storage ' )
)
return sd , sds_service . storage_domain_service ( sd . id )
def post_present ( self , entity_id ) :
if self . param ( ' storage ' ) :
sd , sd_service = self . _get_storage_domain_service ( )
if entity_id not in [
sd_conn . id for sd_conn in self . _connection . follow_link ( sd . storage_connections )
] :
scs_service = sd s _service. storage_domain_service ( sd . id ) . storage_connections_service ( )
scs_service = sd _service. storage_connections_service ( )
if not self . _module . check_mode :
scs_service . add (
connection = otypes . StorageConnection (
@ -168,6 +171,18 @@ class StorageConnectionModule(BaseModule):
)
self . changed = True
def pre_remove ( self , entity_id ) :
if self . param ( ' storage ' ) :
sd , sd_service = self . _get_storage_domain_service ( )
if entity_id in [
sd_conn . id for sd_conn in self . _connection . follow_link ( sd . storage_connections )
] :
scs_service = sd_service . storage_connections_service ( )
sc_service = scs_service . connection_service ( entity_id )
if not self . _module . check_mode :
sc_service . remove ( )
self . changed = True
def update_check ( self , entity ) :
return (
equal ( self . param ( ' address ' ) , entity . address ) and
@ -254,6 +269,7 @@ def main():
)
storage_connection_module . post_present ( ret [ ' id ' ] )
elif state == ' absent ' :
storage_connection_module . pre_remove ( module . params [ ' id ' ] )
ret = storage_connection_module . remove ( entity = entity )
module . exit_json ( * * ret )