OpenStackhorizon追加パネル

openstackバージョン


ウェブコードディレクトリカワカマスOpenStackのISでは、/ usr / share / OpenStackは、ダッシュボード/ openstack_dashboard /ダッシュボード/

ssdパネルディレクトリを作成します

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)の下の計算パネルグループに追加し、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

新しく追加されたパネルを表示する

ここに画像の説明を挿入

これまで、ダッシュボードに新しいSsdパネルが追加されており、後で機能を追加する必要があります。

おすすめ

転載: blog.csdn.net/weixin_40548182/article/details/112647393