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
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 elem = etree.SubElement(image_elem,
6 '{%s}link' % xmlutil.XMLNS_ATOM)
7 elem.set('rel', link['rel'])
8+ if 'type' in link:
9+ elem.set('type', link['type'])
10 elem.set('href', link['href'])
11 return image_elem
12
13
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 import os.path
19
20 from nova.api.openstack import common
21+from nova import utils
22
23
24 class ViewBuilder(object):
25@@ -139,6 +140,7 @@
26 image = ViewBuilder.build(self, image_obj, detail)
27 href = self.generate_href(image_obj["id"])
28 bookmark = self.generate_bookmark(image_obj["id"])
29+ alternate = self.generate_alternate(image_obj["id"])
30
31 image["links"] = [
32 {
33@@ -149,6 +151,11 @@
34 "rel": "bookmark",
35 "href": bookmark,
36 },
37+ {
38+ "rel": "alternate",
39+ "type": "application/vnd.openstack.image",
40+ "href": alternate,
41+ },
42
43 ]
44
45@@ -158,6 +165,13 @@
46 return image
47
48 def generate_bookmark(self, image_id):
49- """Create an url that refers to a specific flavor id."""
50+ """Create a URL that refers to a specific flavor id."""
51 return os.path.join(common.remove_version_from_href(self.base_url),
52 self.project_id, "images", str(image_id))
53+
54+ def generate_alternate(self, image_id):
55+ """Create an alternate link for a specific flavor id."""
56+ glance_url = utils.generate_glance_url()
57+
58+ return "%s/%s/images/%s" % (glance_url, self.project_id,
59+ str(image_id))
60
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 DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID')
66 DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key')
67 # NOTE(sirp): my_ip interpolation doesn't work within nested structures
68+DEFINE_string('glance_host', _get_my_ip(), 'default glance host')
69+DEFINE_integer('glance_port', 9292, 'default glance port')
70 DEFINE_list('glance_api_servers',
71- ['%s:9292' % _get_my_ip()],
72+ ['%s:%d' % (FLAGS.glance_host, FLAGS.glance_port)],
73 'list of glance api servers available to nova (host:port)')
74 DEFINE_integer('s3_port', 3333, 's3 port')
75 DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)')
76
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 import nova.api.openstack
82 from nova.api.openstack import images
83 from nova.api.openstack import xmlutil
84+from nova.api.openstack.views import images as images_view
85 from nova import test
86+from nova import utils
87 from nova.tests.api.openstack import fakes
88
89
90@@ -119,6 +121,7 @@
91
92 href = "http://localhost/v1.1/fake/images/124"
93 bookmark = "http://localhost/fake/images/124"
94+ alternate = "%s/fake/images/124" % utils.generate_glance_url()
95 server_href = "http://localhost/v1.1/servers/42"
96 server_bookmark = "http://localhost/servers/42"
97
98@@ -152,6 +155,11 @@
99 {
100 "rel": "bookmark",
101 "href": bookmark,
102+ },
103+ {
104+ "rel": "alternate",
105+ "type": "application/vnd.openstack.image",
106+ "href": alternate
107 }],
108 },
109 }
110@@ -289,6 +297,12 @@
111 "rel": "bookmark",
112 "href": "http://localhost/fake/images/123",
113 },
114+ {
115+ "rel": "alternate",
116+ "type": "application/vnd.openstack.image",
117+ "href": "%s/fake/images/123" %
118+ utils.generate_glance_url()
119+ },
120 ],
121 },
122 {
123@@ -303,6 +317,12 @@
124 "rel": "bookmark",
125 "href": "http://localhost/fake/images/124",
126 },
127+ {
128+ "rel": "alternate",
129+ "type": "application/vnd.openstack.image",
130+ "href": "%s/fake/images/124" %
131+ utils.generate_glance_url()
132+ },
133 ],
134 },
135 {
136@@ -317,6 +337,12 @@
137 "rel": "bookmark",
138 "href": "http://localhost/fake/images/125",
139 },
140+ {
141+ "rel": "alternate",
142+ "type": "application/vnd.openstack.image",
143+ "href": "%s/fake/images/125" %
144+ utils.generate_glance_url()
145+ },
146 ],
147 },
148 {
149@@ -331,6 +357,12 @@
150 "rel": "bookmark",
151 "href": "http://localhost/fake/images/126",
152 },
153+ {
154+ "rel": "alternate",
155+ "type": "application/vnd.openstack.image",
156+ "href": "%s/fake/images/126" %
157+ utils.generate_glance_url()
158+ },
159 ],
160 },
161 {
162@@ -345,6 +377,12 @@
163 "rel": "bookmark",
164 "href": "http://localhost/fake/images/127",
165 },
166+ {
167+ "rel": "alternate",
168+ "type": "application/vnd.openstack.image",
169+ "href": "%s/fake/images/127" %
170+ utils.generate_glance_url()
171+ },
172 ],
173 },
174 {
175@@ -359,6 +397,12 @@
176 "rel": "bookmark",
177 "href": "http://localhost/fake/images/128",
178 },
179+ {
180+ "rel": "alternate",
181+ "type": "application/vnd.openstack.image",
182+ "href": "%s/fake/images/128" %
183+ utils.generate_glance_url()
184+ },
185 ],
186 },
187 {
188@@ -373,6 +417,12 @@
189 "rel": "bookmark",
190 "href": "http://localhost/fake/images/129",
191 },
192+ {
193+ "rel": "alternate",
194+ "type": "application/vnd.openstack.image",
195+ "href": "%s/fake/images/129" %
196+ utils.generate_glance_url()
197+ },
198 ],
199 },
200 {
201@@ -387,6 +437,12 @@
202 "rel": "bookmark",
203 "href": "http://localhost/fake/images/130",
204 },
205+ {
206+ "rel": "alternate",
207+ "type": "application/vnd.openstack.image",
208+ "href": "%s/fake/images/130" %
209+ utils.generate_glance_url()
210+ },
211 ],
212 },
213 ]
214@@ -493,6 +549,11 @@
215 {
216 "rel": "bookmark",
217 "href": "http://localhost/fake/images/123",
218+ },
219+ {
220+ "rel": "alternate",
221+ "type": "application/vnd.openstack.image",
222+ "href": "%s/fake/images/123" % utils.generate_glance_url()
223 }],
224 },
225 {
226@@ -524,6 +585,11 @@
227 {
228 "rel": "bookmark",
229 "href": "http://localhost/fake/images/124",
230+ },
231+ {
232+ "rel": "alternate",
233+ "type": "application/vnd.openstack.image",
234+ "href": "%s/fake/images/124" % utils.generate_glance_url()
235 }],
236 },
237 {
238@@ -555,6 +621,11 @@
239 {
240 "rel": "bookmark",
241 "href": "http://localhost/fake/images/125",
242+ },
243+ {
244+ "rel": "alternate",
245+ "type": "application/vnd.openstack.image",
246+ "href": "%s/fake/images/125" % utils.generate_glance_url()
247 }],
248 },
249 {
250@@ -586,6 +657,11 @@
251 {
252 "rel": "bookmark",
253 "href": "http://localhost/fake/images/126",
254+ },
255+ {
256+ "rel": "alternate",
257+ "type": "application/vnd.openstack.image",
258+ "href": "%s/fake/images/126" % utils.generate_glance_url()
259 }],
260 },
261 {
262@@ -617,6 +693,11 @@
263 {
264 "rel": "bookmark",
265 "href": "http://localhost/fake/images/127",
266+ },
267+ {
268+ "rel": "alternate",
269+ "type": "application/vnd.openstack.image",
270+ "href": "%s/fake/images/127" % utils.generate_glance_url()
271 }],
272 },
273 {
274@@ -648,6 +729,11 @@
275 {
276 "rel": "bookmark",
277 "href": "http://localhost/fake/images/128",
278+ },
279+ {
280+ "rel": "alternate",
281+ "type": "application/vnd.openstack.image",
282+ "href": "%s/fake/images/128" % utils.generate_glance_url()
283 }],
284 },
285 {
286@@ -679,6 +765,11 @@
287 {
288 "rel": "bookmark",
289 "href": "http://localhost/fake/images/129",
290+ },
291+ {
292+ "rel": "alternate",
293+ "type": "application/vnd.openstack.image",
294+ "href": "%s/fake/images/129" % utils.generate_glance_url()
295 }],
296 },
297 {
298@@ -696,6 +787,11 @@
299 {
300 "rel": "bookmark",
301 "href": "http://localhost/fake/images/130",
302+ },
303+ {
304+ "rel": "alternate",
305+ "type": "application/vnd.openstack.image",
306+ "href": "%s/fake/images/130" % utils.generate_glance_url()
307 }],
308 },
309 ]
310@@ -963,6 +1059,12 @@
311 response = req.get_response(fakes.wsgi_app())
312 self.assertEqual(400, response.status_int)
313
314+ def test_generate_alternate(self):
315+ view = images_view.ViewBuilderV11(1)
316+ generated_url = view.generate_alternate(1)
317+ actual_url = "%s//images/1" % utils.generate_glance_url()
318+ self.assertEqual(generated_url, actual_url)
319+
320
321 class ImageXMLSerializationTest(test.TestCase):
322
323
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
329 import nova
330 from nova import exception
331+from nova import flags
332 from nova import test
333 from nova import utils
334
335
336+FLAGS = flags.FLAGS
337+
338+
339 class ExecuteTestCase(test.TestCase):
340 def test_retry_on_failure(self):
341 fd, tmpfilename = tempfile.mkstemp()
342@@ -291,6 +295,11 @@
343 self.assertFalse(utils.bool_from_str(None))
344 self.assertFalse(utils.bool_from_str('junk'))
345
346+ def test_generate_glance_url(self):
347+ generated_url = utils.generate_glance_url()
348+ actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
349+ self.assertEqual(generated_url, actual_url)
350+
351
352 class IsUUIDLikeTestCase(test.TestCase):
353 def assertUUIDLike(self, val, expected):
354
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 if not isinstance(lst, list):
360 lst = [lst]
361 return [{label: x} for x in lst]
362+
363+
364+def generate_glance_url():
365+ """Generate the URL to glance."""
366+ # TODO(jk0): This will eventually need to take SSL into consideration
367+ # when supported in glance.
368+ return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)