~ajkavanagh/openstack-mojo-specs/fix-os-project-id-nova-creds

« back to all changes in this revision

Viewing changes to helper/utils/mojo_os_utils.py

  • Committer: Alex Kavanagh
  • Date: 2017-09-06 15:07:39 UTC
  • Revision ID: alex.kavanagh@canonical.com-20170906150739-ede5gvcw10bw2pbg
Fix OS_PROJECT_ID polution from env to overcloud nova creds
Also some fixes for keystone client and service_catalog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# Openstack Client helpers
29
29
def get_nova_creds(cloud_creds):
30
30
    auth = get_ks_creds(cloud_creds)
31
 
    if os.environ.get('OS_PROJECT_ID'):
32
 
        auth['project_id'] = os.environ.get('OS_PROJECT_ID')
 
31
    if cloud_creds.get('OS_PROJECT_ID'):
 
32
        auth['project_id'] = cloud_creds.get('OS_PROJECT_ID')
33
33
    return auth
34
34
 
35
35
 
111
111
def get_keystone_client(novarc_creds, insecure=True):
112
112
    keystone_creds = get_ks_creds(novarc_creds)
113
113
    if novarc_creds.get('API_VERSION', 2) == 2:
114
 
        sess = v2.Password(**keystone_creds)
115
 
        return keystoneclient_v2.Client(session=sess)
 
114
        auth = v2.Password(**keystone_creds)
 
115
        sess = session.Session(auth=auth, verify=True)
 
116
        client = keystoneclient_v2.Client(session=sess)
116
117
    else:
117
 
        sess = v3.Password(**keystone_creds)
118
 
        return keystoneclient_v3.Client(session=sess)
 
118
        auth = v3.Password(**keystone_creds)
 
119
        sess = get_keystone_session(novarc_creds, insecure)
 
120
        client = keystoneclient_v3.Client(session=sess)
 
121
    # This populates the client.service_catalog
 
122
    client.auth_ref = auth.get_access(sess)
 
123
    return client
119
124
 
120
125
 
121
126
def get_swift_client(novarc_creds, insecure=True):
136
141
    if novarc_creds.get('API_VERSION', 2) == 2:
137
142
        kc = get_keystone_client(novarc_creds)
138
143
        glance_ep_url = kc.service_catalog.url_for(service_type='image',
139
 
                                                   endpoint_type='publicURL')
 
144
                                                   interface='publicURL')
140
145
    else:
141
146
        keystone_creds = get_ks_creds(novarc_creds, scope='PROJECT')
142
147
        kc = keystoneclient_v3.Client(**keystone_creds)