summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Meade <alex.meade@rackspace.com>2011-07-14 14:01:04 -0400
committerAlex Meade <alex.meade@rackspace.com>2011-07-14 14:01:04 -0400
commit7044080daf2e487a92bba2a9f9b99e3cdb874e88 (patch)
tree569a0112f586efdf556de325f5c5e8730638f9a8
parent3041f2e9eb90e447adbb48827c2c85ca27d436e6 (diff)
updated image entity for servers requests
-rw-r--r--nova/api/openstack/views/servers.py37
-rw-r--r--nova/tests/api/openstack/test_servers.py98
2 files changed, 109 insertions, 26 deletions
diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py
index 3f13e469a..968a904d9 100644
--- a/nova/api/openstack/views/servers.py
+++ b/nova/api/openstack/views/servers.py
@@ -143,21 +143,28 @@ class ViewBuilderV11(ViewBuilder):
def _build_image(self, response, inst):
if 'image_ref' in dict(inst):
image_href = inst['image_ref']
- if str(image_href).isdigit():
- image_href = int(image_href)
- response['image'] = {
- "id": common.get_uuid_from_href(image_href),
- "links": [
- {
- "rel": "self",
- "href": image_href,
- },
- {
- "rel": "bookmark",
- "href": common.remove_version_from_href(image_href),
- },
- ]
- }
+ #if id is a uuid do:
+ if image_href == common.get_uuid_from_href(image_href):
+ image_id = image_href
+ _bookmark = self.image_builder.generate_bookmark(image_href)
+ response['image'] = {
+ "id": image_id,
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": _bookmark,
+ },
+ ]
+ }
+ else:
+ response['image'] = {
+ "links": [
+ {
+ "rel": "bookmark",
+ "href": image_href,
+ },
+ ]
+ }
def _build_flavor(self, response, inst):
if "instance_type" in dict(inst):
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index e00dd825e..2fe236291 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -281,7 +281,6 @@ class ServersTest(test.TestCase):
def test_get_server_by_id_v1_1(self):
self.maxDiff = None
- image_ref = "http://localhost/v1.1/images/10"
image_bookmark = "http://localhost/images/10"
flavor_ref = "http://localhost/v1.1/flavors/1"
flavor_id = "1"
@@ -294,7 +293,7 @@ class ServersTest(test.TestCase):
private_address=private,
public_addresses=public,
power_state=0,
- image_ref=image_ref,
+ image_ref=image_bookmark,
flavor_id=flavor_id,
)
self.stubs.Set(nova.db.api, 'instance_get', _return_server)
@@ -314,12 +313,93 @@ class ServersTest(test.TestCase):
#"accessIPv4" : "67.23.10.132",
#"accessIPv6" : "::babe:67.23.10.132",
"image": {
- "id": "10",
"links": [
{
- "rel": "self",
- "href": image_ref,
+ "rel": "bookmark",
+ "href": image_bookmark,
+ },
+ ],
+ },
+ "flavor": {
+ "id": "1",
+ "links": [
+ {
+ "rel": "self",
+ "href": flavor_ref,
+ },
+ {
+ "rel": "bookmark",
+ "href": flavor_bookmark,
+ },
+ ],
+ },
+ "addresses": {
+ "public": [
+ {
+ "version": 4,
+ "addr": public[0],
},
+ ],
+ "private":[
+ {
+ "version": 4,
+ "addr": private,
+ },
+ ],
+ },
+ "metadata": {
+ "seq": "1",
+ },
+ "links": [
+ {
+ "rel": "self",
+ "href": "http://localhost/v1.1/servers/1",
+ },
+ {
+ "rel": "bookmark",
+ "href": "http://localhost/servers/1",
+ },
+ ],
+ }
+ }
+
+ self.assertDictEqual(res_dict, expected_server)
+
+ def test_get_server_with_active_status_by_id_v1_1(self):
+ self.maxDiff = None
+ image_bookmark = "http://localhost/images/10"
+ flavor_ref = "http://localhost/v1.1/flavors/1"
+ flavor_id = "1"
+ flavor_bookmark = "http://localhost/flavors/1"
+ private = "192.168.0.3"
+ public = ["1.2.3.4"]
+ def _return_server(context, id):
+
+ return stub_instance(1,
+ private_address=private,
+ public_addresses=public,
+ power_state=1,
+ image_ref=image_bookmark,
+ flavor_id=flavor_id,
+ )
+ self.stubs.Set(nova.db.api, 'instance_get', _return_server)
+
+ req = webob.Request.blank('/v1.1/servers/1')
+ res = req.get_response(fakes.wsgi_app())
+ res_dict = json.loads(res.body)
+ expected_server = {
+ "server": {
+ "id": FAKE_UUID,
+ "updated": "2010-11-11T11:00:00Z",
+ "created": "2010-10-10T12:00:00Z",
+ "progress": 100,
+ "name": "server1",
+ "status": "ACTIVE",
+ "hostId": '',
+ #"accessIPv4" : "67.23.10.132",
+ #"accessIPv6" : "::babe:67.23.10.132",
+ "image": {
+ "links": [
{
"rel": "bookmark",
"href": image_bookmark,
@@ -371,9 +451,9 @@ class ServersTest(test.TestCase):
self.assertDictEqual(res_dict, expected_server)
- def test_get_server_with_active_status_by_id_v1_1(self):
+ def test_get_server_with_id_image_ref_by_id_v1_1(self):
self.maxDiff = None
- image_ref = "http://localhost/v1.1/images/10"
+ image_ref = "10"
image_bookmark = "http://localhost/images/10"
flavor_ref = "http://localhost/v1.1/flavors/1"
flavor_id = "1"
@@ -409,10 +489,6 @@ class ServersTest(test.TestCase):
"id": "10",
"links": [
{
- "rel": "self",
- "href": image_ref,
- },
- {
"rel": "bookmark",
"href": image_bookmark,
},