<s> import six <EOL> from nova . api . openstack import extensions <EOL> from nova . api . openstack import wsgi <EOL> from nova import quota <EOL> QUOTAS = quota . QUOTAS <EOL> XMLNS = "<STR_LIT>" <EOL> ALIAS = "<STR_LIT>" <EOL> authorize = extensions . soft_extension_authorizer ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> authorize_for_admin = extensions . extension_authorizer ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class UsedLimitsController ( wsgi . Controller ) : <EOL> def __init__ ( self , ext_mgr ) : <EOL> self . ext_mgr = ext_mgr <EOL> @ staticmethod <EOL> def _reserved ( req ) : <EOL> try : <EOL> return int ( req . GET [ '<STR_LIT>' ] ) <EOL> except ( ValueError , KeyError ) : <EOL> return False <EOL> @ wsgi . extends <EOL> def index ( self , req , resp_obj ) : <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> project_id = self . _project_id ( context , req ) <EOL> quotas = QUOTAS . get_project_quotas ( context , project_id , usages = True ) <EOL> quota_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> quota_map [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> used_limits = { } <EOL> for display_name , key in six . iteritems ( quota_map ) : <EOL> if key in quotas : <EOL> reserved = ( quotas [ key ] [ '<STR_LIT>' ] <EOL> if self . _reserved ( req ) else <NUM_LIT:0> ) <EOL> used_limits [ display_name ] = quotas [ key ] [ '<STR_LIT>' ] + reserved <EOL> resp_obj . obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] . update ( used_limits ) <EOL> def _project_id ( self , context , req ) : <EOL> if self . ext_mgr . is_loaded ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' in req . GET : <EOL> tenant_id = req . GET . get ( '<STR_LIT>' ) <EOL> target = { <EOL> '<STR_LIT>' : tenant_id , <EOL> '<STR_LIT>' : context . user_id <EOL> } <EOL> authorize_for_admin ( context , target = target ) <EOL> return tenant_id <EOL> return context . project_id <EOL> class Used_limits ( extensions . ExtensionDescriptor ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> alias = ALIAS <EOL> namespace = XMLNS <EOL> updated = "<STR_LIT>" <EOL> def get_controller_extensions ( self ) : <EOL> controller = UsedLimitsController ( self . ext_mgr ) <EOL> limits_ext = extensions . ControllerExtension ( self , '<STR_LIT>' , <EOL> controller = controller ) <EOL> return [ limits_ext ] </s>
