Skip to content

Commit

Permalink
Add image caching API for aggregates
Browse files Browse the repository at this point in the history
This adds a new microversion and support for requesting image pre-caching
on an aggregate.

Related to blueprint image-precache-support

Change-Id: I4ab96095106b38737ed355fcad07e758f8b5a9b0
  • Loading branch information
kk7ds authored and mriedem committed Oct 16, 2019
1 parent 11d909c commit 3391298
Show file tree
Hide file tree
Showing 40 changed files with 570 additions and 3 deletions.
33 changes: 33 additions & 0 deletions api-ref/source/os-aggregates.inc
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,36 @@ Response

.. literalinclude:: ../../doc/api_samples/os-aggregates/v2.41/aggregates-metadata-post-resp.json
:language: javascript

Request Image Pre-caching for Aggregate
=======================================

.. rest_method:: POST /os-aggregates/{aggregate_id}/images

Requests that a set of images be pre-cached on compute nodes within the referenced aggregate.

This API is available starting with microversion 2.81.

Normal response codes: 202

Error response codes: badRequest(400), unauthorized(401), forbidden(403),
itemNotFound(404)

Request
-------

.. rest_parameters:: parameters.yaml

- aggregate_id: aggregate_id
- cache: cache
- cache.id: image_id_body

**Example Request Image pre-caching for Aggregate (v2.81): JSON request**

.. literalinclude:: ../../doc/api_samples/os-aggregates/v2.81/aggregate-images-post-req.json
:language: javascript

Response
--------

