Skip to content

Commit d732ee3

Browse files
committed
api: extend evacuate instance to support target state
Start to v2.95 any evacuated instances will be stopped a destination Implements: bp/allowing-target-state-for-evacuate Signed-off-by: Sahid Orentino Ferdjaoui <[email protected]> Change-Id: I141b6f057cc4eb9c541c2bc6eddae27270ede08d
1 parent 8c2e765 commit d732ee3

27 files changed

+252
-27
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"evacuate": {
3+
"targetState": "stopped"
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"evacuate": {
3+
"host": "testHost",
4+
"targetState": "stopped"
5+
}
6+
}

doc/api_samples/versions/v21-version-get-resp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"status": "CURRENT",
22-
"version": "2.94",
22+
"version": "2.95",
2323
"min_version": "2.1",
2424
"updated": "2013-07-23T11:33:21Z"
2525
}

doc/api_samples/versions/versions-get-resp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"status": "CURRENT",
25-
"version": "2.94",
25+
"version": "2.95",
2626
"min_version": "2.1",
2727
"updated": "2013-07-23T11:33:21Z"
2828
}

nova/api/openstack/api_version_request.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
in keypair name.
255255
* 2.93 - Add support for volume backed server rebuild.
256256
* 2.94 - Allow FQDN in server hostname.
257+
* 2.95 - Evacuate will now stop instance at destination.
257258
"""
258259

259260
# The minimum and maximum versions of the API supported
@@ -262,7 +263,7 @@
262263
# Note(cyeoh): This only applies for the v2.1 API once microversions
263264
# support is fully merged. It does not affect the V2 API.
264265
_MIN_API_VERSION = '2.1'
265-
_MAX_API_VERSION = '2.94'
266+
_MAX_API_VERSION = '2.95'
266267
DEFAULT_API_VERSION = _MIN_API_VERSION
267268

268269
# Almost all proxy APIs which are related to network, images and baremetal

nova/api/openstack/compute/evacuate.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323
from nova.api.openstack import wsgi
2424
from nova.api import validation
2525
from nova.compute import api as compute
26+
from nova.compute import vm_states
2627
import nova.conf
2728
from nova import exception
2829
from nova.i18n import _
30+
from nova import objects
2931
from nova.policies import evacuate as evac_policies
3032
from nova import utils
3133

3234
CONF = nova.conf.CONF
3335

3436
LOG = logging.getLogger(__name__)
3537

38+
MIN_VER_NOVA_COMPUTE_EVACUATE_STOPPED = 62
39+
3640

3741
class EvacuateController(wsgi.Controller):
3842
def __init__(self):
@@ -77,7 +81,8 @@ def _get_password_v214(self, req, evacuate_body):
7781
@validation.schema(evacuate.evacuate, "2.0", "2.13")
7882
@validation.schema(evacuate.evacuate_v214, "2.14", "2.28")
7983
@validation.schema(evacuate.evacuate_v2_29, "2.29", "2.67")
80-
@validation.schema(evacuate.evacuate_v2_68, "2.68")
84+
@validation.schema(evacuate.evacuate_v2_68, "2.68", "2.94")
85+
@validation.schema(evacuate.evacuate_v2_95, "2.95")
8186
def _evacuate(self, req, id, body):
8287
"""Permit admins to evacuate a server from a failed host
8388
to a new one.
@@ -92,6 +97,19 @@ def _evacuate(self, req, id, body):
9297
host = evacuate_body.get("host")
9398
force = None
9499

100+
target_state = None
101+
if api_version_request.is_supported(req, min_version='2.95'):
102+
min_ver = objects.service.get_minimum_version_all_cells(
103+
context, ['nova-compute'])
104+
if min_ver < MIN_VER_NOVA_COMPUTE_EVACUATE_STOPPED:
105+
raise exception.NotSupportedComputeForEvacuateV295(
106+
{'currently': min_ver,
107+
'expected': MIN_VER_NOVA_COMPUTE_EVACUATE_STOPPED})
108+
# Starts to 2.95 any evacuated instances will be stopped at
109+
# destination. Previously an active or stopped instance would have
110+
# kept its state.
111+
target_state = vm_states.STOPPED
112+
95113
on_shared_storage = self._get_on_shared_storage(req, evacuate_body)
96114

97115
if api_version_request.is_supported(req, min_version='2.29'):
@@ -120,7 +138,8 @@ def _evacuate(self, req, id, body):
120138

121139
try:
122140
self.compute_api.evacuate(context, instance, host,
123-
on_shared_storage, password, force)
141+
on_shared_storage, password, force,
142+
target_state)
124143
except exception.InstanceInvalidState as state_error:
125144
common.raise_http_conflict_for_instance_invalid_state(state_error,
126145
'evacuate', id)
@@ -130,6 +149,8 @@ def _evacuate(self, req, id, body):
130149
exception.ExtendedResourceRequestOldCompute,
131150
) as e:
132151
raise exc.HTTPBadRequest(explanation=e.format_message())
152+
except exception.UnsupportedRPCVersion as e:
153+
raise exc.HTTPConflict(explanation=e.format_message())
133154

134155
if (not api_version_request.is_supported(req, min_version='2.14') and
135156
CONF.api.enable_instance_password):

nova/api/openstack/compute/rest_api_version_history.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,3 +1237,11 @@ The ``hostname`` parameter to the ``POST /servers`` (create server), ``PUT
12371237
/servers/{id}`` (update server) and ``POST /servers/{server_id}/action
12381238
(rebuild)`` (rebuild server) APIs is now allowed to be a Fully Qualified Domain
12391239
Name (FQDN).
1240+
1241+
1242+
2.95
1243+
---------------------
1244+
1245+
Any evacuated instances will be now stopped at destination. This
1246+
requires minimun compute version 27.0.0 (antelope 2023.1). Operators
1247+
can still use previous microversion for older behavior.

nova/api/openstack/compute/schemas/evacuate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@
4646
# v2.68 removes the 'force' parameter added in v2.29, meaning it is identical
4747
# to v2.14
4848
evacuate_v2_68 = copy.deepcopy(evacuate_v214)
49+
50+
# v2.95 keeps the same schema, evacuating an instance will now result its state
51+
# to be stopped at destination.
52+
evacuate_v2_95 = copy.deepcopy(evacuate_v2_68)

nova/exception.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,3 +2510,10 @@ class ReimageException(NovaException):
25102510

25112511
class InvalidNodeConfiguration(NovaException):
25122512
msg_fmt = _('Invalid node identity configuration: %(reason)s')
2513+
2514+
2515+
class NotSupportedComputeForEvacuateV295(NotSupported):
2516+
msg_fmt = _("Starting to microversion 2.95, evacuate API will stop "
2517+
"instance on destination. To evacuate before upgrades are "
2518+
"complete please use an older microversion. Required version "
2519+
"for compute %(expected), current version %(currently)s")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"evacuate": {
3+
"adminPass": "%(adminPass)s"
4+
}
5+
}

0 commit comments

Comments
 (0)