Merge "Add getServers function to nova rest API"

This commit is contained in:
Jenkins 2016-01-08 04:43:52 +00:00 committed by Gerrit Code Review
commit 634b525537
4 changed files with 49 additions and 0 deletions

View File

@ -144,6 +144,19 @@ class Servers(generic.View):
'config_drive'
]
@rest_utils.ajax()
def get(self, request):
"""Get a list of servers.
The listing result is an object with property "items". Each item is
a server.
Example GET:
http://localhost/api/nova/servers
"""
servers = api.nova.server_list(request)[0]
return {'items': [s.to_dict() for s in servers]}
@rest_utils.ajax(data_required=True)
def post(self, request):
"""Create a server.

View File

@ -39,6 +39,7 @@
getLimits: getLimits,
createServer: createServer,
getServer: getServer,
getServers: getServers,
getExtensions: getExtensions,
getFlavors: getFlavors,
getFlavor: getFlavor,
@ -210,6 +211,21 @@
});
}
/**
* @name horizon.app.core.openstack-service-api.nova.getServers
* @description
* Get a list of servers.
*
* The listing result is an object with property "items". Each item is
* a server.
*/
function getServers() {
return apiService.get('/api/nova/servers/')
.error(function () {
toastService.add('error', gettext('Unable to retrieve instances.'));
});
}
/**
* @name horizon.app.core.openstack-service-api.nova.getExtensions
* @description

View File

@ -107,6 +107,12 @@
42
]
},
{
"func": "getServers",
"method": "get",
"path": "/api/nova/servers/",
"error": "Unable to retrieve instances."
},
{
"func": "getExtensions",
"method": "get",

View File

@ -144,6 +144,20 @@ class NovaRestTestCase(test.TestCase):
[{'name': 'root'}]
)
@mock.patch.object(nova.api, 'nova')
def test_server_list(self, nc):
request = self.mock_rest_request()
nc.server_list.return_value = ([
mock.Mock(**{'to_dict.return_value': {'id': 'one'}}),
mock.Mock(**{'to_dict.return_value': {'id': 'two'}}),
], False)
response = nova.Servers().get(request)
self.assertStatusCode(response, 200)
self.assertEqual(response.json,
{'items': [{'id': 'one'}, {'id': 'two'}]})
nc.server_list.assert_called_once_with(request)
@mock.patch.object(nova.api, 'nova')
def test_server_get_single(self, nc):
request = self.mock_rest_request()