#NEWLINE# @ log_backend_action ( 'pull security groups for tenant' ) #NEWLINE# def pull_tenant_security_groups( self , tenant ) : #NEWLINE# #INDENT# nova = self . nova_client #NEWLINE# service_project_link = tenant . service_project_link #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# backend_security_groups = nova . security_groups . list ( ) #NEWLINE# #UNINDENT# except nova_exceptions . ClientException as e : #NEWLINE# #INDENT# six . reraise ( OpenStackBackendError , e ) #NEWLINE# #UNINDENT# nonexistent_groups = [ ] #NEWLINE# unsynchronized_groups = [ ] #NEWLINE# extra_groups = service_project_link . security_groups . exclude ( backend_id__in = [ g . id for g in backend_security_groups ] ) #NEWLINE# with transaction . atomic ( ) : #NEWLINE# #INDENT# for backend_group in backend_security_groups : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# nc_group = service_project_link . security_groups . get ( backend_id = backend_group . id ) #NEWLINE# if ( not self . _are_security_groups_equal ( backend_group , nc_group ) ) : #NEWLINE# #INDENT# unsynchronized_groups . append ( backend_group ) #NEWLINE# #UNINDENT# #UNINDENT# except models . SecurityGroup . DoesNotExist : #NEWLINE# #INDENT# nonexistent_groups . append ( backend_group ) #NEWLINE# #UNINDENT# #UNINDENT# extra_groups . delete ( ) #NEWLINE# if extra_groups : #NEWLINE# #INDENT# logger . debug ( 'Deleted stale security group: %s.' , ' ,' . join ( ( ( '%s (PK: %s)' % ( sg . name , sg . pk ) ) for sg in extra_groups ) ) ) #NEWLINE# #UNINDENT# for backend_group in unsynchronized_groups : #NEWLINE# #INDENT# nc_security_group = service_project_link . security_groups . get ( backend_id = g . id ) #NEWLINE# if ( backend_group . name != nc_security_group . name ) : #NEWLINE# #INDENT# nc_security_group . name = backend_group . name #NEWLINE# nc_security_group . state = StateMixin . States . OK #NEWLINE# nc_security_group . save ( ) #NEWLINE# #UNINDENT# self . pull_security_group_rules ( nc_security_group ) #NEWLINE# logger . debug ( 'Updated existing security group %s (PK: %s).' , nc_security_group . name , nc_security_group . pk ) #NEWLINE# #UNINDENT# for backend_group in nonexistent_groups : #NEWLINE# #INDENT# nc_security_group = service_project_link . security_groups . create ( backend_id = backend_group . id , name = backend_group . name , state = StateMixin . States . OK ) #NEWLINE# self . pull_security_group_rules ( nc_security_group ) #NEWLINE# logger . debug ( 'Created new security group %s (PK: %s).' , nc_security_group . name , nc_security_group . pk ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# six . reraise ( OpenStackBackendError , e )