96
OpenStack Horizon Controlling the Cloud using Django LA Django Meetup, February 18, 2014 David Lapsley OpenStack Engineer, @metacloudinc @devlaps, [email protected]

OpenStack Horizon: Controlling the Cloud using Django

Embed Size (px)

DESCRIPTION

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.

Citation preview

Page 1: OpenStack Horizon: Controlling the Cloud using Django

OpenStack HorizonControlling the Cloud using Django

LA Django Meetup, February 18, 2014

David LapsleyOpenStack Engineer, @metacloudinc

@devlaps, [email protected]

Page 2: OpenStack Horizon: Controlling the Cloud using Django

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

Page 3: OpenStack Horizon: Controlling the Cloud using Django

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

Page 4: OpenStack Horizon: Controlling the Cloud using Django

OpenStackLinux for the Cloud

Page 5: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing in Action

Creating a virtual server on a Public OpenStack Cloud

Page 6: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing in Action

Page 7: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing in Action

Page 8: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing in Action

Page 9: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing in Action

Page 10: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing in Action

Page 11: OpenStack Horizon: Controlling the Cloud using Django

Cloud Computing Model

Page 12: OpenStack Horizon: Controlling the Cloud using Django

Virtualization

Page 13: OpenStack Horizon: Controlling the Cloud using Django

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, and services) that can be rapidly provisioned and released with minimal management effort or service provider

interaction.”http://www.nist.gov/itl/cloud/

Page 14: OpenStack Horizon: Controlling the Cloud using Django

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…

Page 15: OpenStack Horizon: Controlling the Cloud using Django

Some interesting OpenStack facts …

Page 16: OpenStack Horizon: Controlling the Cloud using Django

OpenStack Source Code

Page 17: OpenStack Horizon: Controlling the Cloud using Django

OpenStack Source Code

Page 18: OpenStack Horizon: Controlling the Cloud using Django

OpenStack Contributors

Page 19: OpenStack Horizon: Controlling the Cloud using Django

14, 175 People132 Countries

http://www.openstack.org

Page 20: OpenStack Horizon: Controlling the Cloud using Django

“Linux for the Cloud”

Page 21: OpenStack Horizon: Controlling the Cloud using Django

OpenStack Projects

• Nova (Compute)– Virtual servers on demand

• Nova (Network)– Manages virtual network resources

• VM Registration (Glance)– Catalog and manage server images

• Identity (Keystone)– Unified authentication and authorization

Page 22: OpenStack Horizon: Controlling the Cloud using Django

OpenStack Projects

• Object Storage (Swift)– Secure, reliable object storage

• Block Storage (Cinder)– Persistent block storage to VMs

• Dashboard (Horizon)– Web-based UI for all OpenStack Services

– Many, many, more: Heat, Neutron, Ceilometer, Reddwarf, ..

Page 23: OpenStack Horizon: Controlling the Cloud using Django

OpenStack HorizonControlling the Cloud with Django

Page 24: OpenStack Horizon: Controlling the Cloud using Django

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

Page 25: OpenStack Horizon: Controlling the Cloud using Django

Django Stack

Page 26: OpenStack Horizon: Controlling the Cloud using Django

Horizon Stack

Page 27: OpenStack Horizon: Controlling the Cloud using Django

Horizon UI Structure (logical)

Sidebar

Panel Group

Panel

User Info

Panel Content

Branding

Dashboard

Page 28: OpenStack Horizon: Controlling the Cloud using Django

Horizon UI Structure (logical)

Project Dropdown

Project Dashboard

Page 29: OpenStack Horizon: Controlling the Cloud using Django

Horizon UI Structure (CSS)

Page 30: OpenStack Horizon: Controlling the Cloud using Django

Horizon Base Demo

Page 31: OpenStack Horizon: Controlling the Cloud using Django

Admin Overview

Page 32: OpenStack Horizon: Controlling the Cloud using Django

Project Overview

Page 33: OpenStack Horizon: Controlling the Cloud using Django

Launching an Instance

Page 34: OpenStack Horizon: Controlling the Cloud using Django

Horizon Base Demo

Page 35: OpenStack Horizon: Controlling the Cloud using Django

Horizon Base Demo

Page 36: OpenStack Horizon: Controlling the Cloud using Django

Horizon Base Demo

Page 37: OpenStack Horizon: Controlling the Cloud using Django

Instance List

Page 38: OpenStack Horizon: Controlling the Cloud using Django

Filtering

Page 39: OpenStack Horizon: Controlling the Cloud using Django

Sorting

Page 40: OpenStack Horizon: Controlling the Cloud using Django

Horizon Base Demo

Page 41: OpenStack Horizon: Controlling the Cloud using Django

Row Actions

Page 42: OpenStack Horizon: Controlling the Cloud using Django

Table Actions

Page 43: OpenStack Horizon: Controlling the Cloud using Django

Table Actions

Page 44: OpenStack Horizon: Controlling the Cloud using Django

Table Actions

Page 45: OpenStack Horizon: Controlling the Cloud using Django

Instance Details

