Add hosts panel

This patch adds hosts panel that includes index view.

Change-Id: I1c51961ba33ed4117774df83cad7d5bc6f076f69
Partial-Implements: blueprint add-host-panel
This commit is contained in:
Shu Muto 2018-10-16 17:11:34 +09:00
parent f571466dea
commit 7ebff515a7
9 changed files with 259 additions and 0 deletions

View File

@ -0,0 +1,19 @@
# 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.
from django.utils.translation import ugettext_lazy as _
import horizon
class Hosts(horizon.Panel):
name = _("Hosts")
slug = "container.hosts"

View File

@ -0,0 +1,20 @@
# 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.
from django.conf.urls import url
from django.utils.translation import ugettext_lazy as _
from horizon.browsers import views
title = _("Hosts")
urlpatterns = [
url('', views.AngularIndexView.as_view(title=title), name='index'),
]

View File

@ -0,0 +1,21 @@
# 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.
# The slug of the panel to be added to HORIZON_CONFIG. Required.
PANEL = 'container.hosts'
# The slug of the panel group the PANEL is associated with.
PANEL_GROUP = 'container'
# The slug of the dashboard the PANEL associated with. Required.
PANEL_DASHBOARD = 'admin'
# Python panel class of the PANEL to be added.
ADD_PANEL = 'zun_ui.content.container.hosts.panel.Hosts'

View File

@ -26,6 +26,7 @@
'horizon.dashboard.container.containers',
'horizon.dashboard.container.capsules',
'horizon.dashboard.container.images',
'horizon.dashboard.container.hosts',
'ngRoute'
])
.config(config);

View File

@ -0,0 +1,5 @@
<hz-resource-property-list
resource-type-name="OS::Zun::Host"
item="item"
property-groups="[['id', 'mem_total', 'cpus', 'disk_total']]">
</hz-resource-property-list>

View File

@ -0,0 +1,129 @@
/**
* 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
* @name horizon.dashboard.container.hosts
* @ngModule
* @description
* Provides all the services and widgets require to display the hosts
* panel
*/
angular
.module('horizon.dashboard.container.hosts', [
'ngRoute'
])
.constant('horizon.dashboard.container.hosts.resourceType', 'OS::Zun::Host')
.run(run)
.config(config);
run.$inject = [
'horizon.framework.conf.resource-type-registry.service',
'horizon.app.core.openstack-service-api.zun',
'horizon.dashboard.container.hosts.basePath',
'horizon.dashboard.container.hosts.resourceType',
'horizon.dashboard.container.hosts.service'
];
function run(registry, zun, basePath, resourceType, hostService) {
registry.getResourceType(resourceType)
.setNames(gettext('Host'), gettext('Hosts'))
// for detail summary view on table row.
.setSummaryTemplateUrl(basePath + 'drawer.html')
// for table row items and detail summary view.
.setProperties(hostProperties())
.setListFunction(hostService.getHostsPromise)
.tableColumns
.append({
id: 'id',
priority: 3
})
.append({
id: 'hostname',
priority: 1,
sortDefault: true
})
.append({
id: 'mem_total',
priority: 2
})
.append({
id: 'cpus',
priority: 2
})
.append({
id: 'disk_total',
priority: 2
});
// for magic-search
registry.getResourceType(resourceType).filterFacets
.append({
'label': gettext('Hostname'),
'name': 'repo',
'singleton': true
})
.append({
'label': gettext('ID'),
'name': 'id',
'singleton': true
});
}
function hostProperties() {
return {
'id': {label: gettext('ID'), filters: ['noValue'] },
'hostname': { label: gettext('Hostname'), filters: ['noValue'] },
'mem_total': { label: gettext('Memory Total'), filters: ['noValue', 'mb'] },
'mem_used': { label: gettext('Memory Used'), filters: ['noValue', 'mb'] },
'cpus': { label: gettext('CPU Total'), filters: ['noValue'] },
'cpu_used': { label: gettext('CPU Used'), filters: ['noValue'] },
'disk_total': { label: gettext('Disk Total'), filters: ['noValue', 'gb'] },
'disk_used': { label: gettext('Disk Used'), filters: ['noValue', 'gb'] },
'disk_quota_supported': { label: gettext('Disk Quota Supported'),
filters: ['noValue', 'yesno'] },
'total_containers': { label: gettext('Disk Used'), filters: ['noValue'] },
'os': { label: gettext('OS'), filters: ['noValue'] },
'os_type': { label: gettext('OS Type'), filters: ['noValue'] },
'architecture': { label: gettext('Architecture'), filters: ['noValue'] },
'kernel_version': { label: gettext('Kernel Version'), filters: ['noValue'] },
'runtimes': { label: gettext('Runtimes'), filters: ['noValue'] },
'labels': { label: gettext('Labels'), filters: ['noValue'] }
};
}
config.$inject = [
'$provide',
'$windowProvider',
'$routeProvider'
];
/**
* @name config
* @param {Object} $provide
* @param {Object} $windowProvider
* @param {Object} $routeProvider
* @description Routes used by this module.
* @returns {undefined} Returns nothing
*/
function config($provide, $windowProvider, $routeProvider) {
var path = $windowProvider.$get().STATIC_URL + 'dashboard/container/hosts/';
$provide.constant('horizon.dashboard.container.hosts.basePath', path);
$routeProvider.when('/admin/container/hosts', {
templateUrl: path + 'panel.html'
});
}
})();

View File

@ -0,0 +1,60 @@
/*
* 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.hosts')
.factory('horizon.dashboard.container.hosts.service', hostsService);
hostsService.$inject = [
'horizon.app.core.detailRoute',
'horizon.app.core.openstack-service-api.zun'
];
/*
* @ngdoc factory
* @name horizon.dashboard.container.hosts.service
*
* @description
* This service provides functions that are used through
* the hosts of container features.
*/
function hostsService(detailRoute, zun) {
return {
getHostsPromise: getHostsPromise
};
/*
* @ngdoc function
* @name getHostsPromise
* @description
* Given filter/query parameters, returns a promise for the matching
* hosts. This is used in displaying lists of hosts.
*/
function getHostsPromise(params) {
return zun.getHosts(params).then(modifyResponse);
}
function modifyResponse(response) {
return {data: {items: response.data.items.map(modifyItem)}};
function modifyItem(item) {
var timestamp = new Date();
item.trackBy = item.id.concat(timestamp.getTime());
return item;
}
}
}
})();

View File

@ -0,0 +1,4 @@
<hz-resource-panel resource-type-name="OS::Zun::Host">
<hz-resource-table resource-type-name="OS::Zun::Host"
track-by="trackBy"></hz-resource-table>
</hz-resource-panel>