Merge "Fix request body for compute unshelve action API"

This commit is contained in:
Zuul 2020-06-22 16:21:16 +00:00 committed by Gerrit Code Review
commit 206a9abec5
1 changed files with 13 additions and 1 deletions

View File

@ -206,7 +206,10 @@ class ServersClient(base_compute_client.BaseComputeClient):
def action(self, server_id, action_name,
schema=schema.server_actions_common_schema,
**kwargs):
post_body = json.dumps({action_name: kwargs})
if 'body' in kwargs:
post_body = json.dumps(kwargs['body'])
else:
post_body = json.dumps({action_name: kwargs})
resp, body = self.post('servers/%s/action' % server_id,
post_body)
if body:
@ -608,6 +611,15 @@ class ServersClient(base_compute_client.BaseComputeClient):
API reference:
https://docs.openstack.org/api-ref/compute/#unshelve-restore-shelved-server-unshelve-action
"""
# NOTE(gmann): pass None as request body if nothing is requested.
# Nova started the request body check since 2.77 microversion and only
# accept AZ or None as valid req body and reject the empty dict {}.
# Before 2.77 microverison anything is valid body as Nova does not
# check the request body but as per api-ref None is valid request
# body to pass so we do not need to check the requested microversion
# here and always default req body to None.
if not kwargs:
kwargs['body'] = {'unshelve': None}
return self.action(server_id, 'unshelve', **kwargs)
def shelve_offload_server(self, server_id, **kwargs):