Add details view for capsule

This patch adds details view for capsule.

Change-Id: Ia6a46b88aeedaea3642c1d424fedaae65f485655
Partial-Implements: blueprint capsule
This commit is contained in:
Shu Muto 2018-06-13 17:16:20 +09:00
parent 247af4b88b
commit 12da76bd2d
10 changed files with 239 additions and 15 deletions

View File

@ -272,6 +272,10 @@ def capsule_list(request, limit=None, marker=None, sort_key=None,
sort_dir)
def capsule_show(request, id):
return zunclient(request).capsules.get(id)
def image_list(request, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=False):
# FIXME(shu-mutou): change "detail" param to True, if it enabled.

View File

@ -179,6 +179,17 @@ class Capsules(generic.View):
return {'items': [i.to_dict() for i in result]}
@urls.register
class Capsule(generic.View):
"""API for retrieving a single capsule"""
url_regex = r'zun/capsules/(?P<id>[^/]+)$'
@rest_utils.ajax()
def get(self, request, id):
"""Get a specific capsule"""
return change_to_id(client.capsule_show(request, id).to_dict())
@urls.register
class Images(generic.View):
"""API for Zun Images"""

View File

@ -26,7 +26,8 @@
angular
.module('horizon.dashboard.container.capsules', [
'ngRoute',
'horizon.dashboard.container.capsules.actions'
'horizon.dashboard.container.capsules.actions',
'horizon.dashboard.container.capsules.details'
])
.constant('horizon.dashboard.container.capsules.events', events())
.constant('horizon.dashboard.container.capsules.resourceType', 'OS::Zun::Capsule')
@ -47,6 +48,7 @@
}
run.$inject = [
'$filter',
'horizon.framework.conf.resource-type-registry.service',
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.capsules.basePath',
@ -54,19 +56,19 @@
'horizon.dashboard.container.capsules.service'
];
function run(registry, zun, basePath, resourceType, capsuleService) {
function run($filter, registry, zun, basePath, resourceType, capsuleService) {
registry.getResourceType(resourceType)
.setNames(gettext('Capsule'), gettext('Capsules'))
// for detail summary view on table row.
.setSummaryTemplateUrl(basePath + 'drawer.html')
// for table row items and detail summary view.
.setDefaultIndexUrl('/project/container/capsules/')
.setProperties(capsuleProperties())
.setListFunction(capsuleService.getCapsulesPromise)
.tableColumns
.append({
id: 'meta_name',
id: 'name',
priority: 1,
sortDefault: true
sortDefault: true,
urlFunction: capsuleService.getDetailsPath
})
.append({
id: 'id',
@ -87,13 +89,13 @@
// for magic-search
registry.getResourceType(resourceType).filterFacets
.append({
'label': gettext('ID'),
'name': 'id',
'label': gettext('Capsule ID'),
'name': 'capsule_id',
'singleton': true
})
.append({
'label': gettext('Name'),
'name': 'meta_name',
'name': 'name',
'singleton': true
})
.append({
@ -115,7 +117,7 @@
'links': {label: gettext('Links'), filters: ['noValue', 'json'] },
'memory': { label: gettext('Memory'), filters: ['noValue'] },
'meta_labels': {label: gettext('Labels'), filters: ['noValue', 'json'] },
'meta_name': { label: gettext('Name'), filters: ['noName'] },
'name': { label: gettext('Name'), filters: ['noName'] },
'project_id': { label: gettext('Project ID'), filters: ['noValue'] },
'restart_policy': { label: gettext('Restart Policy'), filters: ['noValue'] },
'status': { label: gettext('Status'), filters: ['noValue'] },

View File

@ -33,9 +33,36 @@
*/
function capsulesService(detailRoute, zun) {
return {
getDetailsPath: getDetailsPath,
getCapsulePromise: getCapsulePromise,
getCapsulesPromise: getCapsulesPromise
};
/*
* @ngdoc function
* @name getDetailsPath
* @param item {Object} - The capsule object
* @description
* Returns the relative path to the details view.
*/
function getDetailsPath(item) {
return detailRoute + 'OS::Zun::Capsule/' + item.id;
}
/*
* @ngdoc function
* @name getCapsulePromise
* @description
* Given an id, returns a promise for the capsule data.
*/
function getCapsulePromise(identifier) {
return zun.getCapsule(identifier).then(modifyDetails);
}
function modifyDetails(response) {
return {data: modifyItem(response.data)};
}
/*
* @ngdoc function
* @name getCapsulesPromise
@ -52,9 +79,10 @@
}
function modifyItem(item) {
item.id = item.uuid;
item.trackBy = item.uuid;
item.trackBy = item.trackBy.concat(item.updated_at);
item.name = item.meta_name;
item.capsule_id = item.id;
item.id = item.uuid ? item.uuid : item.capsule_id;
item.trackBy = item.id.concat(item.updated_at);
return item;
}
}

View File

@ -0,0 +1,51 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
/**
* @ngdoc overview
* @ngname horizon.dashboard.container.capsules.details
*
* @description
* Provides details features for capsule.
*/
angular.module('horizon.dashboard.container.capsules.details',
['horizon.framework.conf', 'horizon.app.core'])
.run(registerDetails);
registerDetails.$inject = [
'horizon.dashboard.container.capsules.basePath',
'horizon.dashboard.container.capsules.resourceType',
'horizon.dashboard.container.capsules.service',
'horizon.framework.conf.resource-type-registry.service'
];
function registerDetails(
basePath,
resourceType,
capsuleService,
registry
) {
registry.getResourceType(resourceType)
.setLoadFunction(capsuleService.getCapsulePromise)
.detailsViews
.append({
id: 'capsuleDetailsOverview',
name: gettext('Overview'),
template: basePath + 'details/overview.html'
});
}
})();

View File

@ -0,0 +1,37 @@
/*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
"use strict";
angular
.module('horizon.dashboard.container.capsules')
.controller('horizon.dashboard.container.capsules.OverviewController', controller);
controller.$inject = [
'$scope', '$window'
];
function controller(
$scope, $window
) {
var ctrl = this;
ctrl.webRoot = $window.WEBROOT;
$scope.context.loadPromise.then(onGetCapsule);
function onGetCapsule(capsule) {
ctrl.capsule = capsule.data;
}
}
})();

View File

@ -0,0 +1,50 @@
<div ng-controller="horizon.dashboard.container.capsules.OverviewController as ctrl">
<div class="row">
<div class="col-md-6 detail">
<h3 translate>Info</h3>
<hr>
<hz-resource-property-list
resource-type-name="OS::Zun::Capsule"
cls="dl-horizontal"
item="ctrl.capsule"
property-groups="[['id', 'name', 'capsule_versionid', 'status', 'status_reason',
'created_at', 'updated_at', 'project_id', 'user_id']]">
</hz-resource-property-list>
</div>
<div class="col-md-6 detail">
<h3 translate>Spec</h3>
<hr>
<hz-resource-property-list
resource-type-name="OS::Zun::Capsule"
cls="dl-horizontal"
item="ctrl.capsule"
property-groups="[['cpu', 'memory', 'restart_policy',
'meta_labels', 'links', 'addresses']]">
</hz-resource-property-list>
</div>
</div>
<div class="row">
<div class="col-md-6 detail">
<h3 translate>Containers</h3>
<hr>
<div class="row">
<dl class="col-md-12 dl-horizontal" ng-repeat="container in ctrl.capsule.containers">
<dt>Name</dt>
<dd><a href="{$ ctrl.webRoot $}ngdetails/OS::Zun::Container/{$ container.uuid $}">{$ container.name $}</a></dd>
<dt>Container ID</dt>
<dd>{$ container.uuid $}</dd>
</dl>
</div>
</div>
<div class="col-md-6 detail">
<h3 translate>Volumes</h3>
<hr>
<hz-resource-property-list
resource-type-name="OS::Zun::Capsule"
cls="dl-horizontal"
item="ctrl.capsule"
property-groups="[['volumes_info']]">
</hz-resource-property-list>
</div>
</div>
</div>

View File

@ -0,0 +1,36 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
(function() {
'use strict';
/**
* @ngdoc controller
* @name horizon.dashboard.container.capsules.DrawerController
* @description
* This is the controller for the drawer (summary) view.
* Its primary purpose is to provide the metadata definitions to
* the template via the ctrl.metadataDefs member.
*/
angular
.module('horizon.dashboard.container.capsules')
.controller('horizon.dashboard.container.capsules.DrawerController', controller);
controller.$inject = [
];
function controller() {
}
})();

View File

@ -2,6 +2,5 @@
resource-type-name="OS::Zun::Capsule"
item="item"
property-groups="[['id', 'cpu', 'memory', 'capsule_versionid'],
['meta_labels', 'created_at', 'updated_at'],
['addresses', 'volumes_info', 'status_reason']]">
['meta_labels', 'created_at', 'updated_at', 'status_reason']]">
</hz-resource-property-list>

View File

@ -54,6 +54,7 @@
updatePortSecurityGroup: updatePortSecurityGroup,
getZunAvailabilityZones: getZunAvailabilityZones,
getCapsules: getCapsules,
getCapsule: getCapsule,
pullImage: pullImage,
getImages: getImages,
deleteImage: deleteImage,
@ -208,6 +209,11 @@
return apiService.get(capsulesPath).error(error(msg));
}
function getCapsule(id) {
var msg = gettext('Unable to retrieve the Capsule.');
return apiService.get(capsulesPath + id).error(error(msg));
}
////////////
// Images //
////////////