Merge lp:~jk0/nova/alternate_image_links into lp:~hudson-openstack/nova/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
Reviewer Review Type Date Requested Status
Sandy Walsh (community) Approve
Matt Dietz (community) Approve
Review via email: mp+76291@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Matt Dietz (cerberus) wrote :

\o/

review: Approve
Revision history for this message
Sandy Walsh (sandy-walsh) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/api/openstack/images.py'
--- nova/api/openstack/images.py 2011-09-13 18:00:20 +0000
+++ nova/api/openstack/images.py 2011-09-20 21:24:24 +0000
@@ -251,6 +251,8 @@
251 elem = etree.SubElement(image_elem,251 elem = etree.SubElement(image_elem,
252 '{%s}link' % xmlutil.XMLNS_ATOM)252 '{%s}link' % xmlutil.XMLNS_ATOM)
253 elem.set('rel', link['rel'])253 elem.set('rel', link['rel'])
254 if 'type' in link:
255 elem.set('type', link['type'])
254 elem.set('href', link['href'])256 elem.set('href', link['href'])
255 return image_elem257 return image_elem
256258
257259
=== modified file 'nova/api/openstack/views/images.py'
--- nova/api/openstack/views/images.py 2011-09-13 19:59:45 +0000
+++ nova/api/openstack/views/images.py 2011-09-20 21:24:24 +0000
@@ -18,6 +18,7 @@
18import os.path18import os.path
1919
20from nova.api.openstack import common20from nova.api.openstack import common
21from nova import utils
2122
2223
23class ViewBuilder(object):24class ViewBuilder(object):
@@ -139,6 +140,7 @@
139 image = ViewBuilder.build(self, image_obj, detail)140 image = ViewBuilder.build(self, image_obj, detail)
140 href = self.generate_href(image_obj["id"])141 href = self.generate_href(image_obj["id"])
141 bookmark = self.generate_bookmark(image_obj["id"])142 bookmark = self.generate_bookmark(image_obj["id"])
143 alternate = self.generate_alternate(image_obj["id"])
142144
143 image["links"] = [145 image["links"] = [
144 {146 {
@@ -149,6 +151,11 @@
149 "rel": "bookmark",151 "rel": "bookmark",
150 "href": bookmark,152 "href": bookmark,
151 },153 },
154 {
155 "rel": "alternate",
156 "type": "application/vnd.openstack.image",
157 "href": alternate,
158 },
152159
153 ]160 ]
154161
@@ -158,6 +165,13 @@
158 return image165 return image
159166
160 def generate_bookmark(self, image_id):167 def generate_bookmark(self, image_id):
161 """Create an url that refers to a specific flavor id."""168 """Create a URL that refers to a specific flavor id."""
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),
163 self.project_id, "images", str(image_id))170 self.project_id, "images", str(image_id))
171
172 def generate_alternate(self, image_id):
173 """Create an alternate link for a specific flavor id."""
174 glance_url = utils.generate_glance_url()
175
176 return "%s/%s/images/%s" % (glance_url, self.project_id,
177 str(image_id))
164178
=== modified file 'nova/flags.py'
--- nova/flags.py 2011-09-06 11:31:39 +0000
+++ nova/flags.py 2011-09-20 21:24:24 +0000
@@ -271,8 +271,10 @@
271DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID')271DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID')
272DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key')272DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key')
273# NOTE(sirp): my_ip interpolation doesn't work within nested structures273# NOTE(sirp): my_ip interpolation doesn't work within nested structures
274DEFINE_string('glance_host', _get_my_ip(), 'default glance host')
275DEFINE_integer('glance_port', 9292, 'default glance port')
274DEFINE_list('glance_api_servers',276DEFINE_list('glance_api_servers',
275 ['%s:9292' % _get_my_ip()],277 ['%s:%d' % (FLAGS.glance_host, FLAGS.glance_port)],
276 'list of glance api servers available to nova (host:port)')278 'list of glance api servers available to nova (host:port)')
277DEFINE_integer('s3_port', 3333, 's3 port')279DEFINE_integer('s3_port', 3333, 's3 port')
278DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)')280DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)')
279281
=== modified file 'nova/tests/api/openstack/test_images.py'
--- nova/tests/api/openstack/test_images.py 2011-09-19 14:35:08 +0000
+++ nova/tests/api/openstack/test_images.py 2011-09-20 21:24:24 +0000
@@ -33,7 +33,9 @@
33import nova.api.openstack33import nova.api.openstack
34from nova.api.openstack import images34from nova.api.openstack import images
35from nova.api.openstack import xmlutil35from nova.api.openstack import xmlutil
36from nova.api.openstack.views import images as images_view
36from nova import test37from nova import test
38from nova import utils
37from nova.tests.api.openstack import fakes39from nova.tests.api.openstack import fakes
3840
3941
@@ -119,6 +121,7 @@
119121
120 href = "http://localhost/v1.1/fake/images/124"122 href = "http://localhost/v1.1/fake/images/124"
121 bookmark = "http://localhost/fake/images/124"123 bookmark = "http://localhost/fake/images/124"
124 alternate = "%s/fake/images/124" % utils.generate_glance_url()
122 server_href = "http://localhost/v1.1/servers/42"125 server_href = "http://localhost/v1.1/servers/42"
123 server_bookmark = "http://localhost/servers/42"126 server_bookmark = "http://localhost/servers/42"
124127
@@ -152,6 +155,11 @@
152 {155 {
153 "rel": "bookmark",156 "rel": "bookmark",
154 "href": bookmark,157 "href": bookmark,
158 },
159 {
160 "rel": "alternate",
161 "type": "application/vnd.openstack.image",
162 "href": alternate
155 }],163 }],
156 },164 },
157 }165 }
@@ -289,6 +297,12 @@
289 "rel": "bookmark",297 "rel": "bookmark",
290 "href": "http://localhost/fake/images/123",298 "href": "http://localhost/fake/images/123",
291 },299 },
300 {
301 "rel": "alternate",
302 "type": "application/vnd.openstack.image",
303 "href": "%s/fake/images/123" %
304 utils.generate_glance_url()
305 },
292 ],306 ],
293 },307 },
294 {308 {
@@ -303,6 +317,12 @@
303 "rel": "bookmark",317 "rel": "bookmark",
304 "href": "http://localhost/fake/images/124",318 "href": "http://localhost/fake/images/124",
305 },319 },
320 {
321 "rel": "alternate",
322 "type": "application/vnd.openstack.image",
323 "href": "%s/fake/images/124" %
324 utils.generate_glance_url()
325 },
306 ],326 ],
307 },327 },
308 {328 {
@@ -317,6 +337,12 @@
317 "rel": "bookmark",337 "rel": "bookmark",
318 "href": "http://localhost/fake/images/125",338 "href": "http://localhost/fake/images/125",
319 },339 },
340 {
341 "rel": "alternate",
342 "type": "application/vnd.openstack.image",
343 "href": "%s/fake/images/125" %
344 utils.generate_glance_url()
345 },
320 ],346 ],
321 },347 },
322 {348 {
@@ -331,6 +357,12 @@
331 "rel": "bookmark",357 "rel": "bookmark",
332 "href": "http://localhost/fake/images/126",358 "href": "http://localhost/fake/images/126",
333 },359 },
360 {
361 "rel": "alternate",
362 "type": "application/vnd.openstack.image",
363 "href": "%s/fake/images/126" %
364 utils.generate_glance_url()
365 },
334 ],366 ],
335 },367 },
336 {368 {
@@ -345,6 +377,12 @@
345 "rel": "bookmark",377 "rel": "bookmark",
346 "href": "http://localhost/fake/images/127",378 "href": "http://localhost/fake/images/127",
347 },379 },
380 {
381 "rel": "alternate",
382 "type": "application/vnd.openstack.image",
383 "href": "%s/fake/images/127" %
384 utils.generate_glance_url()
385 },
348 ],386 ],
349 },387 },
350 {388 {
@@ -359,6 +397,12 @@
359 "rel": "bookmark",397 "rel": "bookmark",
360 "href": "http://localhost/fake/images/128",398 "href": "http://localhost/fake/images/128",
361 },399 },
400 {
401 "rel": "alternate",
402 "type": "application/vnd.openstack.image",
403 "href": "%s/fake/images/128" %
404 utils.generate_glance_url()
405 },
362 ],406 ],
363 },407 },
364 {408 {
@@ -373,6 +417,12 @@
373 "rel": "bookmark",417 "rel": "bookmark",
374 "href": "http://localhost/fake/images/129",418 "href": "http://localhost/fake/images/129",
375 },419 },
420 {
421 "rel": "alternate",
422 "type": "application/vnd.openstack.image",
423 "href": "%s/fake/images/129" %
424 utils.generate_glance_url()
425 },
376 ],426 ],
377 },427 },
378 {428 {
@@ -387,6 +437,12 @@
387 "rel": "bookmark",437 "rel": "bookmark",
388 "href": "http://localhost/fake/images/130",438 "href": "http://localhost/fake/images/130",
389 },439 },
440 {
441 "rel": "alternate",
442 "type": "application/vnd.openstack.image",
443 "href": "%s/fake/images/130" %
444 utils.generate_glance_url()
445 },
390 ],446 ],
391 },447 },
392 ]448 ]
@@ -493,6 +549,11 @@
493 {549 {
494 "rel": "bookmark",550 "rel": "bookmark",
495 "href": "http://localhost/fake/images/123",551 "href": "http://localhost/fake/images/123",
552 },
553 {
554 "rel": "alternate",
555 "type": "application/vnd.openstack.image",
556 "href": "%s/fake/images/123" % utils.generate_glance_url()
496 }],557 }],
497 },558 },
498 {559 {
@@ -524,6 +585,11 @@
524 {585 {
525 "rel": "bookmark",586 "rel": "bookmark",
526 "href": "http://localhost/fake/images/124",587 "href": "http://localhost/fake/images/124",
588 },
589 {
590 "rel": "alternate",
591 "type": "application/vnd.openstack.image",
592 "href": "%s/fake/images/124" % utils.generate_glance_url()
527 }],593 }],
528 },594 },
529 {595 {
@@ -555,6 +621,11 @@
555 {621 {
556 "rel": "bookmark",622 "rel": "bookmark",
557 "href": "http://localhost/fake/images/125",623 "href": "http://localhost/fake/images/125",
624 },
625 {
626 "rel": "alternate",
627 "type": "application/vnd.openstack.image",
628 "href": "%s/fake/images/125" % utils.generate_glance_url()
558 }],629 }],
559 },630 },
560 {631 {
@@ -586,6 +657,11 @@
586 {657 {
587 "rel": "bookmark",658 "rel": "bookmark",
588 "href": "http://localhost/fake/images/126",659 "href": "http://localhost/fake/images/126",
660 },
661 {
662 "rel": "alternate",
663 "type": "application/vnd.openstack.image",
664 "href": "%s/fake/images/126" % utils.generate_glance_url()
589 }],665 }],
590 },666 },
591 {667 {
@@ -617,6 +693,11 @@
617 {693 {
618 "rel": "bookmark",694 "rel": "bookmark",
619 "href": "http://localhost/fake/images/127",695 "href": "http://localhost/fake/images/127",
696 },
697 {
698 "rel": "alternate",
699 "type": "application/vnd.openstack.image",
700 "href": "%s/fake/images/127" % utils.generate_glance_url()
620 }],701 }],
621 },702 },
622 {703 {
@@ -648,6 +729,11 @@
648 {729 {
649 "rel": "bookmark",730 "rel": "bookmark",
650 "href": "http://localhost/fake/images/128",731 "href": "http://localhost/fake/images/128",
732 },
733 {
734 "rel": "alternate",
735 "type": "application/vnd.openstack.image",
736 "href": "%s/fake/images/128" % utils.generate_glance_url()
651 }],737 }],
652 },738 },
653 {739 {
@@ -679,6 +765,11 @@
679 {765 {
680 "rel": "bookmark",766 "rel": "bookmark",
681 "href": "http://localhost/fake/images/129",767 "href": "http://localhost/fake/images/129",
768 },
769 {
770 "rel": "alternate",
771 "type": "application/vnd.openstack.image",
772 "href": "%s/fake/images/129" % utils.generate_glance_url()
682 }],773 }],
683 },774 },
684 {775 {
@@ -696,6 +787,11 @@
696 {787 {
697 "rel": "bookmark",788 "rel": "bookmark",
698 "href": "http://localhost/fake/images/130",789 "href": "http://localhost/fake/images/130",
790 },
791 {
792 "rel": "alternate",
793 "type": "application/vnd.openstack.image",
794 "href": "%s/fake/images/130" % utils.generate_glance_url()
699 }],795 }],
700 },796 },
701 ]797 ]
@@ -963,6 +1059,12 @@
963 response = req.get_response(fakes.wsgi_app())1059 response = req.get_response(fakes.wsgi_app())
964 self.assertEqual(400, response.status_int)1060 self.assertEqual(400, response.status_int)
9651061
1062 def test_generate_alternate(self):
1063 view = images_view.ViewBuilderV11(1)
1064 generated_url = view.generate_alternate(1)
1065 actual_url = "%s//images/1" % utils.generate_glance_url()
1066 self.assertEqual(generated_url, actual_url)
1067
9661068
967class ImageXMLSerializationTest(test.TestCase):1069class ImageXMLSerializationTest(test.TestCase):
9681070
9691071
=== modified file 'nova/tests/test_utils.py'
--- nova/tests/test_utils.py 2011-08-23 15:07:25 +0000
+++ nova/tests/test_utils.py 2011-09-20 21:24:24 +0000
@@ -20,10 +20,14 @@
2020
21import nova21import nova
22from nova import exception22from nova import exception
23from nova import flags
23from nova import test24from nova import test
24from nova import utils25from nova import utils
2526
2627
28FLAGS = flags.FLAGS
29
30
27class ExecuteTestCase(test.TestCase):31class ExecuteTestCase(test.TestCase):
28 def test_retry_on_failure(self):32 def test_retry_on_failure(self):
29 fd, tmpfilename = tempfile.mkstemp()33 fd, tmpfilename = tempfile.mkstemp()
@@ -291,6 +295,11 @@
291 self.assertFalse(utils.bool_from_str(None))295 self.assertFalse(utils.bool_from_str(None))
292 self.assertFalse(utils.bool_from_str('junk'))296 self.assertFalse(utils.bool_from_str('junk'))
293297
298 def test_generate_glance_url(self):
299 generated_url = utils.generate_glance_url()
300 actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
301 self.assertEqual(generated_url, actual_url)
302
294303
295class IsUUIDLikeTestCase(test.TestCase):304class IsUUIDLikeTestCase(test.TestCase):
296 def assertUUIDLike(self, val, expected):305 def assertUUIDLike(self, val, expected):
297306
=== modified file 'nova/utils.py'
--- nova/utils.py 2011-09-02 18:00:33 +0000
+++ nova/utils.py 2011-09-20 21:24:24 +0000
@@ -910,3 +910,10 @@
910 if not isinstance(lst, list):910 if not isinstance(lst, list):
911 lst = [lst]911 lst = [lst]
912 return [{label: x} for x in lst]912 return [{label: x} for x in lst]
913
914
915def generate_glance_url():
916 """Generate the URL to glance."""
917 # TODO(jk0): This will eventually need to take SSL into consideration
918 # when supported in glance.
919 return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)