~openstack-charmers-next/charms/xenial/glance/trunk

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/openstack/amulet/utils.py

  • Committer: Alex Kavanagh
  • Date: 2016-03-18 10:18:56 UTC
  • Revision ID: alex@ajkavanagh.co.uk-20160318101856-6h157du6i4j4rvuc
Enhanced pause and resume for maintenance mode

Adds improved pause and resume unit to the charm such tha the
charm stays paused during maintenance operations.
Sync latest version of charm-helpers for maintenance mode.

Change-Id: I6e793744709b65c89afb6f0fc460f9d96755bf82

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import glanceclient.v1.client as glance_client
28
28
import heatclient.v1.client as heat_client
29
29
import keystoneclient.v2_0 as keystone_client
30
 
import novaclient.v1_1.client as nova_client
 
30
from keystoneclient.auth.identity import v3 as keystone_id_v3
 
31
from keystoneclient import session as keystone_session
 
32
from keystoneclient.v3 import client as keystone_client_v3
 
33
 
 
34
import novaclient.client as nova_client
31
35
import pika
32
36
import swiftclient
33
37
 
38
42
DEBUG = logging.DEBUG
39
43
ERROR = logging.ERROR
40
44
 
 
45
NOVA_CLIENT_VERSION = "2"
 
46
 
41
47
 
42
48
class OpenStackAmuletUtils(AmuletUtils):
43
49
    """OpenStack amulet utilities.
139
145
                return "role {} does not exist".format(e['name'])
140
146
        return ret
141
147
 
142
 
    def validate_user_data(self, expected, actual):
 
148
    def validate_user_data(self, expected, actual, api_version=None):
143
149
        """Validate user data.
144
150
 
145
151
           Validate a list of actual user data vs a list of expected user
150
156
        for e in expected:
151
157
            found = False
152
158
            for act in actual:
153
 
                a = {'enabled': act.enabled, 'name': act.name,
154
 
                     'email': act.email, 'tenantId': act.tenantId,
155
 
                     'id': act.id}
156
 
                if e['name'] == a['name']:
 
159
                if e['name'] == act.name:
 
160
                    a = {'enabled': act.enabled, 'name': act.name,
 
161
                         'email': act.email, 'id': act.id}
 
162
                    if api_version == 3:
 
163
                        a['default_project_id'] = getattr(act,
 
164
                                                          'default_project_id',
 
165
                                                          'none')
 
166
                    else:
 
167
                        a['tenantId'] = act.tenantId
157
168
                    found = True
158
169
                    ret = self._validate_dict_data(e, a)
159
170
                    if ret:
188
199
        return cinder_client.Client(username, password, tenant, ept)
189
200
 
190
201
    def authenticate_keystone_admin(self, keystone_sentry, user, password,
191
 
                                    tenant):
 
202
                                    tenant=None, api_version=None,
 
203
                                    keystone_ip=None):
192
204
        """Authenticates admin user with the keystone admin endpoint."""
193
205
        self.log.debug('Authenticating keystone admin...')
194
206
        unit = keystone_sentry
195
 
        service_ip = unit.relation('shared-db',
196
 
                                   'mysql:shared-db')['private-address']
197
 
        ep = "http://{}:35357/v2.0".format(service_ip.strip().decode('utf-8'))
198
 
        return keystone_client.Client(username=user, password=password,
199
 
                                      tenant_name=tenant, auth_url=ep)
 
207
        if not keystone_ip:
 
208
            keystone_ip = unit.relation('shared-db',
 
209
                                        'mysql:shared-db')['private-address']
 
210
        base_ep = "http://{}:35357".format(keystone_ip.strip().decode('utf-8'))
 
211
        if not api_version or api_version == 2:
 
212
            ep = base_ep + "/v2.0"
 
213
            return keystone_client.Client(username=user, password=password,
 
214
                                          tenant_name=tenant, auth_url=ep)
 
215
        else:
 
216
            ep = base_ep + "/v3"
 
217
            auth = keystone_id_v3.Password(
 
218
                user_domain_name='admin_domain',
 
219
                username=user,
 
220
                password=password,
 
221
                domain_name='admin_domain',
 
222
                auth_url=ep,
 
223
            )
 
224
            sess = keystone_session.Session(auth=auth)
 
225
            return keystone_client_v3.Client(session=sess)
200
226
 
201
227
    def authenticate_keystone_user(self, keystone, user, password, tenant):
202
228
        """Authenticates a regular user with the keystone public endpoint."""
225
251
        self.log.debug('Authenticating nova user ({})...'.format(user))
226
252
        ep = keystone.service_catalog.url_for(service_type='identity',
227
253
                                              endpoint_type='publicURL')
228
 
        return nova_client.Client(username=user, api_key=password,
 
254
        return nova_client.Client(NOVA_CLIENT_VERSION,
 
255
                                  username=user, api_key=password,
229
256
                                  project_id=tenant, auth_url=ep)
230
257
 
231
258
    def authenticate_swift_user(self, keystone, user, password, tenant):