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
60
59
exceptions_module = exceptions
61
service_types = ['compute']
61
service_types = [COMPUTE] = ['compute']
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)
68
computeshell = novashell.OpenStackComputeShell()
69
extensions = computeshell._discover_extensions(NOVACLIENT_VERSION)
68
if hasattr(nc, 'discover_extensions'):
69
extensions = nc.discover_extensions(NOVACLIENT_VERSION)
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
75
from novaclient import shell as novashell
76
computeshell = novashell.OpenStackComputeShell()
77
extensions = computeshell._discover_extensions(NOVACLIENT_VERSION)
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,
77
85
'extensions': extensions,
425
433
If that's the case, confirm the resize, if not raise an error.
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
439
while server.status in ('RESIZE', 'ACTIVE'):
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)
446
def check_rebuild(self, server, image_id):
457
def check_rebuild(self, server_id, image_id):
448
459
Verify that a rebuilding server is rebuilt.
449
460
Raise error if it ends up in an ERROR state.
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'):
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)
639
650
def validate_with_client(self, client, flavor):
640
651
client.client_plugin('nova').get_flavor_id(flavor)
654
class NetworkConstraint(constraints.BaseCustomConstraint):
656
expected_exceptions = (exception.NovaNetworkNotFound,
657
exception.PhysicalResourceNameAmbiguity)
659
def validate_with_client(self, client, network):
660
client.client_plugin('nova').get_nova_network_id(network)
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
672
class ServerDeleteProgress(object):
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