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'
|
'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)
|
@rest_utils.ajax(data_required=True)
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""Create a server.
|
"""Create a server.
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
getLimits: getLimits,
|
getLimits: getLimits,
|
||||||
createServer: createServer,
|
createServer: createServer,
|
||||||
getServer: getServer,
|
getServer: getServer,
|
||||||
|
getServers: getServers,
|
||||||
getExtensions: getExtensions,
|
getExtensions: getExtensions,
|
||||||
getFlavors: getFlavors,
|
getFlavors: getFlavors,
|
||||||
getFlavor: getFlavor,
|
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
|
* @name horizon.app.core.openstack-service-api.nova.getExtensions
|
||||||
* @description
|
* @description
|
||||||
|
@ -107,6 +107,12 @@
|
|||||||
42
|
42
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"func": "getServers",
|
||||||
|
"method": "get",
|
||||||
|
"path": "/api/nova/servers/",
|
||||||
|
"error": "Unable to retrieve instances."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"func": "getExtensions",
|
"func": "getExtensions",
|
||||||
"method": "get",
|
"method": "get",
|
||||||
|
@ -144,6 +144,20 @@ class NovaRestTestCase(test.TestCase):
|
|||||||
[{'name': 'root'}]
|
[{'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')
|
@mock.patch.object(nova.api, 'nova')
|
||||||
def test_server_get_single(self, nc):
|
def test_server_get_single(self, nc):
|
||||||
request = self.mock_rest_request()
|
request = self.mock_rest_request()
|
||||||
|
Loading…
Reference in New Issue
Block a user