summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-09-20 13:56:15 -0500
committerJosh Kearney <josh@jk0.org>2011-09-20 13:56:15 -0500
commit13e346df0bc88279242ed1c56ad39b36a22c8a39 (patch)
tree5c14a1720772cfb36e6bce9b4ccf79ae7580c091
parentbb018b14fb8786090b2cf8b23723fa97defef9ce (diff)
downloadnova-13e346df0bc88279242ed1c56ad39b36a22c8a39.tar.gz
nova-13e346df0bc88279242ed1c56ad39b36a22c8a39.tar.xz
nova-13e346df0bc88279242ed1c56ad39b36a22c8a39.zip
Refactored alternate link generation.
-rw-r--r--nova/api/openstack/views/images.py19
-rw-r--r--nova/image/glance.py7
-rw-r--r--nova/tests/api/openstack/test_images.py14
-rw-r--r--nova/tests/image/test_glance.py11
4 files changed, 32 insertions, 19 deletions
diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py
index 86e8d7f3a..c41123f5e 100644
--- a/nova/api/openstack/views/images.py
+++ b/nova/api/openstack/views/images.py
@@ -18,6 +18,10 @@
import os.path
from nova.api.openstack import common
+from nova import flags
+
+
+FLAGS = flags.FLAGS
class ViewBuilder(object):
@@ -139,6 +143,7 @@ class ViewBuilderV11(ViewBuilder):
image = ViewBuilder.build(self, image_obj, detail)
href = self.generate_href(image_obj["id"])
bookmark = self.generate_bookmark(image_obj["id"])
+ alternate = self.generate_alternate(image_obj["id"])
image["links"] = [
{
@@ -149,6 +154,11 @@ class ViewBuilderV11(ViewBuilder):
"rel": "bookmark",
"href": bookmark,
},
+ {
+ "rel": "alternate",
+ "type": "application/vnd.openstack.image",
+ "href": alternate,
+ },
]
@@ -158,6 +168,13 @@ class ViewBuilderV11(ViewBuilder):
return image
def generate_bookmark(self, image_id):
- """Create an url that refers to a specific flavor id."""
+ """Create a URL that refers to a specific flavor id."""
return os.path.join(common.remove_version_from_href(self.base_url),
self.project_id, "images", str(image_id))
+
+ def generate_alternate(self, image_id):
+ """Create an alternate link for a specific flavor id."""
+ # TODO(jk0): This will eventually need to take SSL into consideration
+ # when supported in glance.
+ return "http://%s:%d/%s/images/%s" % (FLAGS.glance_host,
+ FLAGS.glance_port, self.project_id, str(image_id))
diff --git a/nova/image/glance.py b/nova/image/glance.py
index e4d9edc93..5ee1d2b8a 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -42,13 +42,6 @@ FLAGS = flags.FLAGS
GlanceClient = utils.import_class('glance.client.Client')
-def _construct_glance_url():
- """Generate the default URL to glance."""
- # TODO(jk0): This will eventually need to take SSL into consideration
- # when supported in glance.
- return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
-
-
def _parse_image_ref(image_href):
"""Parse an image href into composite parts.
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index e5fd4764a..7053db37d 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -30,13 +30,18 @@ import stubout
import webob
from nova import context
+from nova import flags
import nova.api.openstack
from nova.api.openstack import images
from nova.api.openstack import xmlutil
+from nova.api.openstack.views import images as images_view
from nova import test
from nova.tests.api.openstack import fakes
+FLAGS = flags.FLAGS
+
+
NS = "{http://docs.openstack.org/compute/api/v1.1}"
ATOMNS = "{http://www.w3.org/2005/Atom}"
NOW_API_FORMAT = "2010-10-11T10:30:22Z"
@@ -963,6 +968,15 @@ class ImagesTest(test.TestCase):
response = req.get_response(fakes.wsgi_app())
self.assertEqual(400, response.status_int)
+ def test_generate_alternate(self):
+ # TODO(jk0): This will eventually need to take SSL into consideration
+ # when supported in glance.
+ view = images_view.ViewBuilderV11(1)
+ generated_url = view.generate_alternate(1)
+ actual_url = "http://%s:%d//images/1" % (FLAGS.glance_host,
+ FLAGS.glance_port)
+ self.assertEqual(generated_url, actual_url)
+
class ImageXMLSerializationTest(test.TestCase):
diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py
index 9f866d790..290c9a04a 100644
--- a/nova/tests/image/test_glance.py
+++ b/nova/tests/image/test_glance.py
@@ -22,15 +22,11 @@ import stubout
from nova.tests.api.openstack import fakes
from nova import context
from nova import exception
-from nova import flags
from nova.image import glance
from nova import test
from nova.tests.glance import stubs as glance_stubs
-FLAGS = flags.FLAGS
-
-
class NullWriter(object):
"""Used to test ImageService.get which takes a writer object"""
@@ -455,10 +451,3 @@ class TestGlanceImageService(test.TestCase):
image_meta = self.service.get(self.context, image_id, writer)
self.assertEqual(image_meta['created_at'], self.NOW_DATETIME)
self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME)
-
- def test_contruct_glance_url(self):
- # TODO(jk0): This will eventually need to take SSL into consideration
- # when supported in glance.
- generated_url = glance._construct_glance_url()
- actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
- self.assertEqual(generated_url, actual_url)