Page 46: OpenStack Horizon: Controlling the Cloud using Django

Instance Details

Page 47: OpenStack Horizon: Controlling the Cloud using Django

Instance Console

Page 48: OpenStack Horizon: Controlling the Cloud using Django

OpenStack HorizonInteresting Patterns

Page 49: OpenStack Horizon: Controlling the Cloud using Django

Dashboards and Panels

• Horizon provides a flexible framework for creating Dashboards and Panels

• Panels are grouped into PanelGroups• PanelGroups into Dashboards

Page 50: OpenStack Horizon: Controlling the Cloud using Django

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

Page 51: OpenStack Horizon: Controlling the Cloud using Django

‣openstack_dashboard‣dashboards

‣admin‣ladjango

‣static‣ladjango

‣css‣img‣js

‣templates‣ladjango__init__.pydashboard.py

Dashboard Directory Structure

Page 52: OpenStack Horizon: Controlling the Cloud using Django

INSTALLED_APPS = ( ... 'horizon', 'openstack_dashboard.dashboards.project', 'openstack_dashboard.dashboards.admin', 'openstack_dashboard.dashboards.metacloud', 'openstack_dashboard.dashboards.settings', 'openstack_dashboard.dashboards.ladjango', ...)

settings.py

Page 53: OpenStack Horizon: Controlling the Cloud using Django

