summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-08-10 02:01:03 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-08-10 02:01:03 -0400
commit434801e22bbfe2d8e74e18773c109ee657b22616 (patch)
treef7f131e3c58a2811f0de2f6ffc6163407246c98c
parente68ace1d6f7cb6db842aae69faa89cb4679016e7 (diff)
added project_id for flavors requests links
-rw-r--r--nova/api/openstack/flavors.py3
-rw-r--r--nova/api/openstack/images.py6
-rw-r--r--nova/api/openstack/servers.py2
-rw-r--r--nova/tests/api/openstack/test_flavors.py80
4 files changed, 52 insertions, 39 deletions
diff --git a/nova/api/openstack/flavors.py b/nova/api/openstack/flavors.py
index b4bda68d4..fd36060da 100644
--- a/nova/api/openstack/flavors.py
+++ b/nova/api/openstack/flavors.py
@@ -72,7 +72,8 @@ class ControllerV11(Controller):
def _get_view_builder(self, req):
base_url = req.application_url
- return views.flavors.ViewBuilderV11(base_url)
+ project_id = getattr(req.environ['nova.context'], 'project_id', '')
+ return views.flavors.ViewBuilderV11(base_url, project_id)
class FlavorXMLSerializer(wsgi.XMLDictSerializer):
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index ea4209e16..1c8fc10c9 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -166,10 +166,10 @@ class ControllerV10(Controller):
class ControllerV11(Controller):
"""Version 1.1 specific controller logic."""
- def get_builder(self, request):
+ def get_builder(self, req):
"""Property to get the ViewBuilder class we need to use."""
- base_url = request.application_url
- project_id = request.environ['nova.context'].project_id
+ base_url = req.application_url
+ project_id = getattr(req.environ['nova.context'], 'project_id', '')
return images_view.ViewBuilderV11(base_url, project_id)
def index(self, req):
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index a516173d0..45d7dc214 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -639,7 +639,7 @@ class ControllerV11(Controller):
return common.get_id_from_href(flavor_ref)
def _build_view(self, req, instance, is_detail=False):
- project_id = req.environ['nova.context'].project_id
+ project_id = getattr(req.environ['nova.context'], 'project_id', '')
base_url = req.application_url
flavor_builder = nova.api.openstack.views.flavors.ViewBuilderV11(
base_url, project_id)
diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py
index 15c552e72..2db69f4e3 100644
--- a/nova/tests/api/openstack/test_flavors.py
+++ b/nova/tests/api/openstack/test_flavors.py
@@ -152,11 +152,11 @@ class FlavorsTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/12",
+ "href": "http://localhost/v1.1/fake/flavors/12",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/12",
+ "href": "http://localhost/fake/flavors/12",
},
],
},
@@ -177,11 +177,11 @@ class FlavorsTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/1",
+ "href": "http://localhost/v1.1/fake/flavors/1",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/1",
+ "href": "http://localhost/fake/flavors/1",
},
],
},
@@ -191,11 +191,11 @@ class FlavorsTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/2",
+ "href": "http://localhost/v1.1/fake/flavors/2",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/2",
+ "href": "http://localhost/fake/flavors/2",
},
],
},
@@ -219,11 +219,11 @@ class FlavorsTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/1",
+ "href": "http://localhost/v1.1/fake/flavors/1",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/1",
+ "href": "http://localhost/fake/flavors/1",
},
],
},
@@ -235,11 +235,11 @@ class FlavorsTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/2",
+ "href": "http://localhost/v1.1/fake/flavors/2",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/2",
+ "href": "http://localhost/fake/flavors/2",
},
],
},
@@ -274,11 +274,11 @@ class FlavorsXMLSerializationTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/12",
+ "href": "http://localhost/v1.1/fake/flavors/12",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/12",
+ "href": "http://localhost/fake/flavors/12",
},
],
},
@@ -294,8 +294,10 @@ class FlavorsXMLSerializationTest(test.TestCase):
name="asdf"
ram="256"
disk="10">
- <atom:link href="http://localhost/v1.1/flavors/12" rel="self"/>
- <atom:link href="http://localhost/flavors/12" rel="bookmark"/>
+ <atom:link href="http://localhost/v1.1/fake/flavors/12"
+ rel="self"/>
+ <atom:link href="http://localhost/fake/flavors/12"
+ rel="bookmark"/>
</flavor>
""".replace(" ", ""))
@@ -313,11 +315,11 @@ class FlavorsXMLSerializationTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/12",
+ "href": "http://localhost/v1.1/fake/flavors/12",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/12",
+ "href": "http://localhost/fake/flavors/12",
},
],
},
@@ -333,8 +335,10 @@ class FlavorsXMLSerializationTest(test.TestCase):
name="asdf"
ram="256"
disk="10">
- <atom:link href="http://localhost/v1.1/flavors/12" rel="self"/>
- <atom:link href="http://localhost/flavors/12" rel="bookmark"/>
+ <atom:link href="http://localhost/v1.1/fake/flavors/12"
+ rel="self"/>
+ <atom:link href="http://localhost/fake/flavors/12"
+ rel="bookmark"/>
</flavor>
""".replace(" ", ""))
@@ -353,11 +357,11 @@ class FlavorsXMLSerializationTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/23",
+ "href": "http://localhost/v1.1/fake/flavors/23",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/23",
+ "href": "http://localhost/fake/flavors/23",
},
],
}, {
@@ -368,11 +372,11 @@ class FlavorsXMLSerializationTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/13",
+ "href": "http://localhost/v1.1/fake/flavors/13",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/13",
+ "href": "http://localhost/fake/flavors/13",
},
],
},
@@ -389,15 +393,19 @@ class FlavorsXMLSerializationTest(test.TestCase):
name="flavor 23"
ram="512"
disk="20">
- <atom:link href="http://localhost/v1.1/flavors/23" rel="self"/>
- <atom:link href="http://localhost/flavors/23" rel="bookmark"/>
+ <atom:link href="http://localhost/v1.1/fake/flavors/23"
+ rel="self"/>
+ <atom:link href="http://localhost/fake/flavors/23"
+ rel="bookmark"/>
</flavor>
<flavor id="13"
name="flavor 13"
ram="256"
disk="10">
- <atom:link href="http://localhost/v1.1/flavors/13" rel="self"/>
- <atom:link href="http://localhost/flavors/13" rel="bookmark"/>
+ <atom:link href="http://localhost/v1.1/fake/flavors/13"
+ rel="self"/>
+ <atom:link href="http://localhost/fake/flavors/13"
+ rel="bookmark"/>
</flavor>
</flavors>
""".replace(" ", "") % locals())
@@ -417,11 +425,11 @@ class FlavorsXMLSerializationTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/23",
+ "href": "http://localhost/v1.1/fake/flavors/23",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/23",
+ "href": "http://localhost/fake/flavors/23",
},
],
}, {
@@ -432,11 +440,11 @@ class FlavorsXMLSerializationTest(test.TestCase):
"links": [
{
"rel": "self",
- "href": "http://localhost/v1.1/flavors/13",
+ "href": "http://localhost/v1.1/fake/flavors/13",
},
{
"rel": "bookmark",
- "href": "http://localhost/flavors/13",
+ "href": "http://localhost/fake/flavors/13",
},
],
},
@@ -450,12 +458,16 @@ class FlavorsXMLSerializationTest(test.TestCase):
<flavors xmlns="http://docs.openstack.org/compute/api/v1.1"
xmlns:atom="http://www.w3.org/2005/Atom">
<flavor id="23" name="flavor 23">
- <atom:link href="http://localhost/v1.1/flavors/23" rel="self"/>
- <atom:link href="http://localhost/flavors/23" rel="bookmark"/>
+ <atom:link href="http://localhost/v1.1/fake/flavors/23"
+ rel="self"/>
+ <atom:link href="http://localhost/fake/flavors/23"
+ rel="bookmark"/>
</flavor>
<flavor id="13" name="flavor 13">
- <atom:link href="http://localhost/v1.1/flavors/13" rel="self"/>
- <atom:link href="http://localhost/flavors/13" rel="bookmark"/>
+ <atom:link href="http://localhost/v1.1/fake/flavors/13"
+ rel="self"/>
+ <atom:link href="http://localhost/fake/flavors/13"
+ rel="bookmark"/>
</flavor>
</flavors>
""".replace(" ", "") % locals())