DELETE all inventory for a resource provider
This patch adds a new method for deleting all inventories for a resource provider: DELETE /resource-providers/{uuid}/inventories Return codes: 204 NoContent on success 404 NotFound if the resource provider does not exist 405 MethodNotAllowed if a microversion is specified that is before this change (1.5) 409 Conflict if inventory in use or if some other request concurrently updates this resource provider Change-Id: I1ecb12c888f873e8330367c8411d5a2ef0458495 Implements: bp delete-inventories-placement-api
This commit is contained in:
parent
4b79d3e631
commit
df9af212c2
@ -80,7 +80,8 @@ ROUTE_DECLARATIONS = {
|
|||||||
'/resource_providers/{uuid}/inventories': {
|
'/resource_providers/{uuid}/inventories': {
|
||||||
'GET': inventory.get_inventories,
|
'GET': inventory.get_inventories,
|
||||||
'POST': inventory.create_inventory,
|
'POST': inventory.create_inventory,
|
||||||
'PUT': inventory.set_inventories
|
'PUT': inventory.set_inventories,
|
||||||
|
'DELETE': inventory.delete_inventories
|
||||||
},
|
},
|
||||||
'/resource_providers/{uuid}/inventories/{resource_class}': {
|
'/resource_providers/{uuid}/inventories/{resource_class}': {
|
||||||
'GET': inventory.get_inventory,
|
'GET': inventory.get_inventory,
|
||||||
|
@ -18,6 +18,7 @@ from oslo_serialization import jsonutils
|
|||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
|
from nova.api.openstack.placement import microversion
|
||||||
from nova.api.openstack.placement import util
|
from nova.api.openstack.placement import util
|
||||||
from nova.api.openstack.placement import wsgi_wrapper
|
from nova.api.openstack.placement import wsgi_wrapper
|
||||||
from nova import db
|
from nova import db
|
||||||
@ -378,6 +379,37 @@ def set_inventories(req):
|
|||||||
return _send_inventories(req.response, resource_provider, inventories)
|
return _send_inventories(req.response, resource_provider, inventories)
|
||||||
|
|
||||||
|
|
||||||
|
@wsgi_wrapper.PlacementWsgify
|
||||||
|
def delete_inventories(req):
|
||||||
|
"""DELETE all inventory for a resource provider.
|
||||||
|
|
||||||
|
Delete inventory as required to reset all the inventory.
|
||||||
|
If an inventory to be deleted is in use, return a 409 Conflict.
|
||||||
|
On success return a 204 No content.
|
||||||
|
Return 405 Method Not Allowed if the wanted microversion does not match.
|
||||||
|
"""
|
||||||
|
microversion.raise_http_status_code_if_not_version(req, 405, (1, 5))
|
||||||
|
context = req.environ['placement.context']
|
||||||
|
uuid = util.wsgi_path_item(req.environ, 'uuid')
|
||||||
|
resource_provider = objects.ResourceProvider.get_by_uuid(
|
||||||
|
context, uuid)
|
||||||
|
|
||||||
|
inventories = objects.InventoryList(objects=[])
|
||||||
|
|
||||||
|
try:
|
||||||
|
resource_provider.set_inventory(inventories)
|
||||||
|
except (exception.ConcurrentUpdateDetected,
|
||||||
|
exception.InventoryInUse) as exc:
|
||||||
|
raise webob.exc.HTTPConflict(
|
||||||
|
_('update conflict: %(error)s') % {'error': exc})
|
||||||
|
|
||||||
|
response = req.response
|
||||||
|
response.status = 204
|
||||||
|
response.content_type = None
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@wsgi_wrapper.PlacementWsgify
|
@wsgi_wrapper.PlacementWsgify
|
||||||
@util.require_content('application/json')
|
@util.require_content('application/json')
|
||||||
def update_inventory(req):
|
def update_inventory(req):
|
||||||
|
@ -40,6 +40,7 @@ VERSIONS = [
|
|||||||
'1.3', # Adds 'member_of' query parameter to get resource providers
|
'1.3', # Adds 'member_of' query parameter to get resource providers
|
||||||
# that are members of any of the listed aggregates
|
# that are members of any of the listed aggregates
|
||||||
'1.4', # Adds resources query string parameter in GET /resource_providers
|
'1.4', # Adds resources query string parameter in GET /resource_providers
|
||||||
|
'1.5', # Adds DELETE /resource_providers/{uuid}/inventories
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,3 +81,11 @@ If the resource class does not exist, then it will return a HTTP 400.
|
|||||||
requested for a given inventory and resource provider. The `step_size` is
|
requested for a given inventory and resource provider. The `step_size` is
|
||||||
the increment of resource that can be requested for a given resource on a
|
the increment of resource that can be requested for a given resource on a
|
||||||
given provider.
|
given provider.
|
||||||
|
|
||||||
|
1.5 DELETE all inventory for a resource provider
|
||||||
|
------------------------------------------------
|
||||||
|
|
||||||
|
Placement API version 1.5 adds DELETE method for deleting all inventory for a
|
||||||
|
resource provider. The following new method is supported:
|
||||||
|
|
||||||
|
* DELETE /resource_providers/{uuid}/inventories
|
||||||
|
@ -15,6 +15,12 @@ tests:
|
|||||||
response_json_paths:
|
response_json_paths:
|
||||||
$.errors[0].title: Not Found
|
$.errors[0].title: Not Found
|
||||||
|
|
||||||
|
- name: delete all inventory for missing resource provider
|
||||||
|
DELETE: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
request_headers:
|
||||||
|
openstack-api-version: placement 1.5
|
||||||
|
status: 404
|
||||||
|
|
||||||
- name: post new resource provider
|
- name: post new resource provider
|
||||||
POST: /resource_providers
|
POST: /resource_providers
|
||||||
request_headers:
|
request_headers:
|
||||||
@ -538,3 +544,40 @@ tests:
|
|||||||
- Unable to update inventory
|
- Unable to update inventory
|
||||||
response_json_paths:
|
response_json_paths:
|
||||||
$.errors[0].title: Bad Request
|
$.errors[0].title: Bad Request
|
||||||
|
|
||||||
|
- name: delete all inventory bad generation
|
||||||
|
PUT: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
request_headers:
|
||||||
|
content-type: application/json
|
||||||
|
data:
|
||||||
|
resource_provider_generation: 99
|
||||||
|
inventories:
|
||||||
|
IPV4_ADDRESS:
|
||||||
|
total: 253
|
||||||
|
status: 409
|
||||||
|
response_strings:
|
||||||
|
- resource provider generation conflict
|
||||||
|
|
||||||
|
- name: delete all inventory
|
||||||
|
DELETE: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
request_headers:
|
||||||
|
openstack-api-version: placement 1.5
|
||||||
|
status: 204
|
||||||
|
|
||||||
|
- name: get inventories after deletion
|
||||||
|
GET: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
response_json_paths:
|
||||||
|
$.resource_provider_generation: 7
|
||||||
|
$.inventories: {}
|
||||||
|
|
||||||
|
- name: delete empty inventories
|
||||||
|
DELETE: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
request_headers:
|
||||||
|
openstack-api-version: placement 1.5
|
||||||
|
status: 204
|
||||||
|
|
||||||
|
- name: delete inventories earlier version
|
||||||
|
DELETE: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
request_headers:
|
||||||
|
openstack-api-version: placement 1.4
|
||||||
|
status: 405
|
||||||
|
@ -39,13 +39,13 @@ tests:
|
|||||||
response_json_paths:
|
response_json_paths:
|
||||||
$.errors[0].title: Not Acceptable
|
$.errors[0].title: Not Acceptable
|
||||||
|
|
||||||
- name: latest microversion is 1.4
|
- name: latest microversion is 1.5
|
||||||
GET: /
|
GET: /
|
||||||
request_headers:
|
request_headers:
|
||||||
openstack-api-version: placement latest
|
openstack-api-version: placement latest
|
||||||
response_headers:
|
response_headers:
|
||||||
vary: /OpenStack-API-Version/
|
vary: /OpenStack-API-Version/
|
||||||
openstack-api-version: placement 1.4
|
openstack-api-version: placement 1.5
|
||||||
|
|
||||||
- name: other accept header bad version
|
- name: other accept header bad version
|
||||||
GET: /
|
GET: /
|
||||||
|
@ -30,3 +30,14 @@ tests:
|
|||||||
status: 409
|
status: 409
|
||||||
response_strings:
|
response_strings:
|
||||||
- "Unable to delete resource provider $ENVIRON['RP_UUID']: Resource provider has allocations."
|
- "Unable to delete resource provider $ENVIRON['RP_UUID']: Resource provider has allocations."
|
||||||
|
|
||||||
|
- name: fail to delete all inventory
|
||||||
|
DELETE: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||||
|
request_headers:
|
||||||
|
accept: application/json
|
||||||
|
openstack-api-version: placement 1.5
|
||||||
|
status: 409
|
||||||
|
response_headers:
|
||||||
|
content-type: /application/json/
|
||||||
|
response_strings:
|
||||||
|
- "Inventory for 'VCPU, DISK_GB' on resource provider '$ENVIRON['RP_UUID']' in use"
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Supports a new method for deleting all inventory for a
|
||||||
|
resource provider
|
||||||
|
|
||||||
|
* DELETE /resource-providers/{uuid}/inventories
|
||||||
|
|
||||||
|
Return codes
|
||||||
|
|
||||||
|
* 204 NoContent on success
|
||||||
|
* 404 NotFound for missing resource provider
|
||||||
|
* 405 MethodNotAllowed if a microversion is specified that is before
|
||||||
|
this change (1.5)
|
||||||
|
* 409 Conflict if inventory in use or if some other request concurrently
|
||||||
|
updates this resource provider
|
||||||
|
|
||||||
|
Requires OpenStack-API-Version placement 1.5
|
Loading…
Reference in New Issue
Block a user