Cleanup ironic-ui portgroup REST interface
Minor modifications to the ironic-ui REST endpoints for portgroups. The endpoint to query the portgroups associated with a node is now: get /api/ironic/nodes/<node-id>/portgroups, and a portgroup is deleted using: delete /api/ironic/portgroups/<portgroup-id> Change-Id: I1c77869cbb395410612619f382b68eda7ac64198
This commit is contained in:
parent
04537e8158
commit
c5e47e36ff
|
@ -347,20 +347,7 @@ class DriverProperties(generic.View):
|
|||
@urls.register
|
||||
class Portgroups(generic.View):
|
||||
|
||||
url_regex = r'ironic/portgroups/$'
|
||||
|
||||
@rest_utils.ajax()
|
||||
def get(self, request):
|
||||
"""Get the list of portgroups associated with a specified node.
|
||||
|
||||
:param request: HTTP request.
|
||||
:return: List of portgroups.
|
||||
"""
|
||||
portgroups = ironic.portgroup_list(request,
|
||||
request.GET.get('node_id'))
|
||||
return {
|
||||
'portgroups': [i.to_dict() for i in portgroups]
|
||||
}
|
||||
url_regex = r'ironic/portgroups$'
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def post(self, request):
|
||||
|
@ -371,14 +358,25 @@ class Portgroups(generic.View):
|
|||
"""
|
||||
return ironic.portgroup_create(request, request.DATA).to_dict()
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def delete(self, request):
|
||||
"""Delete a portgroup.
|
||||
|
||||
@urls.register
|
||||
class NodePortgroups(generic.View):
|
||||
|
||||
url_regex = r'ironic/nodes/(?P<node_id>{})/portgroups$' . \
|
||||
format(LOGICAL_NAME_PATTERN)
|
||||
|
||||
@rest_utils.ajax()
|
||||
def get(self, request, node_id):
|
||||
"""Get the list of portgroups associated with a specified node.
|
||||
|
||||
:param request: HTTP request.
|
||||
:param node_id: Node name or uuid
|
||||
:return: List of portgroups.
|
||||
"""
|
||||
return ironic.portgroup_delete(request,
|
||||
request.DATA.get('portgroup_id'))
|
||||
portgroups = ironic.portgroup_list(request, node_id)
|
||||
return {
|
||||
'portgroups': [i.to_dict() for i in portgroups]
|
||||
}
|
||||
|
||||
|
||||
@urls.register
|
||||
|
@ -397,6 +395,15 @@ class Portgroup(generic.View):
|
|||
patch = request.DATA.get('patch')
|
||||
return ironic.portgroup_update(request, portgroup_id, patch)
|
||||
|
||||
@rest_utils.ajax()
|
||||
def delete(self, request, portgroup_id):
|
||||
"""Delete a portgroup.
|
||||
|
||||
:param request: HTTP request.
|
||||
:param portgroup_id: UUID or name of portgroup.
|
||||
"""
|
||||
return ironic.portgroup_delete(request, portgroup_id)
|
||||
|
||||
|
||||
@urls.register
|
||||
class PortgroupPorts(generic.View):
|
||||
|
|
|
@ -665,30 +665,35 @@
|
|||
});
|
||||
|
||||
// Create portgroup
|
||||
$httpBackend.whenPOST(/\/api\/ironic\/portgroups\/$/)
|
||||
$httpBackend.whenPOST(/\/api\/ironic\/portgroups$/)
|
||||
.respond(function(method, url, data) {
|
||||
return createPortgroup(JSON.parse(data));
|
||||
});
|
||||
|
||||
// Get portgroups. This function is not fully implemented.
|
||||
$httpBackend.whenGET(/\/api\/ironic\/portgroups\//)
|
||||
// Get the portgroups associated with a node
|
||||
$httpBackend.whenGET(/\/api\/ironic\/nodes\/(.+)\/portgroups/,
|
||||
undefined,
|
||||
undefined,
|
||||
['nodeId'])
|
||||
.respond(function(method, url, data, header, params) {
|
||||
var nodeId = params.node_id;
|
||||
var status = responseCode.RESOURCE_NOT_FOUND;
|
||||
var portgroups = [];
|
||||
if (angular.isDefined(nodes[nodeId])) {
|
||||
angular.forEach(nodes[nodeId].portgroups, function(portgroup) {
|
||||
portgroups.push(portgroup);
|
||||
});
|
||||
if (angular.isDefined(nodes[params.nodeId])) {
|
||||
angular.forEach(nodes[params.nodeId].portgroups,
|
||||
function(portgroup) {
|
||||
portgroups.push(portgroup);
|
||||
});
|
||||
status = responseCode.SUCCESS;
|
||||
}
|
||||
return [status, {portgroups: portgroups}];
|
||||
});
|
||||
|
||||
// Delete portgroup. This function is not yet implemented.
|
||||
$httpBackend.whenDELETE(/\/api\/ironic\/portgroups\/$/)
|
||||
.respond(function(method, url, data) {
|
||||
var portgroupId = JSON.parse(data).portgroup_id;
|
||||
// Delete portgroup.
|
||||
$httpBackend.whenDELETE(/\/api\/ironic\/portgroups\/([^\/]+)$/,
|
||||
undefined,
|
||||
['portgroupId'])
|
||||
.respond(function() {
|
||||
var portgroupId = params.portgroup_id;
|
||||
var status = responseCode.RESOURCE_NOT_FOUND;
|
||||
if (angular.isDefined(portgroups[portgroupId])) {
|
||||
var portgroup = portgroups[portgroupId];
|
||||
|
|
|
@ -574,7 +574,7 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve a list of portgroups associated with a node.
|
||||
* @description Retrieve the list of portgroups associated with a node.
|
||||
*
|
||||
* http://developer.openstack.org/api-ref/baremetal/#list-detailed-portgroups
|
||||
*
|
||||
|
@ -582,8 +582,7 @@
|
|||
* @return {promise} List of portgroups.
|
||||
*/
|
||||
function getPortgroups(nodeId) {
|
||||
return apiService.get('/api/ironic/portgroups/',
|
||||
{params: {node_id: nodeId}})
|
||||
return apiService.get('/api/ironic/nodes/' + nodeId + '/portgroups')
|
||||
.then(function(response) {
|
||||
// Add id property to support delete operations
|
||||
// using the deleteModalService
|
||||
|
@ -612,7 +611,7 @@
|
|||
* @return {promise} Promise containing the portgroup.
|
||||
*/
|
||||
function createPortgroup(params) {
|
||||
return apiService.post('/api/ironic/portgroups/', params)
|
||||
return apiService.post('/api/ironic/portgroups', params)
|
||||
.then(function(response) {
|
||||
toastService.add('success',
|
||||
gettext('Portgroup successfully created'));
|
||||
|
@ -636,8 +635,7 @@
|
|||
* @return {promise} Promise.
|
||||
*/
|
||||
function deletePortgroup(portgroupId) {
|
||||
return apiService.delete('/api/ironic/portgroups/',
|
||||
{portgroup_id: portgroupId})
|
||||
return apiService.delete('/api/ironic/portgroups/' + portgroupId)
|
||||
.catch(function(response) {
|
||||
var msg = interpolate(gettext('Unable to delete portgroup: %s'),
|
||||
[response.data],
|
||||
|
|
Loading…
Reference in New Issue