Merge lp:~jk0/nova/alternate_image_links into lp:~hudson-openstack/nova/trunk
- alternate_image_links
- Merge into trunk
Proposed by
Josh Kearney
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Josh Kearney | ||||
Approved revision: | 1610 | ||||
Merged at revision: | 1609 | ||||
Proposed branch: | lp:~jk0/nova/alternate_image_links | ||||
Merge into: | lp:~hudson-openstack/nova/trunk | ||||
Diff against target: |
368 lines (+138/-2) 6 files modified
nova/api/openstack/images.py (+2/-0) nova/api/openstack/views/images.py (+15/-1) nova/flags.py (+3/-1) nova/tests/api/openstack/test_images.py (+102/-0) nova/tests/test_utils.py (+9/-0) nova/utils.py (+7/-0) |
||||
To merge this branch: | bzr merge lp:~jk0/nova/alternate_image_links | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sandy Walsh (community) | Approve | ||
Matt Dietz (community) | Approve | ||
Review via email: mp+76291@code.launchpad.net |
Commit message
Description of the change
Adds an 'alternate' link to image views per 3.10 and 3.11 of http://
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'nova/api/openstack/images.py' | |||
2 | --- nova/api/openstack/images.py 2011-09-13 18:00:20 +0000 | |||
3 | +++ nova/api/openstack/images.py 2011-09-20 21:24:24 +0000 | |||
4 | @@ -251,6 +251,8 @@ | |||
5 | 251 | elem = etree.SubElement(image_elem, | 251 | elem = etree.SubElement(image_elem, |
6 | 252 | '{%s}link' % xmlutil.XMLNS_ATOM) | 252 | '{%s}link' % xmlutil.XMLNS_ATOM) |
7 | 253 | elem.set('rel', link['rel']) | 253 | elem.set('rel', link['rel']) |
8 | 254 | if 'type' in link: | ||
9 | 255 | elem.set('type', link['type']) | ||
10 | 254 | elem.set('href', link['href']) | 256 | elem.set('href', link['href']) |
11 | 255 | return image_elem | 257 | return image_elem |
12 | 256 | 258 | ||
13 | 257 | 259 | ||
14 | === modified file 'nova/api/openstack/views/images.py' | |||
15 | --- nova/api/openstack/views/images.py 2011-09-13 19:59:45 +0000 | |||
16 | +++ nova/api/openstack/views/images.py 2011-09-20 21:24:24 +0000 | |||
17 | @@ -18,6 +18,7 @@ | |||
18 | 18 | import os.path | 18 | import os.path |
19 | 19 | 19 | ||
20 | 20 | from nova.api.openstack import common | 20 | from nova.api.openstack import common |
21 | 21 | from nova import utils | ||
22 | 21 | 22 | ||
23 | 22 | 23 | ||
24 | 23 | class ViewBuilder(object): | 24 | class ViewBuilder(object): |
25 | @@ -139,6 +140,7 @@ | |||
26 | 139 | image = ViewBuilder.build(self, image_obj, detail) | 140 | image = ViewBuilder.build(self, image_obj, detail) |
27 | 140 | href = self.generate_href(image_obj["id"]) | 141 | href = self.generate_href(image_obj["id"]) |
28 | 141 | bookmark = self.generate_bookmark(image_obj["id"]) | 142 | bookmark = self.generate_bookmark(image_obj["id"]) |
29 | 143 | alternate = self.generate_alternate(image_obj["id"]) | ||
30 | 142 | 144 | ||
31 | 143 | image["links"] = [ | 145 | image["links"] = [ |
32 | 144 | { | 146 | { |
33 | @@ -149,6 +151,11 @@ | |||
34 | 149 | "rel": "bookmark", | 151 | "rel": "bookmark", |
35 | 150 | "href": bookmark, | 152 | "href": bookmark, |
36 | 151 | }, | 153 | }, |
37 | 154 | { | ||
38 | 155 | "rel": "alternate", | ||
39 | 156 | "type": "application/vnd.openstack.image", | ||
40 | 157 | "href": alternate, | ||
41 | 158 | }, | ||
42 | 152 | 159 | ||
43 | 153 | ] | 160 | ] |
44 | 154 | 161 | ||
45 | @@ -158,6 +165,13 @@ | |||
46 | 158 | return image | 165 | return image |
47 | 159 | 166 | ||
48 | 160 | def generate_bookmark(self, image_id): | 167 | def generate_bookmark(self, image_id): |
50 | 161 | """Create an url that refers to a specific flavor id.""" | 168 | """Create a URL that refers to a specific flavor id.""" |
51 | 162 | return os.path.join(common.remove_version_from_href(self.base_url), | 169 | return os.path.join(common.remove_version_from_href(self.base_url), |
52 | 163 | self.project_id, "images", str(image_id)) | 170 | self.project_id, "images", str(image_id)) |
53 | 171 | |||
54 | 172 | def generate_alternate(self, image_id): | ||
55 | 173 | """Create an alternate link for a specific flavor id.""" | ||
56 | 174 | glance_url = utils.generate_glance_url() | ||
57 | 175 | |||
58 | 176 | return "%s/%s/images/%s" % (glance_url, self.project_id, | ||
59 | 177 | str(image_id)) | ||
60 | 164 | 178 | ||
61 | === modified file 'nova/flags.py' | |||
62 | --- nova/flags.py 2011-09-06 11:31:39 +0000 | |||
63 | +++ nova/flags.py 2011-09-20 21:24:24 +0000 | |||
64 | @@ -271,8 +271,10 @@ | |||
65 | 271 | DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID') | 271 | DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID') |
66 | 272 | DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key') | 272 | DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key') |
67 | 273 | # NOTE(sirp): my_ip interpolation doesn't work within nested structures | 273 | # NOTE(sirp): my_ip interpolation doesn't work within nested structures |
68 | 274 | DEFINE_string('glance_host', _get_my_ip(), 'default glance host') | ||
69 | 275 | DEFINE_integer('glance_port', 9292, 'default glance port') | ||
70 | 274 | DEFINE_list('glance_api_servers', | 276 | DEFINE_list('glance_api_servers', |
72 | 275 | ['%s:9292' % _get_my_ip()], | 277 | ['%s:%d' % (FLAGS.glance_host, FLAGS.glance_port)], |
73 | 276 | 'list of glance api servers available to nova (host:port)') | 278 | 'list of glance api servers available to nova (host:port)') |
74 | 277 | DEFINE_integer('s3_port', 3333, 's3 port') | 279 | DEFINE_integer('s3_port', 3333, 's3 port') |
75 | 278 | DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)') | 280 | DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)') |
76 | 279 | 281 | ||
77 | === modified file 'nova/tests/api/openstack/test_images.py' | |||
78 | --- nova/tests/api/openstack/test_images.py 2011-09-19 14:35:08 +0000 | |||
79 | +++ nova/tests/api/openstack/test_images.py 2011-09-20 21:24:24 +0000 | |||
80 | @@ -33,7 +33,9 @@ | |||
81 | 33 | import nova.api.openstack | 33 | import nova.api.openstack |
82 | 34 | from nova.api.openstack import images | 34 | from nova.api.openstack import images |
83 | 35 | from nova.api.openstack import xmlutil | 35 | from nova.api.openstack import xmlutil |
84 | 36 | from nova.api.openstack.views import images as images_view | ||
85 | 36 | from nova import test | 37 | from nova import test |
86 | 38 | from nova import utils | ||
87 | 37 | from nova.tests.api.openstack import fakes | 39 | from nova.tests.api.openstack import fakes |
88 | 38 | 40 | ||
89 | 39 | 41 | ||
90 | @@ -119,6 +121,7 @@ | |||
91 | 119 | 121 | ||
92 | 120 | href = "http://localhost/v1.1/fake/images/124" | 122 | href = "http://localhost/v1.1/fake/images/124" |
93 | 121 | bookmark = "http://localhost/fake/images/124" | 123 | bookmark = "http://localhost/fake/images/124" |
94 | 124 | alternate = "%s/fake/images/124" % utils.generate_glance_url() | ||
95 | 122 | server_href = "http://localhost/v1.1/servers/42" | 125 | server_href = "http://localhost/v1.1/servers/42" |
96 | 123 | server_bookmark = "http://localhost/servers/42" | 126 | server_bookmark = "http://localhost/servers/42" |
97 | 124 | 127 | ||
98 | @@ -152,6 +155,11 @@ | |||
99 | 152 | { | 155 | { |
100 | 153 | "rel": "bookmark", | 156 | "rel": "bookmark", |
101 | 154 | "href": bookmark, | 157 | "href": bookmark, |
102 | 158 | }, | ||
103 | 159 | { | ||
104 | 160 | "rel": "alternate", | ||
105 | 161 | "type": "application/vnd.openstack.image", | ||
106 | 162 | "href": alternate | ||
107 | 155 | }], | 163 | }], |
108 | 156 | }, | 164 | }, |
109 | 157 | } | 165 | } |
110 | @@ -289,6 +297,12 @@ | |||
111 | 289 | "rel": "bookmark", | 297 | "rel": "bookmark", |
112 | 290 | "href": "http://localhost/fake/images/123", | 298 | "href": "http://localhost/fake/images/123", |
113 | 291 | }, | 299 | }, |
114 | 300 | { | ||
115 | 301 | "rel": "alternate", | ||
116 | 302 | "type": "application/vnd.openstack.image", | ||
117 | 303 | "href": "%s/fake/images/123" % | ||
118 | 304 | utils.generate_glance_url() | ||
119 | 305 | }, | ||
120 | 292 | ], | 306 | ], |
121 | 293 | }, | 307 | }, |
122 | 294 | { | 308 | { |
123 | @@ -303,6 +317,12 @@ | |||
124 | 303 | "rel": "bookmark", | 317 | "rel": "bookmark", |
125 | 304 | "href": "http://localhost/fake/images/124", | 318 | "href": "http://localhost/fake/images/124", |
126 | 305 | }, | 319 | }, |
127 | 320 | { | ||
128 | 321 | "rel": "alternate", | ||
129 | 322 | "type": "application/vnd.openstack.image", | ||
130 | 323 | "href": "%s/fake/images/124" % | ||
131 | 324 | utils.generate_glance_url() | ||
132 | 325 | }, | ||
133 | 306 | ], | 326 | ], |
134 | 307 | }, | 327 | }, |
135 | 308 | { | 328 | { |
136 | @@ -317,6 +337,12 @@ | |||
137 | 317 | "rel": "bookmark", | 337 | "rel": "bookmark", |
138 | 318 | "href": "http://localhost/fake/images/125", | 338 | "href": "http://localhost/fake/images/125", |
139 | 319 | }, | 339 | }, |
140 | 340 | { | ||
141 | 341 | "rel": "alternate", | ||
142 | 342 | "type": "application/vnd.openstack.image", | ||
143 | 343 | "href": "%s/fake/images/125" % | ||
144 | 344 | utils.generate_glance_url() | ||
145 | 345 | }, | ||
146 | 320 | ], | 346 | ], |
147 | 321 | }, | 347 | }, |
148 | 322 | { | 348 | { |
149 | @@ -331,6 +357,12 @@ | |||
150 | 331 | "rel": "bookmark", | 357 | "rel": "bookmark", |
151 | 332 | "href": "http://localhost/fake/images/126", | 358 | "href": "http://localhost/fake/images/126", |
152 | 333 | }, | 359 | }, |
153 | 360 | { | ||
154 | 361 | "rel": "alternate", | ||
155 | 362 | "type": "application/vnd.openstack.image", | ||
156 | 363 | "href": "%s/fake/images/126" % | ||
157 | 364 | utils.generate_glance_url() | ||
158 | 365 | }, | ||
159 | 334 | ], | 366 | ], |
160 | 335 | }, | 367 | }, |
161 | 336 | { | 368 | { |
162 | @@ -345,6 +377,12 @@ | |||
163 | 345 | "rel": "bookmark", | 377 | "rel": "bookmark", |
164 | 346 | "href": "http://localhost/fake/images/127", | 378 | "href": "http://localhost/fake/images/127", |
165 | 347 | }, | 379 | }, |
166 | 380 | { | ||
167 | 381 | "rel": "alternate", | ||
168 | 382 | "type": "application/vnd.openstack.image", | ||
169 | 383 | "href": "%s/fake/images/127" % | ||
170 | 384 | utils.generate_glance_url() | ||
171 | 385 | }, | ||
172 | 348 | ], | 386 | ], |
173 | 349 | }, | 387 | }, |
174 | 350 | { | 388 | { |
175 | @@ -359,6 +397,12 @@ | |||
176 | 359 | "rel": "bookmark", | 397 | "rel": "bookmark", |
177 | 360 | "href": "http://localhost/fake/images/128", | 398 | "href": "http://localhost/fake/images/128", |
178 | 361 | }, | 399 | }, |
179 | 400 | { | ||
180 | 401 | "rel": "alternate", | ||
181 | 402 | "type": "application/vnd.openstack.image", | ||
182 | 403 | "href": "%s/fake/images/128" % | ||
183 | 404 | utils.generate_glance_url() | ||
184 | 405 | }, | ||
185 | 362 | ], | 406 | ], |
186 | 363 | }, | 407 | }, |
187 | 364 | { | 408 | { |
188 | @@ -373,6 +417,12 @@ | |||
189 | 373 | "rel": "bookmark", | 417 | "rel": "bookmark", |
190 | 374 | "href": "http://localhost/fake/images/129", | 418 | "href": "http://localhost/fake/images/129", |
191 | 375 | }, | 419 | }, |
192 | 420 | { | ||
193 | 421 | "rel": "alternate", | ||
194 | 422 | "type": "application/vnd.openstack.image", | ||
195 | 423 | "href": "%s/fake/images/129" % | ||
196 | 424 | utils.generate_glance_url() | ||
197 | 425 | }, | ||
198 | 376 | ], | 426 | ], |
199 | 377 | }, | 427 | }, |
200 | 378 | { | 428 | { |
201 | @@ -387,6 +437,12 @@ | |||
202 | 387 | "rel": "bookmark", | 437 | "rel": "bookmark", |
203 | 388 | "href": "http://localhost/fake/images/130", | 438 | "href": "http://localhost/fake/images/130", |
204 | 389 | }, | 439 | }, |
205 | 440 | { | ||
206 | 441 | "rel": "alternate", | ||
207 | 442 | "type": "application/vnd.openstack.image", | ||
208 | 443 | "href": "%s/fake/images/130" % | ||
209 | 444 | utils.generate_glance_url() | ||
210 | 445 | }, | ||
211 | 390 | ], | 446 | ], |
212 | 391 | }, | 447 | }, |
213 | 392 | ] | 448 | ] |
214 | @@ -493,6 +549,11 @@ | |||
215 | 493 | { | 549 | { |
216 | 494 | "rel": "bookmark", | 550 | "rel": "bookmark", |
217 | 495 | "href": "http://localhost/fake/images/123", | 551 | "href": "http://localhost/fake/images/123", |
218 | 552 | }, | ||
219 | 553 | { | ||
220 | 554 | "rel": "alternate", | ||
221 | 555 | "type": "application/vnd.openstack.image", | ||
222 | 556 | "href": "%s/fake/images/123" % utils.generate_glance_url() | ||
223 | 496 | }], | 557 | }], |
224 | 497 | }, | 558 | }, |
225 | 498 | { | 559 | { |
226 | @@ -524,6 +585,11 @@ | |||
227 | 524 | { | 585 | { |
228 | 525 | "rel": "bookmark", | 586 | "rel": "bookmark", |
229 | 526 | "href": "http://localhost/fake/images/124", | 587 | "href": "http://localhost/fake/images/124", |
230 | 588 | }, | ||
231 | 589 | { | ||
232 | 590 | "rel": "alternate", | ||
233 | 591 | "type": "application/vnd.openstack.image", | ||
234 | 592 | "href": "%s/fake/images/124" % utils.generate_glance_url() | ||
235 | 527 | }], | 593 | }], |
236 | 528 | }, | 594 | }, |
237 | 529 | { | 595 | { |
238 | @@ -555,6 +621,11 @@ | |||
239 | 555 | { | 621 | { |
240 | 556 | "rel": "bookmark", | 622 | "rel": "bookmark", |
241 | 557 | "href": "http://localhost/fake/images/125", | 623 | "href": "http://localhost/fake/images/125", |
242 | 624 | }, | ||
243 | 625 | { | ||
244 | 626 | "rel": "alternate", | ||
245 | 627 | "type": "application/vnd.openstack.image", | ||
246 | 628 | "href": "%s/fake/images/125" % utils.generate_glance_url() | ||
247 | 558 | }], | 629 | }], |
248 | 559 | }, | 630 | }, |
249 | 560 | { | 631 | { |
250 | @@ -586,6 +657,11 @@ | |||
251 | 586 | { | 657 | { |
252 | 587 | "rel": "bookmark", | 658 | "rel": "bookmark", |
253 | 588 | "href": "http://localhost/fake/images/126", | 659 | "href": "http://localhost/fake/images/126", |
254 | 660 | }, | ||
255 | 661 | { | ||
256 | 662 | "rel": "alternate", | ||
257 | 663 | "type": "application/vnd.openstack.image", | ||
258 | 664 | "href": "%s/fake/images/126" % utils.generate_glance_url() | ||
259 | 589 | }], | 665 | }], |
260 | 590 | }, | 666 | }, |
261 | 591 | { | 667 | { |
262 | @@ -617,6 +693,11 @@ | |||
263 | 617 | { | 693 | { |
264 | 618 | "rel": "bookmark", | 694 | "rel": "bookmark", |
265 | 619 | "href": "http://localhost/fake/images/127", | 695 | "href": "http://localhost/fake/images/127", |
266 | 696 | }, | ||
267 | 697 | { | ||
268 | 698 | "rel": "alternate", | ||
269 | 699 | "type": "application/vnd.openstack.image", | ||
270 | 700 | "href": "%s/fake/images/127" % utils.generate_glance_url() | ||
271 | 620 | }], | 701 | }], |
272 | 621 | }, | 702 | }, |
273 | 622 | { | 703 | { |
274 | @@ -648,6 +729,11 @@ | |||
275 | 648 | { | 729 | { |
276 | 649 | "rel": "bookmark", | 730 | "rel": "bookmark", |
277 | 650 | "href": "http://localhost/fake/images/128", | 731 | "href": "http://localhost/fake/images/128", |
278 | 732 | }, | ||
279 | 733 | { | ||
280 | 734 | "rel": "alternate", | ||
281 | 735 | "type": "application/vnd.openstack.image", | ||
282 | 736 | "href": "%s/fake/images/128" % utils.generate_glance_url() | ||
283 | 651 | }], | 737 | }], |
284 | 652 | }, | 738 | }, |
285 | 653 | { | 739 | { |
286 | @@ -679,6 +765,11 @@ | |||
287 | 679 | { | 765 | { |
288 | 680 | "rel": "bookmark", | 766 | "rel": "bookmark", |
289 | 681 | "href": "http://localhost/fake/images/129", | 767 | "href": "http://localhost/fake/images/129", |
290 | 768 | }, | ||
291 | 769 | { | ||
292 | 770 | "rel": "alternate", | ||
293 | 771 | "type": "application/vnd.openstack.image", | ||
294 | 772 | "href": "%s/fake/images/129" % utils.generate_glance_url() | ||
295 | 682 | }], | 773 | }], |
296 | 683 | }, | 774 | }, |
297 | 684 | { | 775 | { |
298 | @@ -696,6 +787,11 @@ | |||
299 | 696 | { | 787 | { |
300 | 697 | "rel": "bookmark", | 788 | "rel": "bookmark", |
301 | 698 | "href": "http://localhost/fake/images/130", | 789 | "href": "http://localhost/fake/images/130", |
302 | 790 | }, | ||
303 | 791 | { | ||
304 | 792 | "rel": "alternate", | ||
305 | 793 | "type": "application/vnd.openstack.image", | ||
306 | 794 | "href": "%s/fake/images/130" % utils.generate_glance_url() | ||
307 | 699 | }], | 795 | }], |
308 | 700 | }, | 796 | }, |
309 | 701 | ] | 797 | ] |
310 | @@ -963,6 +1059,12 @@ | |||
311 | 963 | response = req.get_response(fakes.wsgi_app()) | 1059 | response = req.get_response(fakes.wsgi_app()) |
312 | 964 | self.assertEqual(400, response.status_int) | 1060 | self.assertEqual(400, response.status_int) |
313 | 965 | 1061 | ||
314 | 1062 | def test_generate_alternate(self): | ||
315 | 1063 | view = images_view.ViewBuilderV11(1) | ||
316 | 1064 | generated_url = view.generate_alternate(1) | ||
317 | 1065 | actual_url = "%s//images/1" % utils.generate_glance_url() | ||
318 | 1066 | self.assertEqual(generated_url, actual_url) | ||
319 | 1067 | |||
320 | 966 | 1068 | ||
321 | 967 | class ImageXMLSerializationTest(test.TestCase): | 1069 | class ImageXMLSerializationTest(test.TestCase): |
322 | 968 | 1070 | ||
323 | 969 | 1071 | ||
324 | === modified file 'nova/tests/test_utils.py' | |||
325 | --- nova/tests/test_utils.py 2011-08-23 15:07:25 +0000 | |||
326 | +++ nova/tests/test_utils.py 2011-09-20 21:24:24 +0000 | |||
327 | @@ -20,10 +20,14 @@ | |||
328 | 20 | 20 | ||
329 | 21 | import nova | 21 | import nova |
330 | 22 | from nova import exception | 22 | from nova import exception |
331 | 23 | from nova import flags | ||
332 | 23 | from nova import test | 24 | from nova import test |
333 | 24 | from nova import utils | 25 | from nova import utils |
334 | 25 | 26 | ||
335 | 26 | 27 | ||
336 | 28 | FLAGS = flags.FLAGS | ||
337 | 29 | |||
338 | 30 | |||
339 | 27 | class ExecuteTestCase(test.TestCase): | 31 | class ExecuteTestCase(test.TestCase): |
340 | 28 | def test_retry_on_failure(self): | 32 | def test_retry_on_failure(self): |
341 | 29 | fd, tmpfilename = tempfile.mkstemp() | 33 | fd, tmpfilename = tempfile.mkstemp() |
342 | @@ -291,6 +295,11 @@ | |||
343 | 291 | self.assertFalse(utils.bool_from_str(None)) | 295 | self.assertFalse(utils.bool_from_str(None)) |
344 | 292 | self.assertFalse(utils.bool_from_str('junk')) | 296 | self.assertFalse(utils.bool_from_str('junk')) |
345 | 293 | 297 | ||
346 | 298 | def test_generate_glance_url(self): | ||
347 | 299 | generated_url = utils.generate_glance_url() | ||
348 | 300 | actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port) | ||
349 | 301 | self.assertEqual(generated_url, actual_url) | ||
350 | 302 | |||
351 | 294 | 303 | ||
352 | 295 | class IsUUIDLikeTestCase(test.TestCase): | 304 | class IsUUIDLikeTestCase(test.TestCase): |
353 | 296 | def assertUUIDLike(self, val, expected): | 305 | def assertUUIDLike(self, val, expected): |
354 | 297 | 306 | ||
355 | === modified file 'nova/utils.py' | |||
356 | --- nova/utils.py 2011-09-02 18:00:33 +0000 | |||
357 | +++ nova/utils.py 2011-09-20 21:24:24 +0000 | |||
358 | @@ -910,3 +910,10 @@ | |||
359 | 910 | if not isinstance(lst, list): | 910 | if not isinstance(lst, list): |
360 | 911 | lst = [lst] | 911 | lst = [lst] |
361 | 912 | return [{label: x} for x in lst] | 912 | return [{label: x} for x in lst] |
362 | 913 | |||
363 | 914 | |||
364 | 915 | def generate_glance_url(): | ||
365 | 916 | """Generate the URL to glance.""" | ||
366 | 917 | # TODO(jk0): This will eventually need to take SSL into consideration | ||
367 | 918 | # when supported in glance. | ||
368 | 919 | return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port) |
\o/