From 81ea3d5fc47bed84c5f4bf722b02dfa58792e19e Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 29 Jun 2011 18:26:51 -0400 Subject: Updated v1.1 links in flavors to represent the curret spec --- nova/api/openstack/views/flavors.py | 2 -- nova/tests/api/openstack/test_flavors.py | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index 462890ab2..beef67a88 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -79,12 +79,10 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", "href": href, }, { "rel": "bookmark", - "type": "application/xml", "href": href, }, ] diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py index d1c62e454..47e6a3fd3 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/test_flavors.py @@ -146,12 +146,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/12", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/12", }, ], @@ -175,12 +173,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/1", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/1", }, ], @@ -195,12 +191,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/2", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/2", }, ], @@ -227,12 +221,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/1", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/1", }, ], @@ -249,12 +241,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/2", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/2", }, ], -- cgit From 8133b9af105f7924f03b710b30cf4f0acb52f143 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 10:29:31 -0400 Subject: refactored flavors viewbuilder --- nova/api/openstack/views/flavors.py | 15 ++++++++++----- nova/tests/api/openstack/test_flavors.py | 30 +++++------------------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index beef67a88..4e609930c 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -71,6 +71,7 @@ class ViewBuilderV11(ViewBuilder): def _build_links(self, flavor_obj): """Generate a container of links that refer to the provided flavor.""" href = self.generate_href(flavor_obj["id"]) + bookmark = self.generate_bookmark(flavor_obj["id"]) links = [ { @@ -79,11 +80,7 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "href": href, - }, - { - "rel": "bookmark", - "href": href, + "href": bookmark, }, ] @@ -92,3 +89,11 @@ class ViewBuilderV11(ViewBuilder): def generate_href(self, flavor_id): """Create an url that refers to a specific flavor id.""" return "%s/flavors/%s" % (self.base_url, flavor_id) + + def generate_bookmark(self, flavor_id): + """Create an url that refers to a specific flavor id.""" + return "%s/flavors/%s" % (self._remove_version(self.base_url), + flavor_id) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py index 47e6a3fd3..7b4bd12f3 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/test_flavors.py @@ -146,11 +146,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/12", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/12", + "href": "http://localhost/flavors/12", }, ], } @@ -173,11 +169,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", + "href": "http://localhost/flavors/1", }, ], }, @@ -191,11 +183,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", + "href": "http://localhost/flavors/2", }, ], }, @@ -221,11 +209,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", + "href": "http://localhost/flavors/1", }, ], }, @@ -241,11 +225,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", + "href": "http://localhost/flavors/2", }, ], }, -- cgit From 5f772ea10c22549a7149f608cfc2ff932878d6fe Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 11:18:19 -0400 Subject: updated servers --- nova/api/openstack/views/servers.py | 17 ++++++++++------- nova/tests/api/openstack/test_servers.py | 16 ++-------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index cbfa5aae7..1c6dbf87d 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -156,6 +156,7 @@ class ViewBuilderV11(ViewBuilder): def _build_links(self, response, inst): href = self.generate_href(inst["id"]) + bookmark = self.generate_bookmark(inst["id"]) links = [ { @@ -164,13 +165,7 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }, ] @@ -179,3 +174,11 @@ class ViewBuilderV11(ViewBuilder): def generate_href(self, server_id): """Create an url that refers to a specific server id.""" return os.path.join(self.base_url, "servers", str(server_id)) + + def generate_bookmark(self, server_id): + """Create an url that refers to a specific flavor id.""" + return os.path.join(self._remove_version(self.base_url), + "servers", str(server_id)) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index b53c6c9be..110445935 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -290,13 +290,7 @@ class ServersTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/servers/1", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/servers/1", + "href": "http://localhost/servers/1", }, ] @@ -514,13 +508,7 @@ class ServersTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/servers/%d" % (i,), - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/servers/%d" % (i,), + "href": "http://localhost/servers/%d" % (i,), }, ] -- cgit From 386e2a28f2d92dea30a726722b49e97e1c7ebba7 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 11:29:45 -0400 Subject: updated images --- nova/api/openstack/views/images.py | 17 ++++--- nova/tests/api/openstack/test_images.py | 78 ++++++--------------------------- 2 files changed, 24 insertions(+), 71 deletions(-) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index d6a054102..175bcb109 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -104,6 +104,7 @@ class ViewBuilderV11(ViewBuilder): """Return a standardized image structure for display by the API.""" image = ViewBuilder.build(self, image_obj, detail) href = self.generate_href(image_obj["id"]) + bookmark = self.generate_bookmark(image_obj["id"]) image["links"] = [{ "rel": "self", @@ -111,13 +112,15 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }] return image + + def generate_bookmark(self, image_id): + """Create an url that refers to a specific flavor id.""" + return os.path.join(self._remove_version(self._url), + "images", str(image_id)) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index e11e1c046..b864ae9f4 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -400,6 +400,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): actual_image = json.loads(response.body) href = "http://localhost/v1.1/images/123" + bookmark = "http://localhost/images/123" expected_image = { "image": { @@ -414,13 +415,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }], }, } @@ -473,6 +468,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): actual_image = minidom.parseString(response.body.replace(" ", "")) expected_href = "http://localhost/v1.1/images/123" + expected_bookmark = "http://localhost/images/123" expected_now = self.NOW_API_FORMAT expected_image = minidom.parseString(""" - - + """.replace(" ", "") % (locals())) @@ -580,22 +573,17 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): continue href = "http://localhost/v1.1/images/%s" % image["id"] + bookmark = "http://localhost/images/%s" % image["id"] test_image = { "id": image["id"], "name": image["name"], "links": [{ "rel": "self", - "href": "http://localhost/v1.1/images/%s" % image["id"], - }, - { - "rel": "bookmark", - "type": "application/json", "href": href, }, { "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }], } self.assertTrue(test_image in response_list) @@ -674,13 +662,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/123", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/123", + "href": "http://localhost/images/123", }], }, { @@ -696,13 +678,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/124", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/124", + "href": "http://localhost/images/124", }], }, { @@ -719,13 +695,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/125", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/125", + "href": "http://localhost/images/125", }], }, { @@ -741,13 +711,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/126", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/126", + "href": "http://localhost/images/126", }], }, { @@ -763,13 +727,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/127", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/127", + "href": "http://localhost/images/127", }], }, { @@ -784,13 +742,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/129", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/129", + "href": "http://localhost/images/129", }], }, ] @@ -1120,6 +1072,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): self.assertEqual(200, response.status_int) resp_xml = minidom.parseString(response.body.replace(" ", "")) expected_href = "http://localhost/v1.1/images/123" + expected_bookmark = "http://localhost/images/123" expected_image = minidom.parseString(""" - - + """.replace(" ", "") % (locals())) -- cgit From a92158cee2a57316252ec6fd0d6c0c4f1e7a1fcf Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 09:26:25 -0400 Subject: moved remove_version to common.py --- nova/api/openstack/common.py | 3 +++ nova/api/openstack/views/flavors.py | 5 +---- nova/api/openstack/views/images.py | 7 +++---- nova/api/openstack/views/servers.py | 5 +---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index aa8911b62..8794bca6d 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -134,3 +134,6 @@ def get_id_from_href(href): except: LOG.debug(_("Error extracting id from href: %s") % href) raise webob.exc.HTTPBadRequest(_('could not parse id from href')) + +def remove_version(base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index 4e609930c..d967c2af0 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,8 +92,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (self._remove_version(self.base_url), + return "%s/flavors/%s" % (common.remove_version(self.base_url), flavor_id) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 5ab02671c..9d6722326 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -17,6 +17,8 @@ import os.path +from nova.api.openstack import common + class ViewBuilder(object): """Base class for generating responses to OpenStack API image requests.""" @@ -122,8 +124,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, image_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(self._remove_version(self._url), + return os.path.join(common.remove_version(self._url), "images", str(image_id)) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 1c6dbf87d..b85fceb19 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -177,8 +177,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, server_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(self._remove_version(self.base_url), + return os.path.join(common.remove_version(self.base_url), "servers", str(server_id)) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) -- cgit From bf851c7f403c7be8d8f27274fa5216cfa6eaf4f4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 09:42:13 -0400 Subject: Renamed function --- nova/api/openstack/common.py | 9 ++++++++- nova/api/openstack/views/flavors.py | 2 +- nova/api/openstack/views/images.py | 2 +- nova/api/openstack/views/servers.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 8794bca6d..48773291c 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -135,5 +135,12 @@ def get_id_from_href(href): LOG.debug(_("Error extracting id from href: %s") % href) raise webob.exc.HTTPBadRequest(_('could not parse id from href')) -def remove_version(base_url): + +def remove_version_from_href(base_url): + """Removes the api version from the href. + + Given: 'http://www.nova.com/v1.1/123' + Returns: 'http://www.nova.com/123' + + """ return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index d967c2af0..d2f7e3e56 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,5 +92,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (common.remove_version(self.base_url), + return "%s/flavors/%s" % (common.remove_version_from_href(self.base_url), flavor_id) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 9d6722326..005341c62 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -124,5 +124,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, image_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(common.remove_version(self._url), + return os.path.join(common.remove_version_from_href(self._url), "images", str(image_id)) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index b85fceb19..67fb6a84e 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -177,5 +177,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, server_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(common.remove_version(self.base_url), + return os.path.join(common.remove_version_from_href(self.base_url), "servers", str(server_id)) -- cgit From 19e4cef2518e2c1e02e27137cadea55861d092c4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 10:02:06 -0400 Subject: pep8 --- nova/api/openstack/common.py | 2 +- nova/api/openstack/views/flavors.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 48773291c..9aa384f33 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -138,7 +138,7 @@ def get_id_from_href(href): def remove_version_from_href(base_url): """Removes the api version from the href. - + Given: 'http://www.nova.com/v1.1/123' Returns: 'http://www.nova.com/123' diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index d2f7e3e56..0403ece1b 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,5 +92,7 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (common.remove_version_from_href(self.base_url), - flavor_id) + return "%s/flavors/%s" % ( + common.remove_version_from_href(self.base_url), + flavor_id, + ) -- cgit