~ubuntu-branches/ubuntu/wily/heat/wily

« back to all changes in this revision

Viewing changes to heat/engine/clients/os/nova.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant
  • Date: 2015-08-19 08:11:50 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20150819081150-m969fd35xn8bdmfu
Tags: 1:5.0.0~b2-0ubuntu1
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/p/fix-requirements.patch: Dropped. No longer needed.
* d/p/fixup-assert-regex.patch: Rebased.
* d/rules: Remove .eggs directory in override_dh_auto_clean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from novaclient import client as nc
24
24
from novaclient import exceptions
25
 
from novaclient import shell as novashell
26
25
from oslo_config import cfg
27
26
from oslo_serialization import jsonutils
28
27
from oslo_utils import uuidutils
58
57
                                'VERIFY_RESIZE']
59
58
 
60
59
    exceptions_module = exceptions
61
 
    service_types = ['compute']
 
60
 
 
61
    service_types = [COMPUTE] = ['compute']
62
62
 
63
63
    def _create(self):
64
64
        endpoint_type = self._get_client_option('nova', 'endpoint_type')
65
 
        management_url = self.url_for(service_type=self.service_types[0],
 
65
        management_url = self.url_for(service_type=self.COMPUTE,
66
66
                                      endpoint_type=endpoint_type)
67
67
 
68
 
        computeshell = novashell.OpenStackComputeShell()
69
 
        extensions = computeshell._discover_extensions(NOVACLIENT_VERSION)
 
68
        if hasattr(nc, 'discover_extensions'):
 
69
            extensions = nc.discover_extensions(NOVACLIENT_VERSION)
 
70
        else:
 
71
            # TODO(lyj): The else condition is for backward compatibility,
 
72
            #            once novaclient bump to a newer version with
 
73
            #            discover_extensions exists, this should be safely
 
74
            #            removed.
 
75
            from novaclient import shell as novashell
 
76
            computeshell = novashell.OpenStackComputeShell()
 
77
            extensions = computeshell._discover_extensions(NOVACLIENT_VERSION)
70
78
 
71
79
        args = {
72
80
            'project_id': self.context.tenant,
73
81
            'auth_url': self.context.auth_url,
74
 
            'service_type': self.service_types[0],
 
82
            'service_type': self.COMPUTE,
75
83
            'username': None,
76
84
            'api_key': None,
77
85
            'extensions': extensions,
425
433
        If that's the case, confirm the resize, if not raise an error.
426
434
        """
427
435
        self.refresh_server(server)
428
 
        while server.status == 'RESIZE':
 
436
        # resize operation is asynchronous so the server resize may not start
 
437
        # when checking server status (the server may stay ACTIVE instead
 
438
        # of RESIZE).
 
439
        while server.status in ('RESIZE', 'ACTIVE'):
429
440
            yield
430
441
            self.refresh_server(server)
431
442
        if server.status == 'VERIFY_RESIZE':
441
452
        """Rebuild the server and call check_rebuild to verify."""
442
453
        server.rebuild(image_id, password=password,
443
454
                       preserve_ephemeral=preserve_ephemeral)
444
 
        yield self.check_rebuild(server, image_id)
 
455
        yield self.check_rebuild(server.id, image_id)
445
456
 
446
 
    def check_rebuild(self, server, image_id):
 
457
    def check_rebuild(self, server_id, image_id):
447
458
        """
448
459
        Verify that a rebuilding server is rebuilt.
449
460
        Raise error if it ends up in an ERROR state.
450
461
        """
451
 
        self.refresh_server(server)
452
 
        while server.status == 'REBUILD':
 
462
        server = self.fetch_server(server_id)
 
463
        while (server is None or server.status == 'REBUILD'):
453
464
            yield
454
 
            self.refresh_server(server)
 
465
            server = self.fetch_server(server_id)
455
466
        if server.status == 'ERROR':
456
467
            raise exception.Error(
457
468
                _("Rebuilding server failed, status '%s'") % server.status)
638
649
 
639
650
    def validate_with_client(self, client, flavor):
640
651
        client.client_plugin('nova').get_flavor_id(flavor)
 
652
 
 
653
 
 
654
class NetworkConstraint(constraints.BaseCustomConstraint):
 
655
 
 
656
    expected_exceptions = (exception.NovaNetworkNotFound,
 
657
                           exception.PhysicalResourceNameAmbiguity)
 
658
 
 
659
    def validate_with_client(self, client, network):
 
660
        client.client_plugin('nova').get_nova_network_id(network)
 
661
 
 
662
 
 
663
# NOTE(pas-ha): these Server*Progress classes are simple key-value storages
 
664
# meant to be passed between handle_* and check_*_complete,
 
665
# being mutated during subsequent check_*_complete calls.
 
666
class ServerCreateProgress(object):
 
667
    def __init__(self, server_id, complete=False):
 
668
        self.complete = complete
 
669
        self.server_id = server_id
 
670
 
 
671
 
 
672
class ServerDeleteProgress(object):
 
673
 
 
674
    def __init__(self, server_id, image_id=None, image_complete=True):
 
675
        self.server_id = server_id
 
676
        self.image_id = image_id
 
677
        self.image_complete = image_complete