<s> import abc <EOL> from oslo_config import cfg <EOL> from six . moves . urllib import parse <EOL> from rally . cli import envutils <EOL> from rally . common . i18n import _ <EOL> from rally . common import logging <EOL> from rally . common import objects <EOL> from rally . common . plugin import plugin <EOL> from rally import consts <EOL> from rally import exceptions <EOL> CONF = cfg . CONF <EOL> OSCLIENTS_OPTS = [ <EOL> cfg . FloatOpt ( "<STR_LIT>" , default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> ] <EOL> CONF . register_opts ( OSCLIENTS_OPTS ) <EOL> _NAMESPACE = "<STR_LIT>" <EOL> def configure ( name , default_version = None , default_service_type = None , <EOL> supported_versions = None ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( cls ) : <EOL> cls = plugin . configure ( name = name , namespace = _NAMESPACE ) ( cls ) <EOL> cls . _meta_set ( "<STR_LIT>" , default_version ) <EOL> cls . _meta_set ( "<STR_LIT>" , default_service_type ) <EOL> cls . _meta_set ( "<STR_LIT>" , supported_versions or [ ] ) <EOL> return cls <EOL> return wrapper <EOL> class OSClient ( plugin . Plugin ) : <EOL> def __init__ ( self , credential , api_info , cache_obj ) : <EOL> self . credential = credential <EOL> self . api_info = api_info <EOL> self . cache = cache_obj <EOL> def choose_version ( self , version = None ) : <EOL> """<STR_LIT>""" <EOL> version = ( version <EOL> or self . api_info . get ( self . get_name ( ) , { } ) . get ( "<STR_LIT:version>" ) <EOL> or self . _meta_get ( "<STR_LIT>" ) ) <EOL> if version is not None : <EOL> version = str ( version ) <EOL> return version <EOL> @ classmethod <EOL> def get_supported_versions ( cls ) : <EOL> return cls . _meta_get ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def validate_version ( cls , version ) : <EOL> supported_versions = cls . get_supported_versions ( ) <EOL> if supported_versions : <EOL> if str ( version ) not in supported_versions : <EOL> raise exceptions . ValidationError ( _ ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) % { "<STR_LIT>" : version , <EOL> "<STR_LIT>" : supported_versions } ) <EOL> else : <EOL> raise exceptions . RallyException ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> try : <EOL> float ( version ) <EOL> except ValueError : <EOL> raise exceptions . ValidationError ( _ ( <EOL> "<STR_LIT>" ) % version ) <EOL> def choose_service_type ( self , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> return ( service_type <EOL> or self . api_info . get ( self . get_name ( ) , { } ) . get ( "<STR_LIT>" ) <EOL> or self . _meta_get ( "<STR_LIT>" ) ) <EOL> @ classmethod <EOL> def is_service_type_configurable ( cls ) : <EOL> """<STR_LIT>""" <EOL> if cls . _meta_get ( "<STR_LIT>" ) is None : <EOL> raise exceptions . RallyException ( _ ( <EOL> "<STR_LIT>" ) ) <EOL> def keystone ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> keystone = OSClient . get ( "<STR_LIT>" ) ( self . credential , self . api_info , <EOL> self . cache ) <EOL> return keystone ( * args , ** kwargs ) <EOL> def _get_session ( self , auth = None , endpoint = None ) : <EOL> from keystoneclient . auth import token_endpoint <EOL> from keystoneclient import session as ks_session <EOL> if auth is None : <EOL> endpoint = endpoint or self . _get_endpoint ( ) <EOL> kc = self . keystone ( ) <EOL> auth = token_endpoint . Token ( endpoint , kc . auth_token ) <EOL> return ks_session . Session ( <EOL> auth = auth , verify = not self . credential . insecure , <EOL> timeout = CONF . openstack_client_http_timeout ) <EOL> def _get_endpoint ( self , service_type = None ) : <EOL> kc = self . keystone ( ) <EOL> api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> return api_url <EOL> def _get_auth_info ( self , user_key = "<STR_LIT:username>" , <EOL> password_key = "<STR_LIT:password>" , <EOL> auth_url_key = "<STR_LIT>" , <EOL> project_name_key = "<STR_LIT>" , <EOL> domain_name_key = "<STR_LIT>" , <EOL> user_domain_name_key = "<STR_LIT>" , <EOL> project_domain_name_key = "<STR_LIT>" <EOL> ) : <EOL> kw = { <EOL> user_key : self . credential . username , <EOL> password_key : self . credential . password , <EOL> auth_url_key : self . credential . auth_url <EOL> } <EOL> if project_name_key : <EOL> kw . update ( { project_name_key : self . credential . tenant_name } ) <EOL> if "<STR_LIT>" not in self . credential . auth_url : <EOL> kw . update ( { <EOL> domain_name_key : self . credential . domain_name } ) <EOL> kw . update ( { <EOL> user_domain_name_key : self . credential . user_domain_name } ) <EOL> kw . update ( { <EOL> project_domain_name_key : self . credential . project_domain_name } ) <EOL> return kw <EOL> @ abc . abstractmethod <EOL> def create_client ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> key = "<STR_LIT>" . format ( self . get_name ( ) , <EOL> str ( args ) if args else "<STR_LIT>" , <EOL> str ( kwargs ) if kwargs else "<STR_LIT>" ) <EOL> if key not in self . cache : <EOL> self . cache [ key ] = self . create_client ( * args , ** kwargs ) <EOL> return self . cache [ key ] <EOL> @ classmethod <EOL> def get ( cls , name , namespace = _NAMESPACE ) : <EOL> return super ( OSClient , cls ) . get ( name , namespace ) <EOL> @ configure ( "<STR_LIT>" , supported_versions = ( "<STR_LIT:2>" , "<STR_LIT:3>" ) ) <EOL> class Keystone ( OSClient ) : <EOL> def keystone ( self , * args , ** kwargs ) : <EOL> raise exceptions . RallyException ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def _create_keystone_client ( self , args , version = None ) : <EOL> from keystoneclient . auth import identity <EOL> from keystoneclient import client <EOL> auth_arg_list = [ <EOL> "<STR_LIT:username>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:password>" , <EOL> ] <EOL> if "<STR_LIT>" not in args [ "<STR_LIT>" ] and version != "<STR_LIT:2>" : <EOL> auth_arg_list . extend ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> auth_args = { key : args . get ( key ) for key in auth_arg_list } <EOL> auth = identity . Password ( ** auth_args ) <EOL> session = self . _get_session ( auth = auth ) <EOL> args [ "<STR_LIT>" ] = session <EOL> auth_ref = auth . get_access ( session ) <EOL> ks = client . Client ( version = version , ** args ) <EOL> ks . auth_ref = auth_ref <EOL> return ks <EOL> def _remove_url_version ( self ) : <EOL> """<STR_LIT>""" <EOL> url = parse . urlparse ( self . credential . auth_url ) <EOL> parts = ( url . scheme , url . netloc , "<STR_LIT:/>" , url . params , url . query , <EOL> url . fragment ) <EOL> return parse . urlunparse ( parts ) <EOL> def create_client ( self , version = None ) : <EOL> """<STR_LIT>""" <EOL> version = self . choose_version ( version ) <EOL> new_kw = { <EOL> "<STR_LIT>" : CONF . openstack_client_http_timeout , <EOL> "<STR_LIT>" : self . credential . insecure , <EOL> "<STR_LIT>" : self . credential . cacert <EOL> } <EOL> kw = self . credential . to_dict ( ) <EOL> kw . update ( new_kw ) <EOL> if version is not None : <EOL> kw [ "<STR_LIT>" ] = self . _remove_url_version ( ) <EOL> return self . _create_keystone_client ( kw , version = version ) <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:2>" , default_service_type = "<STR_LIT>" ) <EOL> class Nova ( OSClient ) : <EOL> @ classmethod <EOL> def validate_version ( cls , version ) : <EOL> from novaclient import api_versions <EOL> from novaclient import exceptions as nova_exc <EOL> try : <EOL> api_versions . get_api_version ( version ) <EOL> except nova_exc . UnsupportedVersion : <EOL> raise exceptions . RallyException ( <EOL> "<STR_LIT>" % version ) <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from novaclient import client as nova <EOL> kc = self . keystone ( ) <EOL> compute_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = nova . Client ( self . choose_version ( version ) , <EOL> auth_token = kc . auth_token , <EOL> http_log_debug = logging . is_debug ( ) , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( password_key = "<STR_LIT>" ) ) <EOL> client . set_management_url ( compute_api_url ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT>" ] ) <EOL> class Neutron ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from neutronclient . neutron import client as neutron <EOL> kc = self . keystone ( ) <EOL> network_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = neutron . Client ( self . choose_version ( version ) , <EOL> token = kc . auth_token , <EOL> endpoint_url = network_api_url , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> ca_cert = self . credential . cacert , <EOL> ** self . _get_auth_info ( <EOL> project_name_key = "<STR_LIT>" ) <EOL> ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT:image>" , <EOL> supported_versions = [ "<STR_LIT:1>" , "<STR_LIT:2>" ] ) <EOL> class Glance ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> import glanceclient as glance <EOL> kc = self . keystone ( ) <EOL> image_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = glance . Client ( self . choose_version ( version ) , <EOL> endpoint = image_api_url , <EOL> token = kc . auth_token , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" ] ) <EOL> class Heat ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from heatclient import client as heat <EOL> kc = self . keystone ( ) <EOL> orchestration_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = heat . Client ( self . choose_version ( version ) , <EOL> endpoint = orchestration_api_url , <EOL> token = kc . auth_token , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( project_name_key = None ) ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:2>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" , "<STR_LIT:2>" ] ) <EOL> class Cinder ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from cinderclient import client as cinder <EOL> client = cinder . Client ( self . choose_version ( version ) , <EOL> http_log_debug = logging . is_debug ( ) , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( password_key = "<STR_LIT>" ) ) <EOL> kc = self . keystone ( ) <EOL> volume_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client . client . management_url = volume_api_url <EOL> client . client . auth_token = kc . auth_token <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" , "<STR_LIT:2>" ] ) <EOL> class Manila ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from manilaclient import client as manila <EOL> manila_client = manila . Client ( <EOL> self . choose_version ( version ) , <EOL> region_name = self . credential . region_name , <EOL> http_log_debug = logging . is_debug ( ) , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( password_key = "<STR_LIT>" , <EOL> project_name_key = "<STR_LIT>" ) ) <EOL> kc = self . keystone ( ) <EOL> manila_client . client . management_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> manila_client . client . auth_token = kc . auth_token <EOL> return manila_client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:2>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" , "<STR_LIT:2>" ] ) <EOL> class Ceilometer ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from ceilometerclient import client as ceilometer <EOL> kc = self . keystone ( ) <EOL> metering_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> auth_token = kc . auth_token <EOL> if not hasattr ( auth_token , "<STR_LIT>" ) : <EOL> auth_token = lambda : kc . auth_token <EOL> client = ceilometer . get_client ( <EOL> self . choose_version ( version ) , <EOL> os_endpoint = metering_api_url , <EOL> token = auth_token , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( project_name_key = "<STR_LIT>" ) ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" ] ) <EOL> class Ironic ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from ironicclient import client as ironic <EOL> kc = self . keystone ( ) <EOL> baremetal_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = ironic . get_client ( self . choose_version ( version ) , <EOL> os_auth_token = kc . auth_token , <EOL> ironic_url = baremetal_api_url , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT>" , supported_versions = [ "<STR_LIT:1.0>" , "<STR_LIT>" ] , <EOL> default_service_type = "<STR_LIT>" ) <EOL> class Sahara ( OSClient ) : <EOL> def choose_version ( self , version = None ) : <EOL> return float ( super ( Sahara , self ) . choose_version ( version ) ) <EOL> @ classmethod <EOL> def validate_version ( cls , version ) : <EOL> super ( Sahara , cls ) . validate_version ( float ( version ) ) <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from saharaclient import client as sahara <EOL> client = sahara . Client ( <EOL> self . choose_version ( version ) , <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> insecure = self . credential . insecure , <EOL> ** self . _get_auth_info ( password_key = "<STR_LIT>" , <EOL> project_name_key = "<STR_LIT>" ) ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" , "<STR_LIT>" ] ) <EOL> class Zaqar ( OSClient ) : <EOL> def choose_version ( self , version = None ) : <EOL> return float ( super ( Zaqar , self ) . choose_version ( version ) ) <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from zaqarclient . queues import client as zaqar <EOL> kc = self . keystone ( ) <EOL> messaging_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> conf = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : { <EOL> "<STR_LIT>" : self . credential . username , <EOL> "<STR_LIT>" : self . credential . password , <EOL> "<STR_LIT>" : self . credential . tenant_name , <EOL> "<STR_LIT>" : kc . auth_ref . get ( "<STR_LIT>" ) . get ( "<STR_LIT>" ) . get ( "<STR_LIT:id>" ) , <EOL> "<STR_LIT>" : self . credential . auth_url , <EOL> "<STR_LIT>" : self . credential . insecure , <EOL> } } } <EOL> client = zaqar . Client ( url = messaging_api_url , <EOL> version = self . choose_version ( version ) , <EOL> conf = conf ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , <EOL> default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" ] ) <EOL> class Murano ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from muranoclient import client as murano <EOL> kc = self . keystone ( ) <EOL> murano_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name <EOL> ) <EOL> client = murano . Client ( self . choose_version ( version ) , <EOL> endpoint = murano_url , <EOL> token = kc . auth_token ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" , "<STR_LIT:2>" ] ) <EOL> class Designate ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from designateclient import client <EOL> version = self . choose_version ( version ) <EOL> api_url = self . _get_endpoint ( service_type ) <EOL> api_url += "<STR_LIT>" % version <EOL> session = self . _get_session ( endpoint = api_url ) <EOL> return client . Client ( version , session = session ) <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1.0>" , supported_versions = [ "<STR_LIT:1.0>" ] ) <EOL> class Trove ( OSClient ) : <EOL> def create_client ( self , version = None ) : <EOL> """<STR_LIT>""" <EOL> from troveclient import client as trove <EOL> client = trove . Client ( self . choose_version ( version ) , <EOL> region_name = self . credential . region_name , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( password_key = "<STR_LIT>" ) <EOL> ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_service_type = "<STR_LIT>" ) <EOL> class Mistral ( OSClient ) : <EOL> def create_client ( self , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from mistralclient . api import client <EOL> kc = self . keystone ( ) <EOL> mistral_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = client . client ( <EOL> mistral_url = mistral_url , <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> auth_token = kc . auth_token ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_service_type = "<STR_LIT>" ) <EOL> class Swift ( OSClient ) : <EOL> def create_client ( self , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from swiftclient import client as swift <EOL> kc = self . keystone ( ) <EOL> object_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = swift . Connection ( retries = <NUM_LIT:1> , <EOL> preauthurl = object_api_url , <EOL> preauthtoken = kc . auth_token , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( <EOL> user_key = "<STR_LIT:user>" , <EOL> password_key = "<STR_LIT:key>" , <EOL> auth_url_key = "<STR_LIT>" , <EOL> project_name_key = "<STR_LIT>" ) <EOL> ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" ) <EOL> class EC2 ( OSClient ) : <EOL> def create_client ( self ) : <EOL> """<STR_LIT>""" <EOL> import boto <EOL> kc = self . keystone ( ) <EOL> if kc . version != "<STR_LIT>" : <EOL> raise exceptions . RallyException ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> ec2_credential = kc . ec2 . create ( user_id = kc . auth_user_id , <EOL> tenant_id = kc . auth_tenant_id ) <EOL> ec2_api_url = kc . service_catalog . url_for ( <EOL> service_type = consts . ServiceType . EC2 , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> client = boto . connect_ec2_endpoint ( <EOL> url = ec2_api_url , <EOL> aws_access_key_id = ec2_credential . access , <EOL> aws_secret_access_key = ec2_credential . secret , <EOL> is_secure = self . credential . insecure ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT>" , <EOL> default_service_type = "<STR_LIT>" , supported_versions = [ "<STR_LIT>" ] ) <EOL> class Monasca ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from monascaclient import client as monasca <EOL> kc = self . keystone ( ) <EOL> monitoring_api_url = kc . service_catalog . url_for ( <EOL> service_type = self . choose_service_type ( service_type ) , <EOL> endpoint_type = self . credential . endpoint_type , <EOL> region_name = self . credential . region_name ) <EOL> auth_token = kc . auth_token <EOL> client = monasca . Client ( <EOL> self . choose_version ( version ) , <EOL> monitoring_api_url , <EOL> token = auth_token , <EOL> timeout = CONF . openstack_client_http_timeout , <EOL> insecure = self . credential . insecure , <EOL> cacert = self . credential . cacert , <EOL> ** self . _get_auth_info ( project_name_key = "<STR_LIT>" ) ) <EOL> return client <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT>" ) <EOL> class Cue ( OSClient ) : <EOL> def create_client ( self , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from cueclient . v1 import client as cue <EOL> version = self . choose_version ( ) <EOL> api_url = self . _get_endpoint ( service_type ) <EOL> api_url += "<STR_LIT>" % version <EOL> session = self . _get_session ( endpoint = api_url ) <EOL> endpoint_type = self . credential . endpoint_type , <EOL> return cue . Client ( session = session , interface = endpoint_type [ <NUM_LIT:0> ] ) <EOL> @ configure ( "<STR_LIT>" , default_version = "<STR_LIT:1>" , default_service_type = "<STR_LIT>" , <EOL> supported_versions = [ "<STR_LIT:1>" ] ) <EOL> class Senlin ( OSClient ) : <EOL> def create_client ( self , version = None , service_type = None ) : <EOL> """<STR_LIT>""" <EOL> from senlinclient import client as senlin <EOL> return senlin . Client ( <EOL> self . choose_version ( version ) , <EOL> ** self . _get_auth_info ( project_name_key = "<STR_LIT>" ) ) <EOL> class Clients ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , credential , api_info = None ) : <EOL> self . credential = credential <EOL> self . api_info = api_info or { } <EOL> self . cache = { } <EOL> def __getattr__ ( self , client_name ) : <EOL> """<STR_LIT>""" <EOL> return OSClient . get ( client_name ) ( self . credential , self . api_info , <EOL> self . cache ) <EOL> @ classmethod <EOL> def create_from_env ( cls ) : <EOL> creds = envutils . get_creds_from_env_vars ( ) <EOL> return cls ( <EOL> objects . Credential ( <EOL> creds [ "<STR_LIT>" ] , <EOL> creds [ "<STR_LIT>" ] [ "<STR_LIT:username>" ] , <EOL> creds [ "<STR_LIT>" ] [ "<STR_LIT:password>" ] , <EOL> creds [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <EOL> endpoint = creds [ "<STR_LIT>" ] , <EOL> region_name = creds [ "<STR_LIT>" ] , <EOL> https_cacert = creds [ "<STR_LIT>" ] , <EOL> https_insecure = creds [ "<STR_LIT>" ] <EOL> ) ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . cache = { } <EOL> def verified_keystone ( self ) : <EOL> """<STR_LIT>""" <EOL> from keystoneclient import exceptions as keystone_exceptions <EOL> try : <EOL> client = self . keystone ( ) <EOL> if "<STR_LIT>" not in [ role . lower ( ) for role in <EOL> client . auth_ref . role_names ] : <EOL> raise exceptions . InvalidAdminException ( <EOL> username = self . credential . username ) <EOL> except keystone_exceptions . Unauthorized : <EOL> raise exceptions . InvalidEndpointsException ( ) <EOL> except keystone_exceptions . AuthorizationFailure : <EOL> raise exceptions . HostUnreachableException ( <EOL> url = self . credential . auth_url ) <EOL> return client <EOL> def services ( self ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT>" not in self . cache : <EOL> services_data = { } <EOL> ks = self . keystone ( ) <EOL> available_services = ks . service_catalog . get_endpoints ( ) <EOL> for stype in available_services . keys ( ) : <EOL> if stype in consts . ServiceType : <EOL> services_data [ stype ] = consts . ServiceType [ stype ] <EOL> else : <EOL> services_data [ stype ] = "<STR_LIT>" <EOL> self . cache [ "<STR_LIT>" ] = services_data <EOL> return self . cache [ "<STR_LIT>" ] <EOL> @ classmethod <EOL> @ logging . log_deprecated ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> def register ( cls , client_name ) : <EOL> """<STR_LIT>""" <EOL> def wrap ( client_func ) : <EOL> try : <EOL> OSClient . get ( client_name ) <EOL> except exceptions . PluginNotFound : <EOL> pass <EOL> else : <EOL> raise ValueError ( <EOL> _ ( "<STR_LIT>" ) <EOL> % client_name ) <EOL> @ configure ( client_name ) <EOL> class NewClient ( OSClient ) : <EOL> create_client = client_func <EOL> return NewClient <EOL> return wrap </s>
