From 3041f2e9eb90e447adbb48827c2c85ca27d436e6 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 14 Jul 2011 13:25:40 -0400 Subject: Added progress attribute to servers responses --- nova/api/openstack/views/servers.py | 4 ++ nova/tests/api/openstack/test_servers.py | 99 +++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 5d906f3df..3f13e469a 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -183,6 +183,10 @@ class ViewBuilderV11(ViewBuilder): response['id'] = inst['uuid'] response['created'] = inst['created_at'] response['updated'] = inst['updated_at'] + if response['status'] == "ACTIVE": + response['progress'] = 100 + elif response['status'] == "BUILD": + response['progress'] = 0 def _build_links(self, response, inst): href = self.generate_href(inst["id"]) diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 4385e1c14..e00dd825e 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -307,22 +307,117 @@ class ServersTest(test.TestCase): "id": FAKE_UUID, "updated": "2010-11-11T11:00:00Z", "created": "2010-10-10T12:00:00Z", + "progress": 0, "name": "server1", "status": "BUILD", "hostId": '', + #"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": image_ref, + "href": flavor_ref, }, { "rel": "bookmark", - "href": image_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_ref = "http://localhost/v1.1/images/10" + 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_ref, + 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": { + "id": "10", + "links": [ + { + "rel": "self", + "href": image_ref, + }, + { + "rel": "bookmark", + "href": image_bookmark, + }, + ], + }, "flavor": { "id": "1", "links": [ -- cgit