您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)如何自定義horizon插件的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
此例子是基于ocata版本horizon的自定義了一個(gè)插件。幫助對(duì)于horizon自定義dashbaord及panel的了解。要求對(duì)Python、HTML和JavaScript(AngularJS)有基本的了解。
不用說(shuō),選擇一個(gè)有意義的存儲(chǔ)庫(kù)名稱(chēng)很重要。此外,如果您計(jì)劃在您的dashboard插件上支持翻譯,建議選擇一個(gè)類(lèi)似于xxxx-dashboard的名稱(chēng)(或xxxx-ui. xxx-horizon)。OpenStack CI infra腳本將這些后綴視為Django項(xiàng)目。
整個(gè)插件目錄結(jié)構(gòu)如下:
xxxx-dashboard │ ├── xxxxdashboard │ ├── __init__.py │ │ │ ├── enabled │ │ ├──_90000_mydashboard.py │ │ ├──_90010_mygroup_panel_group.py │ │ └──_90011_mypanel.py │ │ │ ├── api │ │ ├──__init__.py │ │ ├── my_rest_api.py │ │ └── myservice.py │ │ │ ├── dashboards │ │ ├──__init__.py │ │ └── mydashboard │ │ ├──__init__.py │ │ ├──dashboard.py │ │ ├── mypanel │ │ │ ├── __init__.py │ │ │ ├── panel.py │ │ │ ├── tests.py │ │ │ ├── urls.py │ │ │ ├── views.py │ │ │ └── templates │ │ │ └── mypanel │ │ │ └── index.html │ │ └── static │ │ └── dashboard │ | └── mydashboard │ | └── mypanel │ | ├── mypanel.html │ | ├── mypanel.js │ | └── mypanel.scss │ | │ │ │ └── locale │ └── <lang> │ └── LC_MESSAGES │ ├── django.po │ └── djangojs.po │ ├── setup.py ├── setup.cfg ├── LICENSE ├── MANIFEST.in ├── README.rst ├── babel-django.cfg └── babel-djangojs.cfg
# The slug of the dashboard to be added to HORIZON['dashboards']. Required. DASHBOARD = 'mydashboard' # If set to True, this dashboard will be set as the default dashboard. #DEFAULT = True # A dictionary of exception classes to be added to HORIZON['exceptions']. ADD_EXCEPTIONS = {} # A list of applications to be added to INSTALLED_APPS. ADD_INSTALLED_APPS = [xxxxdashboard.dashboards.mydashboard'] ADD_ANGULAR_MODULES = [ 'dashboard.mydashboard.mypanel', ] AUTO_DISCOVER_STATIC_FILES = True ADD_JS_FILES = [] ADD_JS_SPEC_FILES = []
from django.utils.translation import ugettext_lazy as _ # The slug of the panel group to be added to HORIZON_CONFIG. Required. PANEL_GROUP = 'mygroup' # The display name of the PANEL_GROUP. Required. PANEL_GROUP_NAME = _('MyGroup') # The slug of the dashboard the PANEL_GROUP associated with. Required. PANEL_GROUP_DASHBOARD = 'mydashboard'
# The slug of the panel to be added to HORIZON_CONFIG. Required. PANEL = 'mypanel' # The slug of the dashboard the PANEL associated with. Required. PANEL_DASHBOARD = 'mydashboard' # The slug of the panel group the PANEL is associated with. PANEL_GROUP = 'mygroup' # If set, it will update the default panel of the PANEL_DASHBOARD. DEFAULT_PANEL = 'mypanel' # Python panel class of the PANEL to be added. ADD_PANEL = 'xxxxdashboard.dashboards.mydashboard.mypanel.panel.MyPanel'
from django.utils.translation import ugettext_lazy as _ import horizon class MyDashboard(horizon.Dashboard): name = _("MyDashboard") slug = "mydashboard" horizon.register(MyDashboard)
from django.utils.translation import ugettext_lazy as _ import horizon class MyPanel(horizon.Panel): name = _("My Panel") slug = "mypanel"
from django.conf.urls import url from xxxxdashboard.dashboards.mydashboard.mypanel import views urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), ]
from django.views.generic import base class IndexView(base.TemplateView): template_name = 'mydashboard/mypanel/index.html'
此文件位于dashboards/mydashboard/mypanel/templates/mypanel/index.html。
{% extends 'base.html' %} {% load i18n %} {% block title %}{% trans "My panel" %}{% endblock %} {% block page_header %} {% include "horizon/common/_domain_page_header.html" with title=page_title %} {% endblock page_header %} {% block main %} <ng-include src="'{{ STATIC_URL }}dashboard/mydashboard/mypanel/mypanel.html'"> </ng-include> {% endblock %} <script src='{{ STATIC_URL }}dashboard/mydashboard/mypanel/mypanel.js' type='text/javascript' charset='utf-8'></script>
<div ng-controller="dashboard.mydashboard.myPluginController as ctrl"> <div>Loading data from your controller:</div> <ul> <li ng-repeat="item in ctrl.items"> <span class="c1">{$ item.name $}</span> <span class="c2">{$ item.id $}</span> </li> </ul> </div>
(function() { 'use strict'; angular .module('dashboard.mydashboard.mypanel', []) .controller('dashboard.mydashboard.myPluginController', myPluginController); myPluginController.$inject = [ '$http' ]; function myPluginController($http) { var ctrl = this; ctrl.items = [ { name: 'abc', id: 123 }, { name: 'efg', id: 345 }, { name: 'hij', id: 678 } ]; } })();
li{ display: inline; margin-right: 15px; input[type="radio"] { margin: 0px; } }
該文件負(fù)責(zé)列出您想要包含在tar中的路徑.
include setup.py recursive-include myplugin *.js *.html *.scss
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT import setuptools # In python < 2.7.4, a lazy loading of package `pbr` will break # setuptools if some other modules registered functions in `atexit`. # solution from: http://bugs.python.org/issue15881#msg170215 try: import multiprocessing # noqa except ImportError: pass setuptools.setup( setup_requires=['pbr>=1.8'], pbr=True)
[metadata] name = myplugin summary = A panel plugin for OpenStack Dashboard description-file = README.rst author = myname author_email = myemail home-page = https://docs.openstack.org/horizon/latest/ classifiers = [ Environment :: OpenStack Framework :: Django Intended Audience :: Developers Intended Audience :: System Administrators License :: OSI Approved :: Apache Software License Operating System :: POSIX :: Linux Programming Language :: Python Programming Language :: Python :: 2 Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.5 [files] packages = myplugin
感謝各位的閱讀!關(guān)于“如何自定義horizon插件”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。