<s> """<STR_LIT>""" <EOL> from nova import context <EOL> from nova import db <EOL> from nova import exception <EOL> from nova import flags <EOL> from nova import log as logging <EOL> FLAGS = flags . FLAGS <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> def create ( name , memory , vcpus , local_gb , flavorid , swap = <NUM_LIT:0> , <EOL> rxtx_quota = <NUM_LIT:0> , rxtx_cap = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> for option in [ memory , vcpus , local_gb , flavorid ] : <EOL> try : <EOL> int ( option ) <EOL> except ValueError : <EOL> raise exception . InvalidInput ( reason = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if ( int ( memory ) <= <NUM_LIT:0> ) or ( int ( vcpus ) <= <NUM_LIT:0> ) or ( int ( local_gb ) < <NUM_LIT:0> ) : <EOL> raise exception . InvalidInput ( reason = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> try : <EOL> db . instance_type_create ( <EOL> context . get_admin_context ( ) , <EOL> dict ( name = name , <EOL> memory_mb = memory , <EOL> vcpus = vcpus , <EOL> local_gb = local_gb , <EOL> flavorid = flavorid , <EOL> swap = swap , <EOL> rxtx_quota = rxtx_quota , <EOL> rxtx_cap = rxtx_cap ) ) <EOL> except exception . DBError , e : <EOL> LOG . exception ( _ ( '<STR_LIT>' ) % e ) <EOL> raise exception . ApiError ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> % locals ( ) ) <EOL> def destroy ( name ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> raise exception . InvalidInstanceType ( instance_type = name ) <EOL> else : <EOL> try : <EOL> db . instance_type_destroy ( context . get_admin_context ( ) , name ) <EOL> except exception . NotFound : <EOL> LOG . exception ( _ ( '<STR_LIT>' ) % name ) <EOL> raise exception . ApiError ( _ ( "<STR_LIT>" ) % name ) <EOL> def purge ( name ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> raise exception . InvalidInstanceType ( instance_type = name ) <EOL> else : <EOL> try : <EOL> db . instance_type_purge ( context . get_admin_context ( ) , name ) <EOL> except exception . NotFound : <EOL> LOG . exception ( _ ( '<STR_LIT>' ) % name ) <EOL> raise exception . ApiError ( _ ( "<STR_LIT>" ) % name ) <EOL> def get_all_types ( inactive = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return db . instance_type_get_all ( context . get_admin_context ( ) , inactive ) <EOL> get_all_flavors = get_all_types <EOL> def get_default_instance_type ( ) : <EOL> """<STR_LIT>""" <EOL> name = FLAGS . default_instance_type <EOL> try : <EOL> return get_instance_type_by_name ( name ) <EOL> except exception . DBError : <EOL> raise exception . ApiError ( _ ( "<STR_LIT>" ) % name ) <EOL> def get_instance_type ( id ) : <EOL> """<STR_LIT>""" <EOL> if id is None : <EOL> return get_default_instance_type ( ) <EOL> try : <EOL> ctxt = context . get_admin_context ( ) <EOL> return db . instance_type_get ( ctxt , id ) <EOL> except exception . DBError : <EOL> raise exception . ApiError ( _ ( "<STR_LIT>" ) % id ) <EOL> def get_instance_type_by_name ( name ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> return get_default_instance_type ( ) <EOL> try : <EOL> ctxt = context . get_admin_context ( ) <EOL> return db . instance_type_get_by_name ( ctxt , name ) <EOL> except exception . DBError : <EOL> raise exception . ApiError ( _ ( "<STR_LIT>" ) % name ) <EOL> def get_instance_type_by_flavor_id ( flavor_id ) : <EOL> """<STR_LIT>""" <EOL> ctxt = context . get_admin_context ( ) <EOL> try : <EOL> return db . instance_type_get_by_flavor_id ( ctxt , flavor_id ) <EOL> except ValueError : <EOL> raise exception . FlavorNotFound ( flavor_id = flavor_id ) </s>
