#NEWLINE# @ log_backend_action ( 'pull floating IPs for tenant' ) #NEWLINE# def pull_tenant_floating_ips( self , tenant ) : #NEWLINE# #INDENT# service_project_link = tenant . service_project_link #NEWLINE# neutron = self . neutron_client #NEWLINE# try : #NEWLINE# #INDENT# nc_floating_ips = { ip . backend_id : ip for ip in service_project_link . floating_ips . all ( ) } #NEWLINE# try : #NEWLINE# #INDENT# backend_floating_ips = { ip [ 'id' ] : ip for ip in neutron . list_floatingips ( tenant_id = self . tenant_id ) [ 'floatingips' ] if ( ip . get ( 'floating_ip_address' ) and ip . get ( 'status' ) ) } #NEWLINE# #UNINDENT# except neutron_exceptions . NeutronClientException as e : #NEWLINE# #INDENT# six . reraise ( OpenStackBackendError , e ) #NEWLINE# #UNINDENT# backend_ids = set ( backend_floating_ips . keys ( ) ) #NEWLINE# nc_ids = set ( nc_floating_ips . keys ( ) ) #NEWLINE# with transaction . atomic ( ) : #NEWLINE# #INDENT# for ip_id in ( nc_ids - backend_ids ) : #NEWLINE# #INDENT# ip = nc_floating_ips [ ip_id ] #NEWLINE# ip . delete ( ) #NEWLINE# logger . info ( 'Deleted stale floating IP port %s in database' , ip . uuid ) #NEWLINE# #UNINDENT# for ip_id in ( backend_ids - nc_ids ) : #NEWLINE# #INDENT# ip = backend_floating_ips [ ip_id ] #NEWLINE# created_ip = service_project_link . floating_ips . create ( status = ip [ 'status' ] , backend_id = ip [ 'id' ] , address = ip [ 'floating_ip_address' ] , backend_network_id = ip [ 'floating_network_id' ] ) #NEWLINE# logger . info ( 'Created new floating IP port %s in database' , created_ip . uuid ) #NEWLINE# #UNINDENT# for ip_id in ( nc_ids & backend_ids ) : #NEWLINE# #INDENT# nc_ip = nc_floating_ips [ ip_id ] #NEWLINE# backend_ip = backend_floating_ips [ ip_id ] #NEWLINE# if ( ( nc_ip . status != backend_ip [ 'status' ] ) or ( nc_ip . address != backend_ip [ 'floating_ip_address' ] ) or ( nc_ip . backend_network_id != backend_ip [ 'floating_network_id' ] ) ) : #NEWLINE# #INDENT# if ( not ( ( nc_ip . status == 'BOOKED' ) and ( backend_ip [ 'status' ] == 'DOWN' ) ) ) : #NEWLINE# #INDENT# nc_ip . status = backend_ip [ 'status' ] #NEWLINE# #UNINDENT# nc_ip . address = backend_ip [ 'floating_ip_address' ] #NEWLINE# nc_ip . backend_network_id = backend_ip [ 'floating_network_id' ] #NEWLINE# nc_ip . save ( ) #NEWLINE# logger . info ( 'Updated existing floating IP port %s in database' , nc_ip . uuid ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# six . reraise ( OpenStackBackendError , e )