<s> from oslo_utils import strutils <EOL> import webob <EOL> from nova . api . openstack import common <EOL> from nova . api . openstack . compute . views import flavors as flavors_view <EOL> from nova . api . openstack import extensions <EOL> from nova . api . openstack import wsgi <EOL> from nova . compute import flavors <EOL> from nova import exception <EOL> from nova . i18n import _ <EOL> from nova import utils <EOL> ALIAS = '<STR_LIT>' <EOL> class FlavorsController ( wsgi . Controller ) : <EOL> """<STR_LIT>""" <EOL> _view_builder_class = flavors_view . ViewBuilderV21 <EOL> @ extensions . expected_errors ( <NUM_LIT> ) <EOL> def index ( self , req ) : <EOL> """<STR_LIT>""" <EOL> limited_flavors = self . _get_flavors ( req ) <EOL> return self . _view_builder . index ( req , limited_flavors ) <EOL> @ extensions . expected_errors ( <NUM_LIT> ) <EOL> def detail ( self , req ) : <EOL> """<STR_LIT>""" <EOL> limited_flavors = self . _get_flavors ( req ) <EOL> req . cache_db_flavors ( limited_flavors ) <EOL> return self . _view_builder . detail ( req , limited_flavors ) <EOL> @ extensions . expected_errors ( <NUM_LIT> ) <EOL> def show ( self , req , id ) : <EOL> """<STR_LIT>""" <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> try : <EOL> flavor = flavors . get_flavor_by_flavor_id ( id , ctxt = context ) <EOL> req . cache_db_flavor ( flavor ) <EOL> except exception . FlavorNotFound as e : <EOL> raise webob . exc . HTTPNotFound ( explanation = e . format_message ( ) ) <EOL> return self . _view_builder . show ( req , flavor ) <EOL> def _parse_is_public ( self , is_public ) : <EOL> """<STR_LIT>""" <EOL> if is_public is None : <EOL> return True <EOL> elif utils . is_none_string ( is_public ) : <EOL> return None <EOL> else : <EOL> try : <EOL> return strutils . bool_from_string ( is_public , strict = True ) <EOL> except ValueError : <EOL> msg = _ ( '<STR_LIT>' ) % is_public <EOL> raise webob . exc . HTTPBadRequest ( explanation = msg ) <EOL> def _get_flavors ( self , req ) : <EOL> """<STR_LIT>""" <EOL> filters = { } <EOL> sort_key = req . params . get ( '<STR_LIT>' ) or '<STR_LIT>' <EOL> sort_dir = req . params . get ( '<STR_LIT>' ) or '<STR_LIT>' <EOL> limit , marker = common . get_limit_and_marker ( req ) <EOL> context = req . environ [ '<STR_LIT>' ] <EOL> if context . is_admin : <EOL> filters [ '<STR_LIT>' ] = self . _parse_is_public ( <EOL> req . params . get ( '<STR_LIT>' , None ) ) <EOL> else : <EOL> filters [ '<STR_LIT>' ] = True <EOL> filters [ '<STR_LIT>' ] = False <EOL> if '<STR_LIT>' in req . params : <EOL> try : <EOL> filters [ '<STR_LIT>' ] = int ( req . params [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> msg = _ ( '<STR_LIT>' ) % req . params [ '<STR_LIT>' ] <EOL> raise webob . exc . HTTPBadRequest ( explanation = msg ) <EOL> if '<STR_LIT>' in req . params : <EOL> try : <EOL> filters [ '<STR_LIT>' ] = int ( req . params [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> msg = ( _ ( '<STR_LIT>' ) % <EOL> req . params [ '<STR_LIT>' ] ) <EOL> raise webob . exc . HTTPBadRequest ( explanation = msg ) <EOL> try : <EOL> limited_flavors = flavors . get_all_flavors_sorted_list ( context , <EOL> filters = filters , sort_key = sort_key , sort_dir = sort_dir , <EOL> limit = limit , marker = marker ) <EOL> except exception . MarkerNotFound : <EOL> msg = _ ( '<STR_LIT>' ) % marker <EOL> raise webob . exc . HTTPBadRequest ( explanation = msg ) <EOL> return limited_flavors <EOL> class Flavors ( extensions . V21APIExtensionBase ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> alias = ALIAS <EOL> version = <NUM_LIT:1> <EOL> def get_resources ( self ) : <EOL> collection_actions = { '<STR_LIT>' : '<STR_LIT:GET>' } <EOL> member_actions = { '<STR_LIT:action>' : '<STR_LIT:POST>' } <EOL> resources = [ <EOL> extensions . ResourceExtension ( ALIAS , <EOL> FlavorsController ( ) , <EOL> member_name = '<STR_LIT>' , <EOL> collection_actions = collection_actions , <EOL> member_actions = member_actions ) <EOL> ] <EOL> return resources <EOL> def get_controller_extensions ( self ) : <EOL> return [ ] </s>
