<s> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from oslo_utils import importutils <EOL> from nova import exception <EOL> from nova . i18n import _ <EOL> LOG = logging . getLogger ( __name__ ) <EOL> CONF = cfg . CONF <EOL> ironic = None <EOL> IRONIC_API_VERSION = ( <NUM_LIT:1> , <NUM_LIT:8> ) <EOL> class IronicClientWrapper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> global ironic <EOL> if ironic is None : <EOL> ironic = importutils . import_module ( '<STR_LIT>' ) <EOL> if not hasattr ( ironic , '<STR_LIT>' ) : <EOL> ironic . exc = importutils . import_module ( '<STR_LIT>' ) <EOL> if not hasattr ( ironic , '<STR_LIT>' ) : <EOL> ironic . client = importutils . import_module ( <EOL> '<STR_LIT>' ) <EOL> self . _cached_client = None <EOL> def _invalidate_cached_client ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _cached_client = None <EOL> def _get_client ( self , retry_on_conflict = True ) : <EOL> max_retries = CONF . ironic . api_max_retries if retry_on_conflict else <NUM_LIT:1> <EOL> retry_interval = ( CONF . ironic . api_retry_interval <EOL> if retry_on_conflict else <NUM_LIT:0> ) <EOL> if retry_on_conflict and self . _cached_client is not None : <EOL> return self . _cached_client <EOL> auth_token = CONF . ironic . admin_auth_token <EOL> if auth_token is None : <EOL> kwargs = { '<STR_LIT>' : CONF . ironic . admin_username , <EOL> '<STR_LIT>' : CONF . ironic . admin_password , <EOL> '<STR_LIT>' : CONF . ironic . admin_url , <EOL> '<STR_LIT>' : CONF . ironic . admin_tenant_name , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : CONF . ironic . api_endpoint } <EOL> else : <EOL> kwargs = { '<STR_LIT>' : auth_token , <EOL> '<STR_LIT>' : CONF . ironic . api_endpoint } <EOL> if CONF . ironic . cafile : <EOL> kwargs [ '<STR_LIT>' ] = CONF . ironic . cafile <EOL> kwargs [ '<STR_LIT>' ] = CONF . ironic . cafile <EOL> kwargs [ '<STR_LIT>' ] = max_retries <EOL> kwargs [ '<STR_LIT>' ] = retry_interval <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' % IRONIC_API_VERSION <EOL> try : <EOL> cli = ironic . client . get_client ( IRONIC_API_VERSION [ <NUM_LIT:0> ] , ** kwargs ) <EOL> if retry_on_conflict : <EOL> self . _cached_client = cli <EOL> except ironic . exc . Unauthorized : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> LOG . error ( msg ) <EOL> raise exception . NovaException ( msg ) <EOL> return cli <EOL> def _multi_getattr ( self , obj , attr ) : <EOL> """<STR_LIT>""" <EOL> for attribute in attr . split ( "<STR_LIT:.>" ) : <EOL> obj = getattr ( obj , attribute ) <EOL> return obj <EOL> def call ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> retry_on_conflict = kwargs . pop ( '<STR_LIT>' , True ) <EOL> for attempt in range ( <NUM_LIT:2> ) : <EOL> client = self . _get_client ( retry_on_conflict = retry_on_conflict ) <EOL> try : <EOL> return self . _multi_getattr ( client , method ) ( * args , ** kwargs ) <EOL> except ironic . exc . Unauthorized : <EOL> if not attempt : <EOL> self . _invalidate_cached_client ( ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> raise </s>
