OpenStack is an open source cloud computing project that is implemented predominantly in Python. OpenStack’s goal is to provide the "ubiquitous open source cloud computing platform for public and private clouds”. The OpenStack project was launched by Rackspace and NASA in July 2010. Since then the project has gained considerable momentum with over 200 companies joining the project, and the launch of commercial services and products that use OpenStack.
The OpenStack Horizon project provides a web-based User Interface to OpenStack services. It is constructed in two parts: (1) a core set of libraries for implementing a Dashboard; (2) a reference dashboard implementation that uses the core set of libraries. Customization is a core part of the Horizon Framework. The framework enables developers to construct their own dashboards, panel groups and panels, and enables them to assemble them together via a common navigation/presentation framework.
In this presentation, we will provide a brief introduction to OpenStack and Horizon. Then we will dive into the details of Horizon. We will review Horizon’s overall architecture and how it integrates with other OpenStack services. We will look at some of Horizon’s interesting features and describe how to get started developing with Horizon. Finally, we will discuss some of the current challenges facing Horizon and some future directions.
OpenStack Horizon: Controlling the Cloud using Django
1. OpenStack Horizon
Controlling the Cloud using Django
LA Django Meetup, February 18, 2014
David Lapsley
OpenStack Engineer, @metacloudinc
@devlaps, dlapsley@metacloud.com
2. About the Presenter
• David is a Lead OpenStack Software Engineer at Metacloud
• David has been using Python for over 10 years and Django for 5 years
• Education:
– Ph. D in Electrical and Electronics Engineering from the University of Melbourne
– B. Sc. and B. E. from Monash University.
• Personal Stuff:
– Originally from Melbourne, Australia. Now based in LA (via Boston). In his spare time, he
enjoys spending time with his family, cycling, and not shoveling snow
3. Our Agenda
• Introduction to Cloud Computing and
OpenStack
• OpenStack Horizon
– Controlling the Cloud with Django
– Interesting Patterns
– Example
– Contributing to Horizon
– Challenges and Future Directions
13. Cloud Computing
“Cloud computing is a model for enabling
convenient, on-demand network access to a
shared pool of configurable computing
resources
(e.g., networks, servers, storage, applications, an
d services) that can be rapidly provisioned and
released with minimal management effort or
service provider interaction.”
http://www.nist.gov/itl/cloud/
14. OpenStack
• Open Source Cloud Platform
– Build public/private clouds
– Multi-tenant
– Virtual machines on demand
– Storage volumes
• Founded in 2010 by Rackspace and NASA
• Since then, enormous growth…
24. Horizon Overview
• Django-based application that provides access
to OpenStack services
• Typically deployed as an Apache WSGI
application
• Leverages well known existing technologies
– Bootstrap, jQuery, Underscore.js, AngularJS, D3.js,
Rickshaw, LESS CSS
• Extends Django stack to enhance application
extensibility
49. Dashboards and Panels
• Horizon provides a flexible framework for
creating Dashboards and Panels
• Panels are grouped into PanelGroups
• PanelGroups into Dashboards
50. Dashboard App
• Dashboards are created as Django
Applications
• Dashboard modules partitioned into:
– static/
• Static media (css, js, img)
– templates/
• Django templates
– python modules:
• dashboard.py module which includes the class used by
Horizon
58. from django.utils.translation import ugettext_lazy as _
import horizon
from openstack_dashboard.dashboards.ladjango import dashboard
class Hypervisors(horizon.Panel):
name = _(”Hypervisors")
slug = 'hypervisors'
dashboard.LADjango.register(Hypervisors)
panel.py
60. View Module
• View module ties together everything
– Tables
– Templates
– API Calls
• Horizon base views:
– APIView, LoginView, MultiTableView, DataTableVie
w, MixedDataTableView, TabView, TabbedTableVie
w, WorkflowView
61. from openstack_dashboard import api
from openstack_dashboard.dashboards.ladjango.hypervisors
import tables as hypervisor_tables
class HypervisorsIndexView(tables.DataTableView):
table_class = hypervisor_tables.AdminHypervisorsTable
template_name = 'ladjango/hypervisors/index.html’
def get_data(self):
hypervisors = []
states = {}
hypervisors = api.nova.hypervisor_list(self.request)
for state in api.nova.service_list(self.request):
if state.binary == 'nova-compute':
states[state.host] = {'state': state.state,
'status': state.status}
for h in hypervisors:
h.service.update(states[getattr(h, h.NAME_ATTR)])
return hypervisors
views.py
62. Table Module
• Table classes provide framework for creating
tables with:
– consistent look and feel
– configurable table_actions row
– configurable row_actions
– select/multi-select column
– sorting
– pagination
• Functionality is split server- and clientside, however implementation is all serverside
63. class HypervisorsFilterAction(tables.FilterAction):
def filter(self, table, hypervisors, filter_string):
"""Naive case-insensitive search."""
q = filter_string.lower()
return [hypervisor for hypervisor in hypervisors
if q in hypervisor.name.lower()]
class EnableAction(tables.BatchAction):
...
class DisableAction(tables.BatchAction):
name = 'disable'
classes = ('btn-danger',)
def allowed(self, request, hypervisor):
return hypervisor.service.get('status') == 'enabled'
def action(self, request, obj_id):
hypervisor = api.nova.hypervisor_get(request, obj_id)
host = getattr(hypervisor, hypervisor.NAME_ATTR)
return api.nova.service_disable(request, host, 'nova-compute')
tables.py
64. def search_link(x):
return "/admin/instances?q={0}".format(x.hypervisor_hostname)
class AdminHypervisorsTable(tables.DataTable):
hypervisor_hostname = tables.Column(
"hypervisor_hostname", verbose_name=_("Hostname"))
state = tables.Column(
lambda hyp: hyp.service.get('state', _("UNKNOWN")).title(),
verbose_name=_("State"))
running_vms = tables.Column(
"running_vms",
link=search_link,
verbose_name=_("Instances"))
...
class Meta:
name = "hypervisors"
verbose_name = _("Hypervisors")
tables.py
71. Authentication
• Keystone manages all Authentication for
OpenStack
• To access an OpenStack service:
– authenticate with Keystone
– Obtain a TOKEN
– Use TOKEN for transactions with OpenStack
service
• Horizon passes all Auth requests to Keystone
via CUSTOM_BACKENDS
72. class MetacloudKeystoneBackend(KeystoneBackend):
def authenticate(self, request=None, username=None, password=None,
user_domain_name=None, auth_url=None):
keystone_client = get_keystone_client()
client = keystone_client.Client(
user_domain_name=user_domain_name,
username=username,
password=password,
auth_url=auth_url,
insecure=insecure,
cacert=ca_cert,
debug=settings.DEBUG)
# auth_ref gets assigned here…
# If we made it here we succeeded. Create our User!
user = create_user_from_token(
request,
Token(auth_ref))
request.user = user
return user
backend.py
74. Custom Overrides Module
• For site-wide customization, Horizon enables
you to define a python module that will be
loaded after Horizon Site has been configured
• Customizations can include:
– Registering or unregistering panels from an
existing dashboard
– Modifying dashboard or panel attributes
– Moving panels between dashboards
– Modifying attributes of existing UI elements
76. from openstack_dashboard.dashboards.ladjango.test import panel as
test_panel
from openstack_dashboard.dashboards.ladjango import dashboard
as ladjango_dashboard
from django.conf import settings
import horizon
LADJANGO_DASHBOARD_SETTINGS = horizon.get_dashboard('ladjango')
if settings.HORIZON_CONFIG.get('test_enabled'):
LADJANGO_DASHBOARD_SETTINGS.register(test_panel.Tests)
ladjango_dashboard.BasePanels.panels += ('ui', )
overrides.py
79. Custom CSS and Javascript
• Horizon templates provides blocks for custom
CSS and Javascript
• To add custom CSS/JS, can either extend
existing templates, or replace with your own
custom templates
87. Metacloud
• Community Support
• Contribute to OpenStack as much as possible
– Bug fixes, features
– Help out with code reviews, documentation
– Participate in design summits