Rewrite Merlin as a collection of Django apps for Horizon integration
Now a running Horizon instance is required to run Mistral Workbook builder. Instructions on integrating Merlin and its extensions (the first of which is Workbook Builder) are provided in README.md. Change-Id: I599ac46c9fd5369e42722b8d7a01d60c9f3323b8
This commit is contained in:
parent
e2428306cd
commit
83d579872a
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*.pyc
|
||||||
|
.venv
|
||||||
|
.tox
|
||||||
|
.idea
|
30
README.md
30
README.md
@ -1,9 +1,31 @@
|
|||||||
# Instructions on running Merlin/Mistral PoC
|
# Instructions on integrating Merlin extensions into Horizon
|
||||||
|
Although the repo contains directories meant to be used as Django apps
|
||||||
|
(with templates, static files, urls & views), the whole project is not
|
||||||
|
meant to be run as a standalone Django web-application (with its own
|
||||||
|
settings.py etc). Instead, it should be embedded into running Horizon
|
||||||
|
instance. To do so you should perform the following steps:
|
||||||
|
|
||||||
|
1. The easiest way to always use the latest version of Merlin is by using
|
||||||
|
symlinks. Identify the directory where ``openstack_dashboard`` and ``horizon``
|
||||||
|
reside. Let's assume this is ``/usr/lib/python2.7/site-packages`` and merlin
|
||||||
|
repo is located at ``/home/user/dev/merlin``. Then run the
|
||||||
|
following commands
|
||||||
```
|
```
|
||||||
git clone https://github.com/stackforge/merlin
|
# for main Merlin sources
|
||||||
cd merlin
|
ln -s /home/user/dev/merlin/merlin /usr/lib/python2.7/site-packages/merlin
|
||||||
python -m SimpleHTTPServer 8080
|
# for files of the Merlin's Mistral extension
|
||||||
|
ln -s /home/user/dev/merlin/extensions/mistral /usr/lib/python2.7/site-packages/mistral
|
||||||
```
|
```
|
||||||
|
|
||||||
|
2. Next thing to do is add panel with Mistral Workbook builder (a Merlin
|
||||||
|
extension) into Horizon. To do it, copy the pluggable config for the Mistral
|
||||||
|
panel:
|
||||||
|
```
|
||||||
|
cp /home/user/dev/merlin/extensions/enabled/_50_add_mistral_panel.py /usr/lib/python2.7/site-packages/openstack_dashboard/enabled/
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Restart Horizon web-server. According to the default values in
|
||||||
|
``_50_add_mistral_panel.py`` you would be able to **Mistral** panel inside
|
||||||
|
the **Project** dashboard, **Orchestration** panel group.
|
||||||
|
|
||||||
For more info please refer to https://wiki.openstack.org/wiki/Merlin
|
For more info please refer to https://wiki.openstack.org/wiki/Merlin
|
||||||
|
0
extensions/__init__.py
Normal file
0
extensions/__init__.py
Normal file
11
extensions/enabled/_50_add_mistral_panel.py
Normal file
11
extensions/enabled/_50_add_mistral_panel.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# The name of the panel to be added to HORIZON_CONFIG. Required.
|
||||||
|
PANEL = 'mistral'
|
||||||
|
# The name of the dashboard the PANEL associated with. Required.
|
||||||
|
PANEL_DASHBOARD = 'project'
|
||||||
|
# The name of the panel group the PANEL is associated with.
|
||||||
|
PANEL_GROUP = 'orchestration'
|
||||||
|
|
||||||
|
ADD_INSTALLED_APPS = ['merlin', 'mistral']
|
||||||
|
|
||||||
|
# Python panel class of the PANEL to be added.
|
||||||
|
ADD_PANEL = 'mistral.panel.MistralPanel'
|
0
extensions/mistral/__init__.py
Normal file
0
extensions/mistral/__init__.py
Normal file
20
extensions/mistral/panel.py
Normal file
20
extensions/mistral/panel.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Copyright (c) 2014 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import horizon
|
||||||
|
|
||||||
|
|
||||||
|
class MistralPanel(horizon.Panel):
|
||||||
|
name = 'Mistral'
|
||||||
|
slug = 'mistral'
|
24
extensions/mistral/templates/mistral/index.html
Normal file
24
extensions/mistral/templates/mistral/index.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{% extends "merlin/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Merlin Project{% endblock %}
|
||||||
|
{% block main %}
|
||||||
|
<div>
|
||||||
|
<div class="left">
|
||||||
|
<div id="toolbar">
|
||||||
|
<button id="create-workbook">New Workbook</button>
|
||||||
|
<button id="save-workbook">Save Workbook</button>
|
||||||
|
</div>
|
||||||
|
<div id="controls"></div>
|
||||||
|
</div>
|
||||||
|
<pre class="right"></pre>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block merlin-css %}
|
||||||
|
<link rel="stylesheet" href="{{ STATIC_URL }}mistral/css/mistral.css">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block merlin-js-scripts %}
|
||||||
|
<script src="{{ STATIC_URL }}mistral/js/schema.js"></script>
|
||||||
|
<script src="{{ STATIC_URL }}mistral/js/workbook.js"></script>
|
||||||
|
{% endblock %}
|
22
extensions/mistral/urls.py
Normal file
22
extensions/mistral/urls.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright (c) 2014 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from django.conf.urls import patterns
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from mistral import views
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||||
|
)
|
19
extensions/mistral/views.py
Normal file
19
extensions/mistral/views.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Copyright (c) 2014 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from django.views.generic import TemplateView # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class IndexView(TemplateView):
|
||||||
|
template_name = 'project/mistral/index.html'
|
25
index.html
25
index.html
@ -1,25 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head lang="en">
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Merlin Project</title>
|
|
||||||
<script src="js/lib/jquery-1.11.1.js"></script>
|
|
||||||
<script src="js/lib/barricade.js"></script>
|
|
||||||
<script src="js/schema.js"></script>
|
|
||||||
<script src="js/merlin.js"></script>
|
|
||||||
<script src="js/lib/js-yaml.js"></script>
|
|
||||||
<link rel="stylesheet" href="css/merlin.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div>
|
|
||||||
<div class="left">
|
|
||||||
<div id="toolbar">
|
|
||||||
<button id="create-workbook">New Workbook</button>
|
|
||||||
<button id="save-workbook">Save Workbook</button>
|
|
||||||
</div>
|
|
||||||
<div id="controls"></div>
|
|
||||||
</div>
|
|
||||||
<pre class="right"></pre>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
10308
js/lib/jquery-1.11.1.js
vendored
10308
js/lib/jquery-1.11.1.js
vendored
File diff suppressed because it is too large
Load Diff
0
merlin/__init__.py
Normal file
0
merlin/__init__.py
Normal file
13
merlin/templates/merlin/base.html
Normal file
13
merlin/templates/merlin/base.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{% include "horizon/_scripts.html" %}
|
||||||
|
<script src="{{ STATIC_URL }}merlin/lib/barricade.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="{{ STATIC_URL }}merlin/lib/js-yaml.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
{% block merlin-js-scripts %}{% endblock %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{% include "_stylesheets.html" %}
|
||||||
|
{% block merlin-css %}{% endblock %}
|
||||||
|
{% endblock %}
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Django>=1.4.2,<1.7
|
0
test-requirements.txt
Normal file
0
test-requirements.txt
Normal file
71
tools/install_venv.py
Normal file
71
tools/install_venv.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Copyright 2010 United States Government as represented by the
|
||||||
|
# Administrator of the National Aeronautics and Space Administration.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Copyright 2010 OpenStack Foundation
|
||||||
|
# Copyright 2013 IBM Corp.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import install_venv_common as install_venv # noqa
|
||||||
|
|
||||||
|
|
||||||
|
def print_help(venv, root):
|
||||||
|
help = """
|
||||||
|
OpenStack development environment setup is complete.
|
||||||
|
|
||||||
|
OpenStack development uses virtualenv to track and manage Python
|
||||||
|
dependencies while in development and testing.
|
||||||
|
|
||||||
|
To activate the OpenStack virtualenv for the extent of your current shell
|
||||||
|
session you can run:
|
||||||
|
|
||||||
|
$ source %s/bin/activate
|
||||||
|
|
||||||
|
Or, if you prefer, you can run commands in the virtualenv on a case by case
|
||||||
|
basis by running:
|
||||||
|
|
||||||
|
$ %s/tools/with_venv.sh <your command>
|
||||||
|
|
||||||
|
Also, make test will automatically use the virtualenv.
|
||||||
|
"""
|
||||||
|
print(help % (venv, root))
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
|
if os.environ.get('tools_path'):
|
||||||
|
root = os.environ['tools_path']
|
||||||
|
venv = os.path.join(root, '.venv')
|
||||||
|
if os.environ.get('venv'):
|
||||||
|
venv = os.environ['venv']
|
||||||
|
|
||||||
|
pip_requires = os.path.join(root, 'requirements.txt')
|
||||||
|
test_requires = os.path.join(root, 'test-requirements.txt')
|
||||||
|
py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
|
||||||
|
project = 'OpenStack'
|
||||||
|
install = install_venv.InstallVenv(root, venv, pip_requires, test_requires,
|
||||||
|
py_version, project)
|
||||||
|
options = install.parse_args(argv)
|
||||||
|
install.check_python_version()
|
||||||
|
install.check_dependencies()
|
||||||
|
install.create_virtualenv(no_site_packages=options.no_site_packages)
|
||||||
|
install.install_dependencies()
|
||||||
|
print_help(venv, root)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
172
tools/install_venv_common.py
Normal file
172
tools/install_venv_common.py
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
# Copyright 2013 OpenStack Foundation
|
||||||
|
# Copyright 2013 IBM Corp.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
"""Provides methods needed by installation script for OpenStack development
|
||||||
|
virtual environments.
|
||||||
|
|
||||||
|
Since this script is used to bootstrap a virtualenv from the system's Python
|
||||||
|
environment, it should be kept strictly compatible with Python 2.6.
|
||||||
|
|
||||||
|
Synced in from openstack-common
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import optparse
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class InstallVenv(object):
|
||||||
|
|
||||||
|
def __init__(self, root, venv, requirements,
|
||||||
|
test_requirements, py_version,
|
||||||
|
project):
|
||||||
|
self.root = root
|
||||||
|
self.venv = venv
|
||||||
|
self.requirements = requirements
|
||||||
|
self.test_requirements = test_requirements
|
||||||
|
self.py_version = py_version
|
||||||
|
self.project = project
|
||||||
|
|
||||||
|
def die(self, message, *args):
|
||||||
|
print(message % args, file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def check_python_version(self):
|
||||||
|
if sys.version_info < (2, 6):
|
||||||
|
self.die("Need Python Version >= 2.6")
|
||||||
|
|
||||||
|
def run_command_with_code(self, cmd, redirect_output=True,
|
||||||
|
check_exit_code=True):
|
||||||
|
"""Runs a command in an out-of-process shell.
|
||||||
|
|
||||||
|
Returns the output of that command. Working directory is self.root.
|
||||||
|
"""
|
||||||
|
if redirect_output:
|
||||||
|
stdout = subprocess.PIPE
|
||||||
|
else:
|
||||||
|
stdout = None
|
||||||
|
|
||||||
|
proc = subprocess.Popen(cmd, cwd=self.root, stdout=stdout)
|
||||||
|
output = proc.communicate()[0]
|
||||||
|
if check_exit_code and proc.returncode != 0:
|
||||||
|
self.die('Command "%s" failed.\n%s', ' '.join(cmd), output)
|
||||||
|
return (output, proc.returncode)
|
||||||
|
|
||||||
|
def run_command(self, cmd, redirect_output=True, check_exit_code=True):
|
||||||
|
return self.run_command_with_code(cmd, redirect_output,
|
||||||
|
check_exit_code)[0]
|
||||||
|
|
||||||
|
def get_distro(self):
|
||||||
|
if (os.path.exists('/etc/fedora-release') or
|
||||||
|
os.path.exists('/etc/redhat-release')):
|
||||||
|
return Fedora(
|
||||||
|
self.root, self.venv, self.requirements,
|
||||||
|
self.test_requirements, self.py_version, self.project)
|
||||||
|
else:
|
||||||
|
return Distro(
|
||||||
|
self.root, self.venv, self.requirements,
|
||||||
|
self.test_requirements, self.py_version, self.project)
|
||||||
|
|
||||||
|
def check_dependencies(self):
|
||||||
|
self.get_distro().install_virtualenv()
|
||||||
|
|
||||||
|
def create_virtualenv(self, no_site_packages=True):
|
||||||
|
"""Creates the virtual environment and installs PIP.
|
||||||
|
|
||||||
|
Creates the virtual environment and installs PIP only into the
|
||||||
|
virtual environment.
|
||||||
|
"""
|
||||||
|
if not os.path.isdir(self.venv):
|
||||||
|
print('Creating venv...', end=' ')
|
||||||
|
if no_site_packages:
|
||||||
|
self.run_command(['virtualenv', '-q', '--no-site-packages',
|
||||||
|
self.venv])
|
||||||
|
else:
|
||||||
|
self.run_command(['virtualenv', '-q', self.venv])
|
||||||
|
print('done.')
|
||||||
|
else:
|
||||||
|
print("venv already exists...")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def pip_install(self, *args):
|
||||||
|
self.run_command(['tools/with_venv.sh',
|
||||||
|
'pip', 'install', '--upgrade'] + list(args),
|
||||||
|
redirect_output=False)
|
||||||
|
|
||||||
|
def install_dependencies(self):
|
||||||
|
print('Installing dependencies with pip (this can take a while)...')
|
||||||
|
|
||||||
|
# First things first, make sure our venv has the latest pip and
|
||||||
|
# setuptools and pbr
|
||||||
|
self.pip_install('pip>=1.4')
|
||||||
|
self.pip_install('setuptools')
|
||||||
|
self.pip_install('pbr')
|
||||||
|
|
||||||
|
self.pip_install('-r', self.requirements, '-r', self.test_requirements)
|
||||||
|
|
||||||
|
def parse_args(self, argv):
|
||||||
|
"""Parses command-line arguments."""
|
||||||
|
parser = optparse.OptionParser()
|
||||||
|
parser.add_option('-n', '--no-site-packages',
|
||||||
|
action='store_true',
|
||||||
|
help="Do not inherit packages from global Python "
|
||||||
|
"install")
|
||||||
|
return parser.parse_args(argv[1:])[0]
|
||||||
|
|
||||||
|
|
||||||
|
class Distro(InstallVenv):
|
||||||
|
|
||||||
|
def check_cmd(self, cmd):
|
||||||
|
return bool(self.run_command(['which', cmd],
|
||||||
|
check_exit_code=False).strip())
|
||||||
|
|
||||||
|
def install_virtualenv(self):
|
||||||
|
if self.check_cmd('virtualenv'):
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.check_cmd('easy_install'):
|
||||||
|
print('Installing virtualenv via easy_install...', end=' ')
|
||||||
|
if self.run_command(['easy_install', 'virtualenv']):
|
||||||
|
print('Succeeded')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print('Failed')
|
||||||
|
|
||||||
|
self.die('ERROR: virtualenv not found.\n\n%s development'
|
||||||
|
' requires virtualenv, please install it using your'
|
||||||
|
' favorite package management tool' % self.project)
|
||||||
|
|
||||||
|
|
||||||
|
class Fedora(Distro):
|
||||||
|
"""This covers all Fedora-based distributions.
|
||||||
|
|
||||||
|
Includes: Fedora, RHEL, CentOS, Scientific Linux
|
||||||
|
"""
|
||||||
|
|
||||||
|
def check_pkg(self, pkg):
|
||||||
|
return self.run_command_with_code(['rpm', '-q', pkg],
|
||||||
|
check_exit_code=False)[1] == 0
|
||||||
|
|
||||||
|
def install_virtualenv(self):
|
||||||
|
if self.check_cmd('virtualenv'):
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.check_pkg('python-virtualenv'):
|
||||||
|
self.die("Please install 'python-virtualenv'.")
|
||||||
|
|
||||||
|
super(Fedora, self).install_virtualenv()
|
7
tools/with_venv.sh
Executable file
7
tools/with_venv.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
TOOLS_PATH=${TOOLS_PATH:-$(dirname $0)}
|
||||||
|
VENV_PATH=${VENV_PATH:-${TOOLS_PATH}}
|
||||||
|
VENV_DIR=${VENV_NAME:-/../.venv}
|
||||||
|
TOOLS=${TOOLS_PATH}
|
||||||
|
VENV=${VENV:-${VENV_PATH}/${VENV_DIR}}
|
||||||
|
source ${VENV}/bin/activate && "$@"
|
Loading…
Reference in New Issue
Block a user