<s> import logging <EOL> from openstackclient . common import exceptions <EOL> from openstackclient . common import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> DEFAULT_API_VERSION = '<STR_LIT:2>' <EOL> API_VERSION_OPTION = '<STR_LIT>' <EOL> API_NAME = '<STR_LIT>' <EOL> API_VERSIONS = { <EOL> "<STR_LIT:2>" : "<STR_LIT>" , <EOL> } <EOL> _compute_api_version = None <EOL> def make_client ( instance ) : <EOL> """<STR_LIT>""" <EOL> from novaclient import client as nova_client <EOL> if _compute_api_version is not None : <EOL> version = _compute_api_version <EOL> else : <EOL> version = instance . _api_version [ API_NAME ] <EOL> LOG . debug ( '<STR_LIT>' , version ) <EOL> http_log_debug = utils . get_effective_log_level ( ) <= logging . DEBUG <EOL> extensions = [ ext for ext in nova_client . discover_extensions ( version ) <EOL> if ext . name == "<STR_LIT>" ] <EOL> kwargs = utils . build_kwargs_dict ( '<STR_LIT>' , instance . _interface ) <EOL> client = nova_client . Client ( <EOL> version , <EOL> session = instance . session , <EOL> extensions = extensions , <EOL> http_log_debug = http_log_debug , <EOL> timings = instance . timing , <EOL> region_name = instance . _region_name , <EOL> ** kwargs <EOL> ) <EOL> return client <EOL> def build_option_parser ( parser ) : <EOL> """<STR_LIT>""" <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' + <EOL> DEFAULT_API_VERSION + <EOL> '<STR_LIT>' ) <EOL> return parser <EOL> def check_api_version ( check_version ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from novaclient import api_versions <EOL> except ImportError : <EOL> return False <EOL> import novaclient <EOL> global _compute_api_version <EOL> _compute_api_version = api_versions . get_api_version ( check_version ) <EOL> if _compute_api_version > api_versions . APIVersion ( "<STR_LIT>" ) : <EOL> if not _compute_api_version . matches ( <EOL> novaclient . API_MIN_VERSION , <EOL> novaclient . API_MAX_VERSION , <EOL> ) : <EOL> raise exceptions . CommandError ( <EOL> "<STR_LIT>" % ( <EOL> novaclient . API_MIN_VERSION . get_string ( ) , <EOL> novaclient . API_MAX_VERSION . get_string ( ) , <EOL> ) , <EOL> ) <EOL> return True </s>
