OpenStack horizon 添加面板

openstack版本

pike
openstack的web代码目录在/usr/share/openstack-dashboard/openstack_dashboard/dashboards/

创建一个ssd的panel目录

cd /usr/share/openstack-dashboard/openstack_dashboard/dashboards/admin/
mkdir ssd

自动生成目录结构及文件内容

cd /usr/share/openstack-dashboard/
python manage.py startpanel ssd --dashboard=openstack_dashboard.dashboards.admin --target=openstack_dashboard/dashboards/admin/ssd

查看生成的ssd目录结构

tree ssd/
ssd/
├── __init__.py
├── panel.py
├── templates
│   └── ssd
│       └── index.html
├── tests.py
├── urls.py
└── views.py

2 directories, 6 files

查看文件内容

[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 %}

将新加的ssd面板加到管理员(admin)底下的计算(compute)面板组,命名为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'

重启http

systemctl restart httpd.service

查看新加的面板

OpenStack horizon 添加面板

到这里已经在dashboard上新加了一个Ssd的面板,后期还需要往里添加功能。

上一篇:PyCharm学生账户登录失败:Certificate used to sign the license is not signed by JetBrains root certificate (2)


下一篇:Nvidia VGPU license 服务器 java 路径安装注意