#NEWLINE# @ extensions . expected_errors ( ( 400 , 403 , 404 ) ) #NEWLINE# def create( self , req , body = None ) : #NEWLINE# #INDENT# context = req . environ [ 'nova.context' ] #NEWLINE# authorize ( context ) #NEWLINE# pool = None #NEWLINE# if ( body and ( 'pool' in body ) ) : #NEWLINE# #INDENT# pool = body [ 'pool' ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# address = self . network_api . allocate_floating_ip ( context , pool ) #NEWLINE# ip = self . network_api . get_floating_ip_by_address ( context , address ) #NEWLINE# #UNINDENT# except exception . NoMoreFloatingIps : #NEWLINE# #INDENT# if pool : #NEWLINE# #INDENT# msg = ( _ ( 'No more floating IPs in pool %s.' ) % pool ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = _ ( 'No more floating IPs available.' ) #NEWLINE# #UNINDENT# raise webob . exc . HTTPNotFound ( explanation = msg ) #NEWLINE# #UNINDENT# except exception . FloatingIpLimitExceeded : #NEWLINE# #INDENT# if pool : #NEWLINE# #INDENT# msg = ( _ ( 'IP allocation over quota in pool %s.' ) % pool ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = _ ( 'IP allocation over quota.' ) #NEWLINE# #UNINDENT# raise webob . exc . HTTPForbidden ( explanation = msg ) #NEWLINE# #UNINDENT# except exception . FloatingIpPoolNotFound as e : #NEWLINE# #INDENT# raise webob . exc . HTTPNotFound ( explanation = e . format_message ( ) ) #NEWLINE# #UNINDENT# except exception . FloatingIpBadRequest as e : #NEWLINE# #INDENT# raise webob . exc . HTTPBadRequest ( explanation = e . format_message ( ) ) #NEWLINE# #UNINDENT# return _translate_floating_ip_view ( ip )