Adding image location selection strategy

Registered by Zhi Yan Liu on 2013-11-15

An image can be saved to more than one backend storage by multi-location mechanism, therefore Glance should be able to select the best backend storage for improve image consuming performance. As an end user, he can get VM or consuming image faster base on this enhancement. This is not only for 'download' transport handling on the API server side but also for client since they can obtain locations by standard 'direct URL' interface. So the strategy option and the configurations of specific strategy should can be added to API server side and client side [1] consistently, and also the strategy based selection functions should be shared between API server side and client side also.

1. Adding "location_selection_strategy" option, and currently support two strategies: "location_order" or "store_type".
2. Implement two selection functions to support those two strategies, and put #1 and #2 stuff to a common code place.
  i. "location_order": using image owner or admin given locations arbitrary order.
  ii. "store_type": using configured backend storage preference, ordered by another option like ['file', 'swift', 's3'], that means using file based location first if image have, then swift and s3 at last.
3. Change Glance v2 'download' action to involve strategy based selection mechanism.

[1] We have a plan to do a reusable glance client library for all clients like Nova and Cinder in near period, it can contains common code to provide uniform image service interface for them. This just like Brick in Cinder.

Blueprint information

Mark Washenberger
Zhi Yan Liu
Needs approval
Zhi Yan Liu
Series goal:
Accepted for icehouse
Milestone target:
milestone icon 2014.1
Started by
Zhi Yan Liu on 2013-11-26
Completed by
Thierry Carrez on 2014-02-11

Related branches



Under the design for this BP, those strategies are all be static and configured by Cloud owner/admin or operator.
In future, we can do a local metrics tracking library for client side, to get the dynamic performance metrics and save those indicators to local. Locality is critical because different glance nodes likely have different relationships to the underlying locations in terms of network distance, so each node should be gearing towards what is best for it.

Addressed by:
    Adding image location selection strategies

Addressed by:
    Apply image location selection strategy

A near miss on icehouse-2, but with the gate going slow and only one patch ready to land, Iets just try to land this ASAP in icehouse 3. Still on top of my review queue! :-)


Sample test sequence to play this feature. --zhiyan

1. Enable 'show_image_direct_url' option and/or 'show_multiple_locations' option for glance api service, for example:

$ cat /etc/glance/glance-api.conf | grep 'show_'
show_image_direct_url = True
show_multiple_locations = False

2. Set 'location_strategy' option to 'location_order' or 'store_type' for glance api service as you needed, like this:

$ cat /etc/glance/glance-api.conf | grep 'location_strategy'
location_strategy = location_order

Currently glance has only two built-in strategies, and if you choose to use 'store_type' as your image location selection strategy then you should configure 'store_type_preference' option within 'store_type_location_strategy' configuration group. For more details of the option please refer descriptions in glance.conf template.

3. Start/restart glance api service to apply those options.

4. Create an image for testing and get image id from response, for example:

$ curl -i -X POST -H 'X-Auth-Token: 7792c8f4500d4b2d9699135815840b26' -H 'Content-Type: application/json' -H 'User-Agent: python-glanceclient' -d '{"container_format": "bare", "disk_format": "qcow2", "name": "image_test", "visibility": "public"}'

5. Assign multiple locations to the image via PATCH, like this:

$ curl -X PATCH -H 'X-Auth-Token: 7792c8f4500d4b2d9699135815840b26' -H 'User-Agent: python-lient' -H 'Content-Type: application/openstack-images-v2.1-json-patch' -i -d '[{"op": "replace", "path": "/locations", "value": [{"url": "file:///home/lzy/image_test_loc_1", "metadata": {}}, {"url": "", "metadata": {}}]}]'

{"status": "active", "name": "image_test", "tags": [], "container_format": "bare", "created_at": "2014-01-30T21:14:25Z", "size": 13147648, "disk_format": "qcow2", "updated_at": "2014-01-30T21:19:37Z", "visibility": "public", "self": "/v2/images/12d618d6-df2a-4e5d-8047-24d31883a1d1", "min_disk": 0, "protected": false, "id": "12d618d6-df2a-4e5d-8047-24d31883a1d1", "file": "/v2/images/12d618d6-df2a-4e5d-8047-24d31883a1d1/file", "owner": "4a0c4051e04a45a193e9bf1a9db3b923", "direct_url": "file:///home/lzy/image_test_loc_1", "min_ram": 0, "schema": "/v2/schemas/image"}

6. Verify image status under 'active' and end user can reach image direct locations as he configured selection strategy, for instance:

$ curl -i -X GET -H 'X-Auth-Token: b2817fe4c9d948ceafdf037b917e086b' -H 'Content-Type: application/json' -H 'User-Agent: python-glanceclient'

{"status": "active", "name": "image_test", "tags": [], "container_format": "bare", "created_at": "2014-01-30T21:14:25Z", "size": 13147648, "disk_format": "qcow2", "updated_at": "2014-01-30T21:19:37Z", "visibility": "public", "locations": [{"url": "file:///home/lzy/image_test_loc_1", "metadata": {}}, {"url": "", "metadata": {}}], "self": "/v2/images/12d618d6-df2a-4e5d-8047-24d31883a1d1", "min_disk": 0, "protected": false, "id": "12d618d6-df2a-4e5d-8047-24d31883a1d1", "file": "/v2/images/12d618d6-df2a-4e5d-8047-24d31883a1d1/file", "owner": "4a0c4051e04a45a193e9bf1a9db3b923", "direct_url": "file:///home/lzy/image_test_loc_1", "min_ram": 0, "schema": "/v2/schemas/image"}

Note, in this case I'm using 'location_order' location selection strategy and enabled 'show_multiple_locations' option for show your details.
And now, from above result you can see the image loctions have been listed as its original order which I provided in above step (first one is 'loc_1' and second is 'loc_2') within 'locations' field, and as we expected the 'direct_url' give a correct value (the first one).

7. As alternative location strategy, if end user use ''store_type' strategy, and give 'http, file' as the value for 'store_type_preference' option, then the image locations result will as following:

{"status": "active", "name": "image_test", "tags": [], "container_format": "bare", "created_at": "2014-01-30T21:14:25Z", "size": 13147648, "disk_format": "qcow2", "updated_at": "2014-01-30T21:19:37Z", "visibility": "public", "locations": [{"url": "", "metadata": {}}, {"url": "file:///home/lzy/image_test_loc_1", "metadata": {}}], "self": "/v2/images/12d618d6-df2a-4e5d-8047-24d31883a1d1", "min_disk": 0, "protected": false, "id": "12d618d6-df2a-4e5d-8047-24d31883a1d1", "file": "/v2/images/12d618d6-df2a-4e5d-8047-24d31883a1d1/file", "owner": "4a0c4051e04a45a193e9bf1a9db3b923", "direct_url": "", "min_ram": 0, "schema": "/v2/schemas/image"}

In above result, the image locations have been exposed as 'store_type_preference' option requireed which we configured (first one is 'loc_2' and second is 'loc_1'), it's different then I initial provided of course.



Work Items

This blueprint contains Public information 
Everyone can see this information.