2011-10-31 11:31:05 -07:00
==================
Horizon Quickstart
==================
2014-01-21 17:30:11 +01:00
.. Note ::
This section has been tested for Horizon on Ubuntu (12.04-64) and Fedora-based (RHEL 6.4) distributions. Feel free to add notes and any changes according to your experiences or operating system.
Linux Systems
=============
Install the prerequisite packages.
On Ubuntu::
2014-03-27 14:21:40 -06:00
> sudo apt-get install git python-dev python-virtualenv libssl-dev libffi-dev
2014-01-21 17:30:11 +01:00
On Fedora-based distributions (e.g., Fedora/RHEL/CentOS/Scientific Linux)::
2014-03-27 14:21:40 -06:00
> sudo yum install gcc git-core python-devel python-virtualenv openssl-devel libffi-devel
2014-01-21 17:30:11 +01:00
2011-11-08 09:25:35 -08:00
Setup
=====
2013-12-03 19:58:19 +01:00
To setup a Horizon development environment simply clone the Horizon git
2012-08-15 11:03:57 -07:00
repository from http://github.com/openstack/horizon and execute the
`` run_tests.sh `` script from the root folder (see :doc: `ref/run_tests` )::
> git clone https://github.com/openstack/horizon.git
> cd horizon
> ./run_tests.sh
2013-12-03 19:58:19 +01:00
Next you will need to setup your Django application config by copying `` openstack_dashboard/local/local_settings.py.example `` to `` openstack_dashboard/local/local_settings.py `` . To do this quickly you can use the following command::
2012-08-15 11:03:57 -07:00
> cp openstack_dashboard/local/local_settings.py.example openstack_dashboard/local/local_settings.py
2011-11-08 09:25:35 -08:00
Horizon assumes a single end-point for OpenStack services which defaults to
the local host (127.0.0.1). If this is not the case change the
2012-08-15 11:03:57 -07:00
`` OPENSTACK_HOST `` setting in the `` openstack_dashboard/local/local_settings.py `` file, to the actual IP address of the OpenStack end-point Horizon should use.
2011-11-08 09:25:35 -08:00
2012-04-13 21:46:04 -07:00
To start the Horizon development server use the Django `` manage.py `` utility
2012-05-22 16:46:15 +10:00
with the context of the virtual environment::
2011-11-08 09:25:35 -08:00
2012-05-22 16:46:15 +10:00
> tools/with_venv.sh ./manage.py runserver
2011-11-08 09:25:35 -08:00
Alternately specify the listen IP and port::
2012-05-22 16:46:15 +10:00
> tools/with_venv.sh ./manage.py runserver 0.0.0.0:8080
2011-11-08 09:25:35 -08:00
2012-08-15 11:03:57 -07:00
.. note ::
If you would like to run commands without the prefix of `` tools/with_venv.sh `` you may source your environment directly. This will remain active as long as your shell session stays open::
> source .venv/bin/activate
2011-11-08 09:25:35 -08:00
Once the Horizon server is running point a web browser to http://localhost:8000
2012-08-15 11:03:57 -07:00
or to the IP and port the server is listening for.
2011-11-08 09:25:35 -08:00
2012-03-13 20:35:23 -07:00
.. note ::
The `` DevStack `` project (http://devstack.org/) can be used to install
an OpenStack development environment from scratch.
2011-11-08 09:25:35 -08:00
2012-03-13 13:11:16 -07:00
.. note ::
The minimum required set of OpenStack services running includes the
following:
2012-04-13 21:46:04 -07:00
* Nova (compute, api, scheduler, and network)
2012-03-13 13:11:16 -07:00
* Glance
* Keystone
Optional support is provided for Swift.
2011-10-31 11:31:05 -07:00
Horizon's Structure
===================
2012-01-04 14:46:40 -08:00
This project is a bit different from other OpenStack projects in that it has
two very distinct components underneath it: `` horizon `` , and
2012-05-22 16:46:15 +10:00
`` openstack_dashboard `` .
2011-10-31 11:31:05 -07:00
The `` horizon `` directory holds the generic libraries and components that can
2012-01-04 14:46:40 -08:00
be used in any Django project.
2011-10-31 11:31:05 -07:00
2012-05-22 16:46:15 +10:00
The `` openstack_dashboard `` directory contains a reference Django project that
2012-01-04 14:46:40 -08:00
uses `` horizon `` .
For development, both pieces share an environment which (by default) is
built with the `` tools/install_venv.py `` script. That script creates a
virtualenv and installs all the necessary packages.
2012-05-22 16:46:15 +10:00
If dependencies are added to either `` horizon `` or `` openstack_dashboard `` ,
2013-05-28 10:06:10 +02:00
they should be added to `` requirements.txt `` .
2011-10-31 11:31:05 -07:00
2011-11-10 17:08:04 -08:00
.. important ::
If you do anything which changes the environment (adding new dependencies
or renaming directories are both great examples) be sure to increment the
`` environment_version `` counter in :doc: `run_tests.sh <ref/run_tests>` .
2011-10-31 11:31:05 -07:00
Project
=======
2014-03-29 18:30:46 +01:00
Dashboard configuration
-----------------------
2011-10-31 11:31:05 -07:00
2014-03-29 18:30:46 +01:00
To add a new dashboard to your project, you need to add a configuration file to
`` openstack_dashboard/local/enabled `` directory. For more information on this,
see :ref: `pluggable-settings-label` .
2011-10-31 11:31:05 -07:00
2014-03-29 18:30:46 +01:00
There is also an alternative way to add a new dashboard, by adding it to
Django's `` INSTALLED_APPS `` setting. For more information about this, see
:ref: `dashboards` . However, please note that the recommended way is to take
advantage of the pluggable settings feature.
2011-10-31 11:31:05 -07:00
URLs
----
Then you add a single line to your project's `` urls.py `` ::
url(r'', include(horizon.urls)),
Those urls are automatically constructed based on the registered Horizon apps.
If a different URL structure is desired it can be constructed by hand.
Templates
---------
Pre-built template tags generate navigation. In your `` nav.html ``
template you might have the following::
{% load horizon %}
<div class='nav'>
{% horizon_main_nav %}
</div>
And in your `` sidebar.html `` you might have::
{% load horizon %}
<div class='sidebar'>
{% horizon_dashboard_nav %}
</div>
These template tags are aware of the current "active" dashboard and panel
via template context variables and will render accordingly.
Application
===========
Structure
---------
2014-03-29 18:30:46 +01:00
An application would have the following structure (we'll use project as
2011-10-31 11:31:05 -07:00
an example)::
2013-04-25 11:58:38 +02:00
project/
2011-10-31 11:31:05 -07:00
|---__init__.py
|---dashboard.py <-----Registers the app with Horizon and sets dashboard properties
|---overview/
2014-03-29 18:30:46 +01:00
|---images/
2013-04-25 11:58:38 +02:00
|-- images
|-- __init__.py
2011-10-31 11:31:05 -07:00
|---panel.py <-----Registers the panel in the app and defines panel properties
2013-04-25 11:58:38 +02:00
|-- snapshots/
|-- templates/
|-- tests.py
|-- urls.py
|-- views.py
2011-10-31 11:31:05 -07:00
...
...
Dashboard Classes
-----------------
Inside of `` dashboard.py `` you would have a class definition and the registration
process::
import horizon
2013-04-25 11:58:38 +02:00
....
# ObjectStorePanels is an example for a PanelGroup
# for panel classes in general, see below
class ObjectStorePanels(horizon.PanelGroup):
slug = "object_store"
name = _("Object Store")
panels = ('containers',)
class Project(horizon.Dashboard):
name = _("Project") # Appears in navigation
slug = "project" # Appears in URL
# panels may be strings or refer to classes, such as
# ObjectStorePanels
panels = (BasePanels, NetworkPanels, ObjectStorePanels)
2011-10-31 11:31:05 -07:00
default_panel = 'overview'
2013-04-25 11:58:38 +02:00
supports_tenants = True
2011-10-31 11:31:05 -07:00
...
2013-04-25 11:58:38 +02:00
horizon.register(Project)
2011-10-31 11:31:05 -07:00
Panel Classes
-------------
To connect a :class: `~horizon.Panel` with a :class: `~horizon.Dashboard` class
2013-10-24 15:11:38 -05:00
you register it in a `` panel.py `` file like so::
2011-10-31 11:31:05 -07:00
import horizon
2013-04-25 11:58:38 +02:00
from openstack_dashboard.dashboards.project import dashboard
2011-10-31 11:31:05 -07:00
class Images(horizon.Panel):
name = "Images"
slug = 'images'
2012-04-13 21:46:04 -07:00
permissions = ('openstack.roles.admin', 'my.other.permission',)
2011-10-31 11:31:05 -07:00
# You could also register your panel with another application's dashboard
2013-04-25 11:58:38 +02:00
dashboard.Project.register(Images)
2011-10-31 11:31:05 -07:00
By default a :class: `~horizon.Panel` class looks for a `` urls.py `` file in the
same directory as `` panel.py `` to include in the rollup of url patterns from
panels to dashboards to Horizon, resulting in a wholly extensible, configurable
URL structure.