The response body is always empty.
5 changes: 5 additions & 0 deletions api-ref/source/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,11 @@ boot_index:
in: body
required: true
type: integer
cache:
description: A list of image objects to cache.
in: body
required: true
type: array
certificate:
description: |
The certificate object.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"add_host": {
"host": "compute"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cache":
[
{"id": "70a599e0-31e7-49b7-b260-868f441e862b"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"set_metadata":
{
"metadata":
{
"key": "value"
}
}
}
7 changes: 7 additions & 0 deletions doc/api_samples/os-aggregates/v2.81/aggregate-post-req.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"aggregate":
{
"name": "name",
"availability_zone": "london"
}
}
12 changes: 12 additions & 0 deletions doc/api_samples/os-aggregates/v2.81/aggregate-post-resp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"aggregate": {
"availability_zone": "london",
"created_at": "2019-10-08T15:15:27.988513",
"deleted": false,
"deleted_at": null,
"id": 1,
"name": "name",
"updated_at": null,
"uuid": "a25e34a2-4fc1-4876-82d0-cf930fa04b82"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"remove_host": {
"host": "compute"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"aggregate":
{
"name": "newname",
"availability_zone": "nova2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"aggregate": {
"availability_zone": "nova2",
"created_at": "2019-10-11T14:19:00.718841",
"deleted": false,
"deleted_at": null,
"hosts": [],
"id": 1,
"metadata": {
"availability_zone": "nova2"
},
"name": "newname",
"updated_at": "2019-10-11T14:19:00.785838",
"uuid": "4e7fa22f-f6cf-4e81-a5c7-6dc485815f81"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"aggregate": {
"availability_zone": "london",
"created_at": "2019-10-11T14:19:05.250053",
"deleted": false,
"deleted_at": null,
"hosts": [
"compute"
],
"id": 1,
"metadata": {
"availability_zone": "london"
},
"name": "name",
"updated_at": null,
"uuid": "47832b50-a192-4900-affe-8f7fdf2d7f22"
}
}
16 changes: 16 additions & 0 deletions doc/api_samples/os-aggregates/v2.81/aggregates-get-resp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"aggregate": {
"availability_zone": "london",
"created_at": "2019-10-11T14:19:07.366577",
"deleted": false,
"deleted_at": null,
"hosts": [],
"id": 1,
"metadata": {
"availability_zone": "london"
},
"name": "name",
"updated_at": null,
"uuid": "7c5ff84a-c901-4733-adf8-06875e265080"
}
}
20 changes: 20 additions & 0 deletions doc/api_samples/os-aggregates/v2.81/aggregates-list-get-resp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"aggregates": [
{
"availability_zone": "london",
"created_at": "2019-10-11T14:19:07.386637",
"deleted": false,
"deleted_at": null,
"hosts": [
"compute"
],
"id": 1,
"metadata": {
"availability_zone": "london"
},
"name": "name",
"updated_at": null,
"uuid": "070cb72c-f463-4f72-9c61-2c0556eb8c07"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"aggregate": {
"availability_zone": "london",
"created_at": "2019-10-11T14:19:03.103465",
"deleted": false,
"deleted_at": null,
"hosts": [],
"id": 1,
"metadata": {
"availability_zone": "london",
"key": "value"
},
"name": "name",
"updated_at": "2019-10-11T14:19:03.169058",
"uuid": "0843db7c-f161-446d-84c8-d936320da2e8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"aggregate": {
"availability_zone": "london",
"created_at": "2019-10-11T14:19:05.250053",
"deleted": false,
"deleted_at": null,
"hosts": [],
"id": 1,
"metadata": {
"availability_zone": "london"
},
"name": "name",
"updated_at": null,
"uuid": "47832b50-a192-4900-affe-8f7fdf2d7f22"
}
}
2 changes: 1 addition & 1 deletion doc/api_samples/versions/v21-version-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"status": "CURRENT",
"version": "2.80",
"version": "2.81",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}
Expand Down
2 changes: 1 addition & 1 deletion doc/api_samples/versions/versions-get-resp.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"status": "CURRENT",
"version": "2.80",
"version": "2.81",
"min_version": "2.1",
"updated": "2013-07-23T11:33:21Z"
}
Expand Down
4 changes: 3 additions & 1 deletion nova/api/openstack/api_version_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
``GET /os-migrations``,
``GET /servers/{server_id}/migrations``, and
``GET /servers/{server_id}/migrations/{migration_id}``.
* 2.81 - Adds support for image cache management by aggregate by adding
``POST /os-aggregates/{aggregate_id}/images``.
"""

# The minimum and maximum versions of the API supported
Expand All @@ -225,7 +227,7 @@
# Note(cyeoh): This only applies for the v2.1 API once microversions
# support is fully merged. It does not affect the V2 API.
_MIN_API_VERSION = "2.1"
_MAX_API_VERSION = "2.80"
_MAX_API_VERSION = "2.81"
DEFAULT_API_VERSION = _MIN_API_VERSION

# Almost all proxy APIs which are related to network, images and baremetal
Expand Down
30 changes: 30 additions & 0 deletions nova/api/openstack/compute/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

from nova.api.openstack import api_version_request
from nova.api.openstack import common
from nova.api.openstack.compute.schemas import aggregate_images
from nova.api.openstack.compute.schemas import aggregates
from nova.api.openstack import wsgi
from nova.api import validation
from nova.compute import api as compute
from nova.conductor import api as conductor
from nova import exception
from nova.i18n import _
from nova.policies import aggregates as aggr_policies
Expand All @@ -39,6 +41,7 @@ class AggregateController(wsgi.Controller):
def __init__(self):
super(AggregateController, self).__init__()
self.api = compute.AggregateAPI()
self.conductor_tasks = conductor.ComputeTaskAPI()

@wsgi.expected_errors(())
def index(self, req):
Expand Down Expand Up @@ -222,3 +225,30 @@ def _build_aggregate_items(self, req, aggregate):
key in aggregate.obj_extra_fields) and
(show_uuid or key != 'uuid')):
yield key, getattr(aggregate, key)

@wsgi.Controller.api_version('2.81')
@wsgi.response(202)
@wsgi.expected_errors((400, 404))
@validation.schema(aggregate_images.aggregate_images_v2_81)
def images(self, req, id, body):
"""Allows image cache management requests."""
context = _get_context(req)
context.can(aggr_policies.NEW_POLICY_ROOT % 'images')

image_ids = []
for image_req in body.get('cache'):
image_ids.append(image_req['id'])

if image_ids != list(set(image_ids)):
raise exc.HTTPBadRequest(
explanation=_('Duplicate images in request'))

try:
aggregate = self.api.get_aggregate(context, id)
except exception.AggregateNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())

try:
self.conductor_tasks.cache_images(context, aggregate, image_ids)
except exception.NovaException as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
6 changes: 6 additions & 0 deletions nova/api/openstack/compute/rest_api_version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,9 @@ project, for example:
* ``GET /os-migrations?user_id=ef9d34b4-45d0-4530-871b-3fb535988394``
* ``GET /os-migrations?project_id=011ee9f4-8f16-4c38-8633-a254d420fd54``
* ``GET /os-migrations?user_id=ef9d34b4-45d0-4530-871b-3fb535988394&project_id=011ee9f4-8f16-4c38-8633-a254d420fd54``

2.81
----

Adds support for image cache management by aggregate by adding
``POST /os-aggregates/{aggregate_id}/images``.
3 changes: 3 additions & 0 deletions nova/api/openstack/compute/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ def _create_controller(main_controller, action_controller_list):
('/os-aggregates/{id}/action', {
'POST': [aggregates_controller, 'action'],
}),
('/os-aggregates/{id}/images', {
'POST': [aggregates_controller, 'images'],
}),
('/os-assisted-volume-snapshots', {
'POST': [assisted_volume_snapshots_controller, 'create']
}),
Expand Down
34 changes: 34 additions & 0 deletions nova/api/openstack/compute/schemas/aggregate_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from nova.api.validation import parameter_types


aggregate_images_v2_81 = {
'type': 'object',
'properties': {
'cache': {
'type': ['array'],
'minItems': 1,
'items': {
'type': 'object',
'properties': {
'id': parameter_types.image_id,
},
'additionalProperties': False,
'required': ['id'],
},
},
},
'required': ['cache'],
'additionalProperties': False,
}
11 changes: 11 additions & 0 deletions nova/policies/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


POLICY_ROOT = 'os_compute_api:os-aggregates:%s'
NEW_POLICY_ROOT = 'compute:aggregates:%s'


aggregates_policies = [
Expand Down Expand Up @@ -102,6 +103,16 @@
'method': 'GET'
}
]),
policy.DocumentedRuleDefault(
NEW_POLICY_ROOT % 'images',
base.RULE_ADMIN_API,
"Request image caching for an aggregate",
[
{
'path': '/os-aggregates/{aggregate_id}/images',
'method': 'POST'
}
]),
]


Expand Down
Loading

0 comments on commit 3391298

Please sign in to comment.