<s> from cinderclient import client as cinderclient <EOL> from glanceclient import client as glanceclient <EOL> from keystoneclient . auth . identity . generic import password as keystone_auth <EOL> from keystoneclient import client as keystoneclient <EOL> from keystoneclient import session as keystone_session <EOL> from neutronclient . v2_0 import client as neutronclient <EOL> from novaclient import api_versions as nova_api_versions <EOL> from novaclient import client as novaclient <EOL> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> import oslo_messaging as messaging <EOL> from ec2api . i18n import _ , _LI , _LW <EOL> logger = logging . getLogger ( __name__ ) <EOL> ec2_opts = [ <EOL> cfg . BoolOpt ( '<STR_LIT>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" ) , <EOL> secret = True ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" ) ) , <EOL> ] <EOL> CONF = cfg . CONF <EOL> CONF . register_opts ( ec2_opts ) <EOL> REQUIRED_NOVA_API_VERSION = '<STR_LIT>' <EOL> REQUIRED_NOVA_API_VERSION_ID = '<STR_LIT>' % REQUIRED_NOVA_API_VERSION <EOL> LEGACY_NOVA_API_VERSION = '<STR_LIT:2>' <EOL> REQUIRED_NOVA_API_MICROVERSION = '<STR_LIT>' <EOL> _nova_api_version = None <EOL> def nova ( context ) : <EOL> global _nova_api_version <EOL> if not _nova_api_version : <EOL> _nova_api_version = _get_nova_api_version ( context ) <EOL> clnt = novaclient . Client ( _nova_api_version , <EOL> session = context . session , <EOL> service_type = CONF . nova_service_type ) <EOL> if not hasattr ( clnt . client , '<STR_LIT>' ) : <EOL> setattr ( clnt . client , '<STR_LIT>' , None ) <EOL> return clnt <EOL> def neutron ( context ) : <EOL> return neutronclient . Client ( session = context . session , <EOL> service_type = '<STR_LIT>' ) <EOL> def glance ( context ) : <EOL> return glanceclient . Client ( '<STR_LIT:1>' , service_type = '<STR_LIT:image>' , <EOL> session = context . session ) <EOL> def cinder ( context ) : <EOL> url = context . session . get_endpoint ( service_type = CONF . cinder_service_type ) <EOL> version = cinderclient . get_volume_api_from_url ( url ) <EOL> return cinderclient . Client ( version , session = context . session , <EOL> service_type = CONF . cinder_service_type ) <EOL> def keystone ( context ) : <EOL> auth_url = context . session . get_endpoint ( service_type = '<STR_LIT>' ) <EOL> return keystoneclient . Client ( auth_url = auth_url , <EOL> session = context . session ) <EOL> def nova_cert ( context ) : <EOL> _cert_api = _rpcapi_CertAPI ( context ) <EOL> return _cert_api <EOL> def _get_nova_api_version ( context ) : <EOL> client = novaclient . Client ( REQUIRED_NOVA_API_VERSION , <EOL> session = context . session , <EOL> service_type = CONF . nova_service_type ) <EOL> required = nova_api_versions . APIVersion ( REQUIRED_NOVA_API_MICROVERSION ) <EOL> current = client . versions . get_current ( ) <EOL> if not current : <EOL> logger . warning ( <EOL> _LW ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> { '<STR_LIT:url>' : client . client . get_endpoint ( ) , <EOL> '<STR_LIT>' : CONF . nova_service_type , <EOL> '<STR_LIT>' : REQUIRED_NOVA_API_MICROVERSION } ) <EOL> return REQUIRED_NOVA_API_MICROVERSION <EOL> if current . id != REQUIRED_NOVA_API_VERSION_ID : <EOL> logger . warning ( <EOL> _LW ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> CONF . nova_service_type ) <EOL> return LEGACY_NOVA_API_VERSION <EOL> if ( nova_api_versions . APIVersion ( current . version ) < required ) : <EOL> logger . warning ( <EOL> _LW ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> { '<STR_LIT>' : current . version , <EOL> '<STR_LIT>' : REQUIRED_NOVA_API_MICROVERSION } ) <EOL> return current . version <EOL> logger . info ( _LI ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> { '<STR_LIT>' : current . version , <EOL> '<STR_LIT>' : ( <EOL> REQUIRED_NOVA_API_MICROVERSION ) } ) <EOL> return REQUIRED_NOVA_API_MICROVERSION <EOL> class _rpcapi_CertAPI ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , context ) : <EOL> super ( _rpcapi_CertAPI , self ) . __init__ ( ) <EOL> target = messaging . Target ( topic = CONF . cert_topic , version = '<STR_LIT>' ) <EOL> self . client = _rpc_get_client ( target ) <EOL> self . context = context <EOL> def decrypt_text ( self , text ) : <EOL> cctxt = self . client . prepare ( ) <EOL> return cctxt . call ( self . context , '<STR_LIT>' , <EOL> project_id = self . context . project_id , <EOL> text = text ) <EOL> _rpc_TRANSPORT = None <EOL> def _rpc_init ( conf ) : <EOL> global _rpc_TRANSPORT <EOL> messaging . set_transport_defaults ( '<STR_LIT>' ) <EOL> _rpc_TRANSPORT = messaging . get_transport ( conf ) <EOL> def _rpc_get_client ( target ) : <EOL> if not _rpc_TRANSPORT : <EOL> _rpc_init ( CONF ) <EOL> assert _rpc_TRANSPORT is not None <EOL> serializer = _rpc_RequestContextSerializer ( ) <EOL> return messaging . RPCClient ( _rpc_TRANSPORT , <EOL> target , <EOL> serializer = serializer ) <EOL> class _rpc_RequestContextSerializer ( messaging . NoOpSerializer ) : <EOL> def serialize_context ( self , context ) : <EOL> return context . to_dict ( ) <EOL> _admin_session = None <EOL> def get_os_admin_session ( ) : <EOL> """<STR_LIT>""" <EOL> global _admin_session <EOL> if not _admin_session : <EOL> auth = keystone_auth . Password ( <EOL> username = CONF . admin_user , <EOL> password = CONF . admin_password , <EOL> project_name = CONF . admin_tenant_name , <EOL> tenant_name = CONF . admin_tenant_name , <EOL> auth_url = CONF . keystone_url , <EOL> ) <EOL> params = { '<STR_LIT>' : auth } <EOL> update_request_params_with_ssl ( params ) <EOL> _admin_session = keystone_session . Session ( ** params ) <EOL> return _admin_session <EOL> def update_request_params_with_ssl ( params ) : <EOL> verify = CONF . ssl_ca_file or not CONF . ssl_insecure <EOL> if verify is not True : <EOL> params [ '<STR_LIT>' ] = verify </s>
