~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/engine/resources/nova_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-09-08 21:51:19 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20130908215119-7tcek6gn73275x5k
Tags: upstream-2013.2~b3
ImportĀ upstreamĀ versionĀ 2013.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
logger = logging.getLogger(__name__)
34
34
 
35
35
 
 
36
deferred_server_statuses = ['BUILD',
 
37
                            'HARD_REBOOT',
 
38
                            'PASSWORD',
 
39
                            'REBOOT',
 
40
                            'RESCUE',
 
41
                            'RESIZE',
 
42
                            'REVERT_RESIZE',
 
43
                            'SHUTOFF',
 
44
                            'SUSPENDED',
 
45
                            'VERIFY_RESIZE']
 
46
 
 
47
 
36
48
def get_image_id(nova_client, image_identifier):
37
49
    '''
38
50
    Return an id for the specified image name or identifier.
54
66
        try:
55
67
            image_list = nova_client.images.list()
56
68
        except clients.novaclient.exceptions.ClientException as ex:
57
 
            raise exception.ServerError(message=str(ex))
 
69
            raise exception.Error(
 
70
                message="Error retrieving image list from nova: %s" % str(ex))
58
71
        image_names = dict(
59
72
            (o.id, o.name)
60
73
            for o in image_list if o.name == image_identifier)
173
186
    mime_blob = MIMEMultipart(_subparts=subparts)
174
187
 
175
188
    return mime_blob.as_string()
 
189
 
 
190
 
 
191
def delete_server(server):
 
192
    '''
 
193
    Return a co-routine that deletes the server and waits for it to
 
194
    disappear from Nova.
 
195
    '''
 
196
    server.delete()
 
197
 
 
198
    while True:
 
199
        yield
 
200
 
 
201
        try:
 
202
            server.get()
 
203
        except clients.novaclient.exceptions.NotFound:
 
204
            break
 
205
 
 
206
 
 
207
def check_resize(server, flavor):
 
208
    """
 
209
    Verify that the server is properly resized. If that's the case, confirm
 
210
    the resize, if not raise an error.
 
211
    """
 
212
    yield
 
213
    server.get()
 
214
    while server.status == 'RESIZE':
 
215
        yield
 
216
        server.get()
 
217
    if server.status == 'VERIFY_RESIZE':
 
218
        server.confirm_resize()
 
219
    else:
 
220
        raise exception.Error(
 
221
            _("Resizing to '%(flavor)s' failed, status '%(status)s'") %
 
222
            dict(flavor=flavor, status=server.status))
 
223
 
 
224
 
 
225
def server_to_ipaddress(client, server):
 
226
    '''
 
227
    Return the server's IP address, fetching it from Nova.
 
228
    '''
 
229
    try:
 
230
        server = client.servers.get(server)
 
231
    except clients.novaclient.exceptions.NotFound as ex:
 
232
        logger.warn('Instance (%s) not found: %s' % (server, str(ex)))
 
233
    else:
 
234
        for n in server.networks:
 
235
            if len(server.networks[n]) > 0:
 
236
                return server.networks[n][0]