#NEWLINE# def allocate_floating_ip( self , context , project_id , auto_assigned = False , pool = None ) : #NEWLINE# #INDENT# 'Gets a floating IP from the pool.' #NEWLINE# pool = ( pool or CONF . default_floating_pool ) #NEWLINE# use_quota = ( not auto_assigned ) #NEWLINE# if ( not self . _floating_ip_pool_exists ( context , pool ) ) : #NEWLINE# #INDENT# raise exception . FloatingIpPoolNotFound ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if use_quota : #NEWLINE# #INDENT# reservations = QUOTAS . reserve ( context , floating_ips = 1 , project_id = project_id ) #NEWLINE# #UNINDENT# #UNINDENT# except exception . OverQuota : #NEWLINE# #INDENT# LOG . warning ( _LW ( 'Quota exceeded for %s, tried to allocate floating IP' ) , context . project_id ) #NEWLINE# raise exception . FloatingIpLimitExceeded ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# floating_ip = objects . FloatingIP . allocate_address ( context , project_id , pool , auto_assigned = auto_assigned ) #NEWLINE# payload = dict ( project_id = project_id , floating_ip = floating_ip ) #NEWLINE# self . notifier . info ( context , 'network.floating_ip.allocate' , payload ) #NEWLINE# if use_quota : #NEWLINE# #INDENT# QUOTAS . commit ( context , reservations , project_id = project_id ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# if use_quota : #NEWLINE# #INDENT# QUOTAS . rollback ( context , reservations , project_id = project_id ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return floating_ip