Example #1
0
 def connection(self):
     if not self._connection:
         cacert = self.client_config.get('cacert')
         insecure = self.client_config.get(
             'insecure', False)
         if cacert or insecure:
             if cacert:
                 os.environ["REQUESTS_CA_BUNDLE"] = cacert
             auth_dict = dict(
                 auth_url=self.client_config.get('auth_url'),
                 username=self.client_config.get('username'),
                 password=self.client_config.get('api_key'),
                 project_name=self.client_config.get('project_name'),
                 user_domain_name=self.client_config.get(
                     'user_domain_name'),
                 project_domain_name=self.client_config.get(
                     'project_domain_name'),
             )
             auth = v3.Password(**auth_dict)
             sess = session.Session(
                 auth=auth, verify=cacert if not insecure else False)
             self._connection = client_v1.Client(
                 session=sess,
                 insecure=insecure)
         else:
             self._connection = client.client(**self.client_config)
     return self._connection
def client(dcmanager_url=None, username=None, api_key=None,
           project_name=None, auth_url=None, project_id=None,
           endpoint_type='publicURL', service_type='dcmanager',
           auth_token=None, user_id=None, cacert=None, insecure=False,
           profile=None, auth_type='keystone', client_id=None,
           client_secret=None, session=None, **kwargs):
    if dcmanager_url and not isinstance(dcmanager_url, six.string_types):
        raise RuntimeError('DC Manager url should be a string.')

    return client_v1.Client(
        dcmanager_url=dcmanager_url,
        username=username,
        api_key=api_key,
        project_name=project_name,
        auth_url=auth_url,
        project_id=project_id,
        endpoint_type=endpoint_type,
        service_type=service_type,
        auth_token=auth_token,
        user_id=user_id,
        cacert=cacert,
        insecure=insecure,
        profile=profile,
        auth_type=auth_type,
        client_id=client_id,
        client_secret=client_secret,
        session=session,
        **kwargs
    )
Example #3
0
def dcmanagerclient(request):
    endpoint = base.url_for(request, 'dcmanager', 'adminURL')
    c = client.Client(project_id=request.user.project_id,
                      user_id=request.user.id,
                      auth_token=request.user.token.id,
                      dcmanager_url=endpoint)
    return c