from django.utils.translation import ugettext_lazy as _ import horizon class BasePanelGroup(horizon.PanelGroup): slug = "overview" name = _("Overview") panels = (”hypervisors",) class LADjango(horizon.Dashboard): name = _("LA Django") slug = "ladjango" panels = (BasePanelGroup,) default_panel = "hypervisors" roles = ("admin",) horizon.register(LADjango)

dashboard.py

Page 54: OpenStack Horizon: Controlling the Cloud using Django

Starting Point

Page 55: OpenStack Horizon: Controlling the Cloud using Django

LA Django Dashboard

Dashboard Tab

Panel Group

Page 56: OpenStack Horizon: Controlling the Cloud using Django

Panel

• Panels are created as Python Modules• Panel modules partitioned into:

– static/• Static media (css, js, img)

– templates/• Django templates

– python modules:• urls.py, views.py, panel.py• tables.py, forms.py, tabs.py, tests.py

Page 57: OpenStack Horizon: Controlling the Cloud using Django

‣ladjango‣ hypervisors__init__.pypanel.pyurls.pyviews.pytests.pytables.py...

‣ static‣ ladjango

‣ hypervisors‣ css‣ img‣ js

‣ templates‣ ladjango

‣ hypervisorsindex.html...

__init__.pydashboard.py

Panel Directory Structure

Page 58: OpenStack Horizon: Controlling the Cloud using Django

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

Page 59: OpenStack Horizon: Controlling the Cloud using Django

LA Django Dashboard

Panel Nav Entry

Page 60: OpenStack Horizon: Controlling the Cloud using Django

View Module

• View module ties together everything– Tables– Templates– API Calls

• Horizon base views:– APIView, LoginView, MultiTableView,

DataTableView, MixedDataTableView, TabView, TabbedTableView, WorkflowView

Page 61: OpenStack Horizon: Controlling the Cloud using Django

views.py

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

Page 62: OpenStack Horizon: Controlling the Cloud using Django

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 client-side, however implementation is all server-side

Page 63: OpenStack Horizon: Controlling the Cloud using Django

tables.py

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')

Page 64: OpenStack Horizon: Controlling the Cloud using Django

tables.py

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")

table_actions = (HypervisorsFilterAction, )

row_actions = (EnableAction, DisableAction)

Page 65: OpenStack Horizon: Controlling the Cloud using Django

Template

• Standard Django template format• Typically leverage base horizon templates (e.g.

base.html)

Page 66: OpenStack Horizon: Controlling the Cloud using Django

index.html

{% extends 'base.html' %}

{% load i18n horizon humanize sizeformat %}

{% block title %}{% trans "Hypervisors" %}{% endblock %}

{% block page_header %}

{% include "horizon/common/_page_header.html" with title=_("All Hypervisors") %}

{% endblock page_header %}

{% block main %}

{{ table.render }}

{% endblock %}

Page 67: OpenStack Horizon: Controlling the Cloud using Django

URLs Modules

• Provides URL to View mappings

Page 68: OpenStack Horizon: Controlling the Cloud using Django

from django.conf.urls import patterns from django.conf.urls import url from openstack_dashboard.dashboards.ladjango.hypervisors\

import views urlpatterns = patterns( 'openstack_dashboard.dashboards.ladjango.hypervisors.views' url(r'^$', views.IndexView.as_view(), name='index'),)

urls.py

Page 69: OpenStack Horizon: Controlling the Cloud using Django

Completed Dashboard!

Nav Entries

Column Sorting

Table Action

State Aware Row ActionsPanel Rendering

Data Retrieval RPC

Linking

Page 70: OpenStack Horizon: Controlling the Cloud using Django

Click through to Instances

Page 71: OpenStack Horizon: Controlling the Cloud using Django

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

Page 72: OpenStack Horizon: Controlling the Cloud using Django

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

Page 73: OpenStack Horizon: Controlling the Cloud using Django

Customization Hooks

• Change Site Title, Logo, Brand Links• Modify Dashboards and Panels• Change Button Styles• Use Custom Stylesheets• Use Custom Javascript

Page 74: OpenStack Horizon: Controlling the Cloud using Django

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

Page 75: OpenStack Horizon: Controlling the Cloud using Django

HORIZON_CONFIG = {

...

'customization_module':

'openstack_dashboard.dashboards.ladjango.overrides',

'test_enabled': True,

}

local_settings.py

Page 76: OpenStack Horizon: Controlling the Cloud using Django

overrides.py

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', )

Page 77: OpenStack Horizon: Controlling the Cloud using Django

Full LA Django Dashboard

Page 78: OpenStack Horizon: Controlling the Cloud using Django

Test Panel

Page 79: OpenStack Horizon: Controlling the Cloud using Django

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

Page 80: OpenStack Horizon: Controlling the Cloud using Django

<!DOCTYPE html>

<html>

<head>

<title>{% block title %}{% endblock %} - {% site_branding %}</title>

{% block css %}

{% include "_stylesheets.html" %}

{% endblock %}

. . .

</head>

<body id="{% block body_id %}{% endblock %}">

{% block content %}

. . .

{% endblock %}

<div id="footer”>{% block footer %}{% endblock %}</div>

{% block js %}

{% include "horizon/_scripts.html" %}

{% endblock %}

</body>

</html>

base.html

Page 81: OpenStack Horizon: Controlling the Cloud using Django

index.html

{% extends 'base.html' %}

{% load i18n %}

{% block title %}{% trans "Volumes" %}{% endblock %}

{% block css %}

{% include "ladjango/_stylesheets.html" %}

{% endblock %}

{% block page_header %}

{% include "horizon/common/_page_header.html" with title=_("Volumes") %}

{% endblock page_header %}

{% block main %}

<div id="volumes">{{ volumes_table.render }}</div>

<div id="volume-types">{{ volume_types_table.render }}</div>

{% endblock %}

{% block js%}

{% include "ladjango/_scripts.html" %}

{% endblock %}

Page 82: OpenStack Horizon: Controlling the Cloud using Django

Horizon Base View

Page 83: OpenStack Horizon: Controlling the Cloud using Django

Custom View

Page 84: OpenStack Horizon: Controlling the Cloud using Django

About Metacloud

Page 85: OpenStack Horizon: Controlling the Cloud using Django

Metacloud

Takes the best of OpenStack and enhances it to deliver a fully scalable, highly

available, and customizable cloud platform.

Page 86: OpenStack Horizon: Controlling the Cloud using Django

Metacloud OpenStack

• High Availability

• Scalability• Patches/Fixes• Enhanced UI

Cloud Operations

• Install• Monitor• Upgrade

Services

• On-Prem Private Cloud

• Hosted Private Cloud

Metacloud

Page 87: OpenStack Horizon: Controlling the Cloud using Django

Metacloud

• Community Support• Contribute to OpenStack as much as possible

– Bug fixes, features– Help out with code reviews, documentation– Participate in design summits

Page 88: OpenStack Horizon: Controlling the Cloud using Django

OpenStack HorizonContributing

Page 89: OpenStack Horizon: Controlling the Cloud using Django

Devstack and Contributing

• Devstack:– “A documented shell script to build complete

OpenStack development environments.”– http://devstack.org

• Contributing to Horizon:– http://docs.openstack.org/developer/horizon/

contributing.html

Page 90: OpenStack Horizon: Controlling the Cloud using Django

Challenges and Future Directions

Page 91: OpenStack Horizon: Controlling the Cloud using Django

Challenges

• Bugs!• Performance• Evolving Architecture in a Smooth Manner

Page 92: OpenStack Horizon: Controlling the Cloud using Django

Future Directions

• Evolving the client: AngularJS• Search/Data Service Model

Page 93: OpenStack Horizon: Controlling the Cloud using Django

Lastly…

Page 94: OpenStack Horizon: Controlling the Cloud using Django

References

• IRC channels (freenode.net)– #openstack-dev– #openstack-horizon– #openstack-meeting

• Web:– http://docs.openstack.org/developer/horizon/– https://launchpad.net/horizon– http://devstack.org– https://github.com/openstack– https://github.com/openstack/horizon– http://docs.openstack.org/developer/horizon/– http://docs.openstack.org/developer/horizon/topics/settings.html– https://wiki.openstack.org/wiki/Gerrit_Workflow

Page 95: OpenStack Horizon: Controlling the Cloud using Django

References

• Web:– http://www.stackalytics.com– http://activity.openstack.org/dash/browser/– http://gabrielhurley.github.io/slides/openstack/

building_on_horizon/– http://www.solinea.com/blog/openstack-grizzly-

architecture-revisited

Page 96: OpenStack Horizon: Controlling the Cloud using Django

For more information visit:

metacloud.com

Thank You

[email protected]

@devlaps