horizon源码结构

来源:互联网 发布:pe备份c盘数据 编辑:程序博客网 时间:2024/06/06 06:50
/usr/share/pyshared/horizon/horizon   其他openstack也在这里例如, nova   novaclient   glance   keystone  keystoneclient..
 
 

/usr/lib/python2.7/dist-packages/horizon   其他openstack组件也在这里 ...进该目录后,用ll命令查看。该目录的文件有对应的指向  其实就是指向上面的那个目录里的文件
 
 
find / -depth  -name "settings.py" -print
/usr/lib/python2.7/dist-packages/django/conf/project_template/settings.py
/usr/share/pyshared/django/conf/project_template/settings.py
/usr/share/openstack-dashboard/openstack_dashboard/settings.py
/usr/share/openstack-dashboard/settings.py
 
setting指定ROOT_URLCONF
 
/usr/share/openstack-dashboard/openstack_dashboard/views.py
/usr/share/openstack-dashboard/openstack_dashboard/templates/splash.html 指定起始页
 
 

不同版本文件目录结构不大一样,但是大体能找到在什么地方 。本文以Essex版本介绍
 
dashboard源码解读
目录结构:
/usr/share/pyshared/horizon
1.api                                    horizon通过这里访问openstack各个组件的api
2.context_processors.py
3.decorators.py
4.forms
5.locale  各种语言配置  汉化zh_CN 文件夹中,只需修改LC_MESSAGES下的django.po即可
6.models.py
7.static     所有的js文件
8.tabs
9.templaetags    
                                   
                                                1.branding.py    Template tags for customizing Horizon
                                                 2.horizon.py     控制菜单显示和角色权限匹配
                                                 3.  parse_date.py                             Template tags for parsing date strings
                                                 4.sizeformat.py   Template tags for displaying sizes
                                                  5.truncate_filter.py    Template tags for truncating strings
10.test
11.usage            总览的基类    nova  syspanel中的总览都是调用这里
12.utiles
13.views
14.base.py
15 dashboards
16.execptions.py
17.__init__.py
18.middleware.py
19.site_urls.py
20.tables                        table的基类                      
                                                         各个模块的tables.py用于定义显示格式
21.templates
22.test.py
23.time.py
24.users.py
25.version.py
 
 
 
templates
/usr/share/pyshared/horizon/templates/horizon/common/_silder.html    
horizon_dashboard_nav
 
/usr/share/pyshared/horizon/templates/horizon/_nav_list.html  左侧菜单的标签标题
/usr/share/pyshared/horizon/templates/horizon/_subnav_list.html  左侧菜单显示
/usr/share/pyshared/horizon/templatetags/horizon.py  控制左侧菜单显示
 
 
 
 
 
 base.html
sudo find ./ -depth -name "base.html" -print 
./tests/templates/base.html
./dashboards/settings/templates/settings/base.html
./dashboards/nova/templates/nova/base.html
./dashboards/syspanel/templates/syspanel/base.html
 
 
 
/usr/share/pyshared/horizon/templates/horizon/common/_sidebar.html    左侧面板
该文件最后一行:
{% horizon_dashboard_nav %}
 
horizon_dashboard_nav 在文件/usr/share/pyshared/horizon/templatetags/horizon.py中定义
 

@register.inclusion_tag('horizon/_subnav_list.html', takes_context=True)
def horizon_dashboard_nav(context):
    """ Generates sub-navigation entries for the current dashboard. """
    if 'request' not in context:
        return {}
    dashboard = context['request'].horizon['dashboard']
    panel_groups = dashboard.get_panel_groups()
    non_empty_groups = []

    for group in panel_groups.values():
        allowed_panels = []
        for panel in group:
            if callable(panel.nav) and panel.nav(context):
                allowed_panels.append(panel)
            elif not callable(panel.nav) and panel.nav:
                allowed_panels.append(panel)
        if allowed_panels:
            non_empty_groups.append((group.name, allowed_panels))

    return {'components': SortedDict(non_empty_groups),
            'user': context['request'].user,
            'current': context['request'].horizon['panel'].slug,
            'request': context['request']}

 
 
 
菜单位置:
/usr/share/pyshared/horizon/dashboards/syspanel/dashboard.py
文件全部内容

from django.utils.translation import ugettext_lazy as _

import horizon


class SystemPanels(horizon.PanelGroup):
    slug = "syspanel"
    name = _("System Panel")
    panels = ('overview', 'instances', 'services', 'flavors', 'images',
              'projects', 'users', 'quotas',)

 


class Syspanel(horizon.Dashboard):
    name = _("Admin")
    slug = "syspanel"
    panels = (SystemPanels,)
    default_panel = 'overview'
    roles = ('admin',)


horizon.register(Syspanel)

 
 
菜单显示的名字不在上述文件中,而在相应模块的panel.py中
/usr/share/pyshared/horizon/dashboards/syspanel/quotas/panel.py
 

from django.utils.translation import ugettext_lazy as _

import horizon
from horizon.dashboards.syspanel import dashboard


class Quotas(horizon.Panel):
    name = _("Quotas")    菜单显示名字
    slug = 'quotas'    与dashboard.py中保持一致


dashboard.Syspanel.register(Quotas)

 
 
 
 
 
原创粉丝点击