Horizon 대시보드 생성

1 개요[ | ]

Building a Dashboard using Horizon
호라이즌 대시보드 생성

2 사전작업[ | ]

3 대시보드·패널 기본구조 생성[ | ]

[root@controller horizon]# mkdir openstack_dashboard/dashboards/mydashboard
[root@controller horizon]# tox -e manage -- startdash mydashboard --target openstack_dashboard/dashboards/mydashboard
manage create: /usr/local/horizon/.tox/manage
manage installdeps: -r/usr/local/horizon/requirements.txt, -r/usr/local/horizon/test-requirements.txt
... (생략)
manage runtests: PYTHONHASHSEED='2999997611'
manage runtests: commands[0] | /usr/local/horizon/.tox/manage/bin/python /usr/local/horizon/manage.py startdash mydashboard --target openstack_dashboard/dashboards/mydashboard
______________________________ summary _______________________________
  manage: commands succeeded
  congratulations :)
[root@controller horizon]# mkdir openstack_dashboard/dashboards/mydashboard/mypanel
[root@controller horizon]# tox -e manage -- startpanel mypanel --dashboard=openstack_dashboard.dashboards.mydashboard --target=openstack_dashboard/dashboards/mydashboard/mypanel
... (생략)
manage runtests: PYTHONHASHSEED='16613082'
manage runtests: commands[0] | /usr/local/horizon/.tox/manage/bin/python /usr/local/horizon/manage.py startpanel mypanel --dashboard=openstack_dashboard.dashboards.mydashboard --target=openstack_dashboard/dashboards/mydashboard/mypanel
______________________________ summary _______________________________
  manage: commands succeeded
  congratulations :)

4 dashboard.py 수정[ | ]

[root@controller horizon]# cd openstack_dashboard
[root@controller openstack_dashboard]# vi dashboards/mydashboard/dashboard.py
from django.utils.translation import ugettext_lazy as _
import horizon

class Mygroup(horizon.PanelGroup):
    slug = "mygroup"
    name = _("My Group")
    panels = ('mypanel',)

class Mydashboard(horizon.Dashboard):
   name = _("Mydashboard")
   slug = "mydashboard"
   panels = (Mygroup,)
   default_panel = 'mypanel'

horizon.register(Mydashboard)

5 panel.py 수정[ | ]

[root@controller openstack_dashboard]# vi dashboards/mydashboard/mypanel/panel.py
from django.utils.translation import ugettext_lazy as _
import horizon
from openstack_dashboard.dashboards.mydashboard import dashboard

class Mypanel(horizon.Panel):
    name = _("Mypanel")
    slug = "mypanel"

dashboard.Mydashboard.register(Mypanel)

6 _50_mydashboard.py 생성[ | ]

[root@controller openstack_dashboard]# vi enabled/_50_mydashboard.py
DASHBOARD = 'mydashboard'
DISABLED = False
ADD_INSTALLED_APPS = [
    'openstack_dashboard.dashboards.mydashboard',
]

7 아파치 리로드[ | ]

[root@controller openstack_dashboard]# systemctl reload httpd
[root@controller openstack_dashboard]#

8 (참고) 자동생성된 파일내용[ | ]

  • mypanel/urls.py
from django.conf.urls import url
from openstack_dashboard.dashboards.mydashboard.mypanel import views

urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
]
  • mypanel/views.py
from horizon import views

class IndexView(views.APIView):
    template_name = 'mydashboard/mypanel/index.html'
    def get_data(self, request, context, *args, **kwargs):
        return context
  • mypanel/templates/mypanel/index.html
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Mypanel" %}{% endblock %}

{% block page_header %}
  {% include "horizon/common/_page_header.html" with title=_("Mypanel") %}
{% endblock page_header %}

{% block main %}
{% endblock %}

9 같이 보기[ | ]

10 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}