openstack version
The web code directory of pike openstack is in /usr/share/openstack-dashboard/openstack_dashboard/dashboards/
Create a ssd panel directory
cd /usr/share/openstack-dashboard/openstack_dashboard/dashboards/admin/
mkdir ssd
Automatically generate directory structure and file content
cd /usr/share/openstack-dashboard/
python manage.py startpanel ssd --dashboard=openstack_dashboard.dashboards.admin --target=openstack_dashboard/dashboards/admin/ssd
View the generated ssd directory structure
tree ssd/
ssd/
├── __init__.py
├── panel.py
├── templates
│ └── ssd
│ └── index.html
├── tests.py
├── urls.py
└── views.py
2 directories, 6 files
View file content
[root@controller ssd]# cat panel.py
# 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
from openstack_dashboard.dashboards.admin import dashboard
class Ssd(horizon.Panel):
name = _("Ssd")
slug = "ssd"
dashboard.Admin.register(Ssd)
[root@controller ssd]# cat tests.py
# 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 horizon.test import helpers as test
class SsdTests(test.TestCase):
# Unit tests for ssd.
def test_me(self):
self.assertTrue(1 + 1 == 2)
[root@controller ssd]# cat urls.py
# 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 openstack_dashboard.dashboards.admin.ssd import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
]
[root@controller ssd]# cat views.py
# 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 horizon import views
class IndexView(views.APIView):
# A very simple class-based view...
template_name = 'admin/ssd/index.html'
def get_data(self, request, context, *args, **kwargs):
# Add data to the context here...
return context
cat templates/ssd/index.html
{
% extends 'base.html' %}
{
% load i18n %}
{
% block title %}{
% trans "Ssd" %}{
% endblock %}
{
% block page_header %}
{
% include "horizon/common/_page_header.html" with title=_("Ssd") %}
{
% endblock page_header %}
{
% block main %}
{
% endblock %}
Add the newly added ssd panel to the compute panel group under the administrator (admin) and name it Ssd.
cat /usr/share/openstack-dashboard/openstack_dashboard/enabled/_2160_admin_ssd_panel.py
# The slug of the panel to be added to HORIZON_CONFIG. Required.
PANEL = 'ssd'
# The slug of the dashboard the PANEL associated with. Required.
PANEL_DASHBOARD = 'admin'
# The slug of the panel group the PANEL is associated with.
PANEL_GROUP = 'compute'
# Python panel class of the PANEL to be added.
ADD_PANEL = 'openstack_dashboard.dashboards.admin.ssd.panel.Ssd'
Restart http
systemctl restart httpd.service
View the newly added panel
Up to this point, a new Ssd panel has been added to the dashboard, and functions need to be added later.