<s> import webob . exc <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from oslo_utils import excutils <EOL> from oslo_utils import uuidutils <EOL> import six <EOL> from networking_cisco . _i18n import _ , _LE <EOL> from neutron . api . v2 import attributes <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def get_specific_config ( prefix ) : <EOL> """<STR_LIT>""" <EOL> conf_dict = { } <EOL> multi_parser = cfg . MultiConfigParser ( ) <EOL> read_ok = multi_parser . read ( cfg . CONF . config_file ) <EOL> if len ( read_ok ) != len ( cfg . CONF . config_file ) : <EOL> raise cfg . Error ( _ ( "<STR_LIT>" ) ) <EOL> for parsed_file in multi_parser . parsed : <EOL> for parsed_item in parsed_file . keys ( ) : <EOL> p_i = parsed_item . lower ( ) <EOL> if p_i . startswith ( prefix ) : <EOL> section_type , uuid = p_i . split ( '<STR_LIT::>' ) <EOL> if section_type == prefix : <EOL> conf_dict [ uuid ] = { k : v [ <NUM_LIT:0> ] for ( k , v ) in parsed_file [ <EOL> parsed_item ] . items ( ) } <EOL> return conf_dict <EOL> def verify_resource_dict ( res_dict , is_create , attr_info ) : <EOL> """<STR_LIT>""" <EOL> if is_create : <EOL> for attr , attr_vals in six . iteritems ( attr_info ) : <EOL> if attr_vals [ '<STR_LIT>' ] : <EOL> if '<STR_LIT:default>' not in attr_vals and attr not in res_dict : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % attr <EOL> raise webob . exc . HTTPBadRequest ( msg ) <EOL> res_dict [ attr ] = res_dict . get ( attr , attr_vals . get ( '<STR_LIT:default>' ) ) <EOL> else : <EOL> if attr in res_dict : <EOL> msg = _ ( "<STR_LIT>" ) % attr <EOL> raise webob . exc . HTTPBadRequest ( msg ) <EOL> else : <EOL> for attr , attr_vals in six . iteritems ( attr_info ) : <EOL> if attr in res_dict and not attr_vals [ '<STR_LIT>' ] : <EOL> msg = _ ( "<STR_LIT>" ) % attr <EOL> raise webob . exc . HTTPBadRequest ( msg ) <EOL> for attr , attr_vals in six . iteritems ( attr_info ) : <EOL> if ( attr not in res_dict or <EOL> res_dict [ attr ] is attributes . ATTR_NOT_SPECIFIED ) : <EOL> continue <EOL> if '<STR_LIT>' in attr_vals : <EOL> res_dict [ attr ] = attr_vals [ '<STR_LIT>' ] ( res_dict [ attr ] ) <EOL> if '<STR_LIT>' not in attr_vals : <EOL> continue <EOL> for rule in attr_vals [ '<STR_LIT>' ] : <EOL> _ensure_format ( rule , attr , res_dict ) <EOL> res = attributes . validators [ rule ] ( res_dict [ attr ] , <EOL> attr_vals [ '<STR_LIT>' ] [ rule ] ) <EOL> if res : <EOL> msg_dict = dict ( attr = attr , reason = res ) <EOL> msg = ( _ ( "<STR_LIT>" ) % <EOL> msg_dict ) <EOL> raise webob . exc . HTTPBadRequest ( msg ) <EOL> return res_dict <EOL> def uuidify ( val ) : <EOL> """<STR_LIT>""" <EOL> if uuidutils . is_uuid_like ( val ) : <EOL> return val <EOL> else : <EOL> try : <EOL> int_val = int ( val , <NUM_LIT:16> ) <EOL> except ValueError : <EOL> with excutils . save_and_reraise_exception ( ) : <EOL> LOG . error ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , val ) <EOL> res = str ( int_val ) <EOL> num = <NUM_LIT:12> - len ( res ) <EOL> return "<STR_LIT>" + "<STR_LIT:0>" * num + res <EOL> def _ensure_format ( rule , attribute , res_dict ) : <EOL> """<STR_LIT>""" <EOL> if rule == '<STR_LIT>' or ( rule == '<STR_LIT>' and <EOL> res_dict [ attribute ] ) : <EOL> res_dict [ attribute ] = uuidify ( res_dict [ attribute ] ) <EOL> elif rule == '<STR_LIT>' : <EOL> if not res_dict [ attribute ] : <EOL> res_dict [ attribute ] = [ ] <EOL> else : <EOL> temp_list = res_dict [ attribute ] . split ( '<STR_LIT::>' ) <EOL> res_dict [ attribute ] = [ ] <EOL> for item in temp_list : <EOL> res_dict [ attribute ] . append = uuidify ( item ) <EOL> elif rule == '<STR_LIT>' and res_dict [ attribute ] == "<STR_LIT>" : <EOL> res_dict [ attribute ] = None </s>
