<s> from oslo_db import exception as db_exc <EOL> from oslo_log import log as logging <EOL> from oslo_utils import excutils <EOL> from oslo_utils import uuidutils <EOL> from sqlalchemy import exc as sql_exc <EOL> from sqlalchemy . orm import exc <EOL> from networking_cisco . _i18n import _LE <EOL> from networking_cisco . plugins . cisco . db . l3 import l3_models <EOL> import networking_cisco . plugins . cisco . extensions . routertype as routertype <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class RoutertypeDbMixin ( routertype . RoutertypePluginBase ) : <EOL> """<STR_LIT>""" <EOL> def create_routertype ( self , context , routertype ) : <EOL> """<STR_LIT>""" <EOL> LOG . debug ( "<STR_LIT>" , routertype ) <EOL> rt = routertype [ '<STR_LIT>' ] <EOL> with context . session . begin ( subtransactions = True ) : <EOL> routertype_db = l3_models . RouterType ( <EOL> id = self . _get_id ( rt ) , <EOL> tenant_id = rt [ '<STR_LIT>' ] , <EOL> name = rt [ '<STR_LIT:name>' ] , <EOL> description = rt [ '<STR_LIT:description>' ] , <EOL> template_id = rt [ '<STR_LIT>' ] , <EOL> ha_enabled_by_default = rt [ '<STR_LIT>' ] , <EOL> shared = rt [ '<STR_LIT>' ] , <EOL> slot_need = rt [ '<STR_LIT>' ] , <EOL> scheduler = rt [ '<STR_LIT>' ] , <EOL> driver = rt [ '<STR_LIT>' ] , <EOL> cfg_agent_service_helper = rt [ '<STR_LIT>' ] , <EOL> cfg_agent_driver = rt [ '<STR_LIT>' ] ) <EOL> context . session . add ( routertype_db ) <EOL> return self . _make_routertype_dict ( routertype_db ) <EOL> def update_routertype ( self , context , id , routertype ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> rt = routertype [ '<STR_LIT>' ] <EOL> with context . session . begin ( subtransactions = True ) : <EOL> rt_query = context . session . query ( l3_models . RouterType ) <EOL> if not rt_query . filter_by ( id = id ) . update ( rt ) : <EOL> raise routertype . RouterTypeNotFound ( id = id ) <EOL> return self . get_routertype ( context , id ) <EOL> def delete_routertype ( self , context , id ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> try : <EOL> with context . session . begin ( subtransactions = True ) : <EOL> routertype_query = context . session . query ( l3_models . RouterType ) <EOL> if not routertype_query . filter_by ( id = id ) . delete ( ) : <EOL> raise routertype . RouterTypeNotFound ( id = id ) <EOL> except db_exc . DBError as e : <EOL> with excutils . save_and_reraise_exception ( ) as ctxt : <EOL> if isinstance ( e . inner_exception , sql_exc . IntegrityError ) : <EOL> ctxt . reraise = False <EOL> raise routertype . RouterTypeInUse ( id = id ) <EOL> def get_routertype ( self , context , id , fields = None ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> rt_db = self . _get_routertype ( context , id ) <EOL> return self . _make_routertype_dict ( rt_db , fields ) <EOL> def get_routertypes ( self , context , filters = None , fields = None , <EOL> sorts = None , limit = None , marker = None , <EOL> page_reverse = False ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> return self . _get_collection ( context , l3_models . RouterType , <EOL> self . _make_routertype_dict , <EOL> filters = filters , fields = fields , <EOL> sorts = sorts , limit = limit , <EOL> marker_obj = marker , <EOL> page_reverse = page_reverse ) <EOL> def get_routertype_by_id_name ( self , context , id_or_name ) : <EOL> return self . _make_routertype_dict ( <EOL> self . get_routertype_db_by_id_name ( context , id_or_name ) ) <EOL> def get_routertype_db_by_id_name ( self , context , id_or_name ) : <EOL> query = context . session . query ( l3_models . RouterType ) <EOL> query = query . filter ( l3_models . RouterType . id == id_or_name ) <EOL> try : <EOL> return query . one ( ) <EOL> except exc . MultipleResultsFound : <EOL> with excutils . save_and_reraise_exception ( ) : <EOL> LOG . error ( _LE ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , id_or_name ) <EOL> raise routertype . RouterTypeNotFound ( router_type = id_or_name ) <EOL> except exc . NoResultFound : <EOL> query = context . session . query ( l3_models . RouterType ) <EOL> query = query . filter ( l3_models . RouterType . name == id_or_name ) <EOL> try : <EOL> return query . one ( ) <EOL> except exc . MultipleResultsFound : <EOL> with excutils . save_and_reraise_exception ( ) : <EOL> LOG . debug ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> id_or_name ) <EOL> raise routertype . MultipleRouterTypes ( name = id_or_name ) <EOL> except exc . NoResultFound : <EOL> with excutils . save_and_reraise_exception ( ) : <EOL> LOG . error ( _LE ( '<STR_LIT>' ) , <EOL> id_or_name ) <EOL> raise routertype . RouterTypeNotFound ( id = id_or_name ) <EOL> def _get_routertype ( self , context , id ) : <EOL> try : <EOL> return self . _get_by_id ( context , l3_models . RouterType , id ) <EOL> except exc . NoResultFound : <EOL> raise routertype . RouterTypeNotFound ( id = id ) <EOL> def _make_routertype_dict ( self , routertype , fields = None ) : <EOL> res = { '<STR_LIT:id>' : routertype [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT:name>' : routertype [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT:description>' : routertype [ '<STR_LIT:description>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : routertype [ '<STR_LIT>' ] } <EOL> return self . _fields ( res , fields ) <EOL> def _get_id ( self , res ) : <EOL> uuid = res . get ( '<STR_LIT:id>' ) <EOL> if uuid : <EOL> return uuid <EOL> return uuidutils . generate_uuid ( ) </s>
