~openstack-charmers/charms/trusty/quantum-gateway/old-1410

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-07-28 11:33:12 UTC
  • Revision ID: james.page@ubuntu.com-20140728113312-nzew0x1rn4ogh1g9
Resync helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
            image = glance.images.create(name=image_name, is_public=True,
178
178
                                         disk_format='qcow2',
179
179
                                         container_format='bare', data=f)
180
 
        count = 1
181
 
        status = image.status
182
 
        while status != 'active' and count < 10:
183
 
            time.sleep(3)
184
 
            image = glance.images.get(image.id)
185
 
            status = image.status
186
 
            self.log.debug('image status: {}'.format(status))
187
 
            count += 1
188
 
 
189
 
        if status != 'active':
190
 
            self.log.error('image creation timed out')
191
 
            return None
192
 
 
193
180
        return image
194
181
 
195
182
    def delete_image(self, glance, image):
196
183
        """Delete the specified image."""
197
 
        num_before = len(list(glance.images.list()))
198
184
        glance.images.delete(image)
199
185
 
200
 
        count = 1
201
 
        num_after = len(list(glance.images.list()))
202
 
        while num_after != (num_before - 1) and count < 10:
203
 
            time.sleep(3)
204
 
            num_after = len(list(glance.images.list()))
205
 
            self.log.debug('number of images: {}'.format(num_after))
206
 
            count += 1
207
 
 
208
 
        if num_after != (num_before - 1):
209
 
            self.log.error('image deletion timed out')
210
 
            return False
211
 
 
212
 
        return True
213
 
 
214
186
    def create_instance(self, nova, image_name, instance_name, flavor):
215
187
        """Create the specified instance."""
216
188
        image = nova.images.find(name=image_name)
227
199
            self.log.debug('instance status: {}'.format(status))
228
200
            count += 1
229
201
 
230
 
        if status != 'ACTIVE':
231
 
            self.log.error('instance creation timed out')
 
202
        if status == 'BUILD':
232
203
            return None
233
204
 
234
205
        return instance
235
206
 
236
207
    def delete_instance(self, nova, instance):
237
208
        """Delete the specified instance."""
238
 
        num_before = len(list(nova.servers.list()))
239
209
        nova.servers.delete(instance)
240
 
 
241
 
        count = 1
242
 
        num_after = len(list(nova.servers.list()))
243
 
        while num_after != (num_before - 1) and count < 10:
244
 
            time.sleep(3)
245
 
            num_after = len(list(nova.servers.list()))
246
 
            self.log.debug('number of instances: {}'.format(num_after))
247
 
            count += 1
248
 
 
249
 
        if num_after != (num_before - 1):
250
 
            self.log.error('instance deletion timed out')
251
 
            return False
252
 
 
253
 
        return True