Bug 1041738

Summary: [RFE][glance]: Adding image location selection strategy
Product: Red Hat OpenStack Reporter: RHOS Integration <rhos-integ>
Component: openstack-glanceAssignee: Flavio Percoco <fpercoco>
Status: CLOSED ERRATA QA Contact: Tzach Shefi <tshefi>
Severity: medium Docs Contact:
Priority: urgent    
Version: unspecifiedCC: adahms, dnavale, dron, eglynn, fpercoco, markmc, scohen, tshefi, yeylon
Target Milestone: Upstream M3Keywords: FutureFeature, Triaged
Target Release: 5.0 (RHEL 7)   
Hardware: Unspecified   
OS: Unspecified   
URL: https://blueprints.launchpad.net/glance/+spec/image-location-selection-strategy
Whiteboard: upstream_milestone_icehouse-3 upstream_status_implemented upstream_definition_approved
Fixed In Version: openstack-glance-2014.1-2.el7ost Doc Type: Enhancement
Doc Text:
Multi-location support allows Glance to store locations pointing to copies of the same image data stored in different places. Previously, this feature did not allow Glance to choose the store from which to download an image. This update adds two strategies for selecting the location to send back to the client - the location from which to download the image. The two strategies are: 1. Location order: A simple round-robin that goes through all the available locations in order - as they were inserted. 2. Store type: Allows users to specify store preferences. A possible combination is: `http, file`. This tells Glance to try to download images from HTTP stores before downloading them from file stores.
Story Points: ---
Clone Of:
: 1082901 (view as bug list) Environment:
Last Closed: 2014-07-08 15:31:52 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1082901    

Description RHOS Integration 2013-12-12 19:06:39 UTC
Cloned from launchpad blueprint https://blueprints.launchpad.net/glance/+spec/image-location-selection-strategy.

Description:

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.

Specification URL (additional information):

None

Comment 13 Flavio Percoco 2014-03-21 10:50:08 UTC
Test case for this feature:

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


$ glance image-create --disk-format qcow2 --container-format bare --name test
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | None                                 |
| container_format | bare                                 |
| created_at       | 2014-03-21T09:40:57                  |
| deleted          | False                                |
| deleted_at       | None                                 |
| disk_format      | qcow2                                |
| id               | a9ff0a36-c6bd-4c4e-b3b2-50a2a1cf4e44 |
| is_public        | False                                |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | test                                 |
| owner            | 9599f20756514c6085310f2b2998afa1     |
| protected        | False                                |
| size             | 0                                    |
| status           | queued                               |
| updated_at       | 2014-03-21T09:40:57                  |
| virtual_size     | None                                 |
+------------------+--------------------------------------+

This curl command is needed. Support for multi-location is being added to the client: https://review.openstack.org/#/c/72539/3

$ curl -X PATCH -H 'X-Auth-Token: b1f05c68b0534e28b4c45e05f0ac67de' -H 'User-Agent: python-lient' -H 'Content-Type: application/openstack-images-v2.1-json-patch' -i http://127.0.0.1:9292/v2/images/a9ff0a36-c6bd-4c4e-b3b2-50a2a1cf4e44 -d '[{"op": "replace", "path": "/locations", "value": [{"url": "file:///home/fedora/test", "metadata": {}}, {"url": "http://127.0.0.1:9292/image_test_loc_2", "metadata": {}}]}]'


Note that file:// is chosen instead of http.

[fedora@glance-strategy devstack]$ glance --os-image-api-version 2 image-show a9ff0a36-c6bd-4c4e-b3b2-50a2a1cf4e44
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| container_format | bare                                 |
| created_at       | 2014-03-21T09:40:57Z                 |
| direct_url       | file:///home/fedora/test             |
| disk_format      | qcow2                                |
| id               | a9ff0a36-c6bd-4c4e-b3b2-50a2a1cf4e44 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | test                                 |
| owner            | 9599f20756514c6085310f2b2998afa1     |
| protected        | False                                |
| size             | 4096                                 |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2014-03-21T09:43:34Z                 |
| visibility       | private                              |
+------------------+--------------------------------------+


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

[fedora@glance-strategy devstack]$ cat /etc/glance/glance-api.conf | egrep "(location_strategy|store_type_preference)"
location_strategy = store_type 
[store_type_location_strategy]
# location strategy defined by the 'location_strategy' config option.
store_type_preference = http, file


[fedora@glance-strategy devstack]$ glance --os-image-api-version 2 image-show a9ff0a36-c6bd-4c4e-b3b2-50a2a1cf4e44
+------------------+----------------------------------------+
| Property         | Value                                  |
+------------------+----------------------------------------+
| container_format | bare                                   |
| created_at       | 2014-03-21T09:40:57Z                   |
| direct_url       | http://127.0.0.1:9292/image_test_loc_2 |
| disk_format      | qcow2                                  |
| id               | a9ff0a36-c6bd-4c4e-b3b2-50a2a1cf4e44   |
| min_disk         | 0                                      |
| min_ram          | 0                                      |
| name             | test                                   |
| owner            | 9599f20756514c6085310f2b2998afa1       |
| protected        | False                                  |
| size             | 4096                                   |
| status           | active                                 |
| tags             | []                                     |
| updated_at       | 2014-03-21T09:43:34Z                   |
| visibility       | private                                |
+------------------+----------------------------------------+

Comment 16 Tzach Shefi 2014-06-16 11:37:00 UTC
Verified on:
RHEL7
python-glance-2014.1-2.el7ost.noarch
python-glanceclient-0.12.0-1.el7ost.noarch
openstack-glance-2014.1-2.el7ost.noarch

Work flow see comment 4 and 13. 
Output from testing same as mentioned in comment 4.

Comment 18 errata-xmlrpc 2014-07-08 15:31:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHEA-2014-0851.html