Merge "Add getServers function to nova rest API"
This commit is contained in:
commit
634b525537
@ -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.
|
||||
|
@ -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
|
||||
|
@ -107,6 +107,12 @@
|
||||
42
|
||||
]
|
||||
},
|
||||
{
|
||||
"func": "getServers",
|
||||
"method": "get",
|
||||
"path": "/api/nova/servers/",
|
||||
"error": "Unable to retrieve instances."
|
||||
},
|
||||
{
|
||||
"func": "getExtensions",
|
||||
"method": "get",
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user