Commit 44719ea4 authored by Ayush Tiwari's avatar Ayush Tiwari

Wendelin: Add jupyter(ipython-notebook) to wendelin software release

Now we have a combined software release for wendelin(erp5-cluster) and ipython-notebook(jupyter).
The main instance wendelin will request for notebook as well as erp5-cluster.
Different software-types available are :-
1. default - Will behave exactly same as default for erp5-cluster. Return parameters for various softwares in erp5-cluster.
2. create-erp5-site: Will create erp5-bootstrap service and start erp5.

In the parameters, users have to provide with "jupyter-family" key whose value would be the family user wants jupyter to use while interacting with erp5.
parent f99b8fae
[buildout]
parts =
request-erp5
dynamic-publish-default-information
publish-erp5-request-parameters
eggs-directory = {{ parameter_dict['eggs_directory'] }}
develop-eggs-directory = {{ parameter_dict['develop_eggs_directory'] }}
offline = true
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
key = ${slap-connection:key-file}
cert = ${slap-connection:cert-file}
[slap_connection]
# Kept for backward compatiblity
computer_id = ${slap-connection:computer-id}
partition_id = ${slap-connection:partition-id}
server_url = ${slap-connection:server-url}
software_release_url = ${slap-connection:software-release-url}
key_file = ${slap-connection:key-file}
cert_file = ${slap-connection:cert-file}
[request-erp5]
<= slap-connection
recipe = slapos.cookbook:request
name = ERP5
software-url = ${slap-connection:software-release-url}
{% if slap_software_type=='default'-%}
{% set software_type='erp5-cluster-default'-%}
{% elif slap_software_type=='create-erp5-site' -%}
{% set software_type='erp5-cluster-create-erp5-site'-%}
{% else -%}
{% set software_type=slap_software_type -%}
{% endif -%}
software-type = {{ software_type }}
sla-computer_guid = ${slap-connection:computer-id}
# Dirty hack to show all connection and instance parameters
# Must be changed after updating request recipe to show all the published
# parameters at once, something like exporter parameter in request recipe which
# calls getConnectionParameterDict()
# Other option would be to give some parameter in slapconfiguration recipe from
# where once can get ConnectionParameterDict, as for now we can get
# InstanceParameterDict using configuration parameter in slapconfiguration recipe,
# but there is no such param for connection parameters which is just unfortunate
config-_ = {{ json_module.dumps(slapparameter_dict) }}
return = _
[publish-erp5-request-parameters]
recipe = slapos.cookbook:switch-softwaretype
profile = dynamic-publish-default-information:rendered
[erp5-published-values]
erp5_request_parameters = ${request-erp5:connection-_}
{% set jupyter_family = slapparameter_dict.get('jupyter-family') -%}
[dynamic-publish-default-information]
recipe = slapos.recipe.template:jinja2
rendered = ${buildout:directory}/${:filename}
context =
key eggs_directory buildout:eggs-directory
key develop_eggs_directory buildout:develop-eggs-directory
${:extra-context}
template = {{ template_publish_information }}
filename = dynamic-publish-default-information.cfg
extensions = jinja2.ext.do
extra-context =
import json_module json
raw jupyter_family {{ jupyter_family }}
section erp5_published_values erp5-published-values
[buildout]
parts =
instance
publish-connection-parameter
## Monitoring part XXX whe should not have to specify all parts like this
## Parts to add for monitoring
certificate-authority
cron
cron-entry-monitor
cron-entry-rss
deploy-index
deploy-settings-cgi
deploy-status-cgi
deploy-status-history-cgi
setup-static-files
certificate-authority
zero-parameters
public-symlink
cgi-httpd-wrapper
cgi-httpd-graceful-wrapper
monitor-promise
monitor-instance-log-access
## Monitor for ipython
monitor-current-log-access
monitor-deploy-set-password-cgi
erp5-kernel
kernel-json
extends = {{ parameter_dict['monitor-template'] }}
eggs-directory = {{ parameter_dict['eggs_directory'] }}
develop-eggs-directory = {{ parameter_dict['develop_eggs_directory'] }}
offline = true
[slapconfiguration]
recipe = slapos.cookbook:slapconfiguration
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
key = ${slap-connection:key-file}
cert = ${slap-connection:cert-file}
configuration.erp5_url = {{ dumps(slapparameter_dict['erp5_url']) }}
[instance-parameter]
port = 8888
host = ${slapconfiguration:ipv6-random}
cert_file = ${generate-certificate:cert_file}
key_file = ${generate-certificate:key_file}
logfile = ${directory:log}/ipython_notebook.log
notebook_dir = ${directory:notebook_dir}
[generate-certificate]
; TODO: there is a slapos recipe to generate certificates. Use it instead
recipe = plone.recipe.command
command =
if [ ! -e ${instance-parameter:key_file} ]
then
{{ parameter_dict['openssl_output'] }} req -x509 -nodes -days 3650 \
-subj "/C=AA/ST=X/L=X/O=Dis/CN=${instance-parameter:host}" \
-newkey rsa:1024 -keyout ${instance-parameter:key_file} \
-out ${instance-parameter:cert_file}
fi
update-command = ${:command}
cert_file = ${directory:etc}/ipython_notebook_cert.crt
key_file = ${directory:etc}/ipython_notebook_cert.key
[instance]
recipe = slapos.cookbook:wrapper
command-line =
{{ parameter_dict['bin_directory'] }}/ipython notebook
--no-browser
--matplotlib=inline
--ip=${instance-parameter:host}
--port=${instance-parameter:port}
--port-retries=0
--certfile=${instance-parameter:cert_file}
--keyfile=${instance-parameter:key_file}
--notebook-dir=${instance-parameter:notebook_dir}
--logfile=${instance-parameter:logfile}
--config=${ipython_notebook_config:rendered}
## Adding log-level as parameter helps in checking error from ipython-notebook
## service.
--log-level="DEBUG"
wrapper-path = ${directory:service}/ipython_notebook
parameters-extra = true
environment = IPYTHONDIR=${directory:ipython_dir}
[ipython_notebook_config]
recipe = slapos.recipe.template:jinja2
template = {{ parameter_dict['ipython_notebook_config_location'] }}/{{ parameter_dict['ipython_notebook_config_filename'] }}
rendered = ${directory:etc}/ipython_notebook_config.py
mode = 0744
context =
raw config_cfg ${buildout:directory}/knowledge0.cfg
raw ipython_dir ${directory:ipython_dir}
[monitor-current-log-access]
< = monitor-directory-access
source = ${instance-parameter:logfile}
[monitor-deploy-set-password-cgi]
recipe = slapos.recipe.template:jinja2
template = {{ parameter_dict['ipython_notebook_set_password_location'] }}/{{ parameter_dict['ipython_notebook_set_password_filename'] }}
rendered = ${monitor-directory:knowledge0-cgi}/${:filename}
filename = ipython-notebook-password.cgi
mode = 0744
context =
raw config_cfg ${buildout:directory}/knowledge0.cfg
raw python_executable {{ parameter_dict['bin_directory'] }}/ipython
key pwd monitor-directory:knowledge0-cgi
key this_file :filename
key httpd_graceful cgi-httpd-graceful-wrapper:rendered
[directory]
recipe = slapos.cookbook:mkdirectory
home = ${buildout:directory}
etc = ${:home}/etc
var = ${:home}/var
script = ${:etc}/run/
service = ${:etc}/service
promise = ${:etc}/promise/
log = ${:var}/log
notebook_dir = ${:var}/notebooks
ipython_dir = ${:home}/ipython
ipython_kernel_dir = ${:ipython_dir}/kernels
erp5_kernel_dir = ${:ipython_kernel_dir}/ERP5
[publish-connection-parameter]
recipe = slapos.cookbook:publish.serialised
url = https://[${instance-parameter:host}]:${instance-parameter:port}
monitor_url = ${monitor-parameters:url}
erp5_url = ${slapconfiguration:configuration.erp5_url}
[erp5-kernel]
recipe = slapos.recipe.template:jinja2
template = {{ parameter_dict['erp5_kernel_location'] }}/{{ parameter_dict['erp5_kernel_filename'] }}
rendered = ${directory:erp5_kernel_dir}/ERP5kernel.py
mode = 0744
context =
raw python_executable {{ parameter_dict['bin_directory'] }}/pythonwitheggs
key erp5_url slapconfiguration:configuration.erp5_url
[kernel-json]
recipe = slapos.recipe.template:jinja2
template = {{ parameter_dict['kernel_json_location'] }}/{{ parameter_dict['kernel_json_filename'] }}
rendered = ${directory:erp5_kernel_dir}/kernel.json
mode = 0744
context =
raw python_executable {{ parameter_dict['bin_directory'] }}/pythonwitheggs
key kernel_dir erp5-kernel:rendered
raw display_name ERP5
raw language_name python
{
"$schema": "http://json-schema.org/draft-04/schema#",
"extends": "./schema-definitions.json#",
"description": "Parameters to instantiate wendelin release with jupyter",
"additionalProperties": {
"$ref": "../erp5/instance-erp5-input-schema.json#properties"
},
"properties": {
"jupyter-family": {
"description": "Family name to be used in jupyter(ipython-notebook) erp5-url",
"default": "default",
"type": "string"
}
}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Values returned by Wendelin instantiation",
"additionalProperties": {
"$ref": "../erp5/instance-erp5-output-schema.json#properties"
},
"properties": {
"notebook-url": {
"description": "IPython Notebook url",
"type": "string"
},
"jupyter-family-url": {
"description": "erp5v family url used in jupyter/ipython-notebook",
"type": "string"
},
"error-message": {
"description": "Error message in case of missing jupyter family or wrong family name",
"type": "string"
}
}
}
[buildout]
extends = {{ template_erp5_cluster }}
parts =
switch-softwaretype
eggs-directory = {{ eggs_directory }}
develop-eggs-directory ={{ develop_eggs_directory }}
offline = true
[dynamic-template-notebook-parameters]
bin_directory = {{ bin_directory }}
develop_eggs_directory = {{ develop_eggs_directory }}
eggs_directory = {{ eggs_directory }}
openssl_output = {{ openssl_output }}
ipython_notebook_config_location = {{ ipython_notebook_config_location }}
ipython_notebook_config_filename = {{ ipython_notebook_config_filename }}
ipython_notebook_set_password_location = {{ ipython_notebook_set_password_location }}
ipython_notebook_set_password_filename = {{ ipython_notebook_set_password_filename }}
erp5_kernel_location = {{ erp5_kernel_location }}
erp5_kernel_filename = {{ erp5_kernel_filename }}
kernel_json_location = {{ kernel_json_location }}
kernel_json_filename = {{ kernel_json_filename }}
monitor-template = {{ monitor_template }}
[dynamic-template-notebook]
< = jinja2-template-base
template = {{ template_notebook }}
filename = instance-notebook.cfg
extensions = jinja2.ext.do
extra-context =
section parameter_dict dynamic-template-notebook-parameters
[dynamic-template-default-parameters]
instance-erp5-site = ${dynamic-template-create-erp5-site:rendered}
eggs_directory = {{ eggs_directory }}
develop_eggs_directory = {{ develop_eggs_directory }}
[dynamic-template-default]
< = jinja2-template-base
template = {{template_default}}
filename = instance-default.cfg
extensions = jinja2.ext.do
extra-context =
import json_module json
raw template_publish_information {{ template_publish_information }}
key slap_software_type slap-configuration:slap-software-type
section parameter_dict dynamic-template-default-parameters
[switch-softwaretype]
recipe = slapos.cookbook:switch-softwaretype
default = dynamic-template-default:rendered
create-erp5-site = dynamic-template-default:rendered
notebook = dynamic-template-notebook:rendered
erp5-cluster-create-erp5-site = dynamic-template-create-erp5-site:rendered
erp5-cluster-default = dynamic-template-erp5:rendered
[buildout] [buildout]
versions = versions versions = versions
extends = extends =
../../software/ipython_notebook/software.cfg ../../stack/slapos.cfg
../../stack/monitor/buildout.cfg
../../component/fluentd/buildout.cfg ../../component/fluentd/buildout.cfg
../../component/matplotlib/buildout.cfg ../../component/matplotlib/buildout.cfg
../../component/ipython/buildout.cfg ../../component/ipython/buildout.cfg
...@@ -10,9 +11,14 @@ extends = ...@@ -10,9 +11,14 @@ extends =
../../component/msgpack-python/buildout.cfg ../../component/msgpack-python/buildout.cfg
../../component/scipy/buildout.cfg ../../component/scipy/buildout.cfg
../../component/scikit-learn/buildout.cfg ../../component/scikit-learn/buildout.cfg
../../component/pandas/buildout.cfg
../../component/manpy/buildout.cfg
../../software/erp5/software.cfg ../../software/erp5/software.cfg
parts += parts +=
slapos-cookbook
slapos-cookbook-develop
wendelin wendelin
jupyter_wendelin
scipy scipy
scikit-learn scikit-learn
pandas pandas
...@@ -22,6 +28,24 @@ parts += ...@@ -22,6 +28,24 @@ parts +=
matplotlib matplotlib
fluentd fluentd
ipython_notebook ipython_notebook
template-notebook
template-default
template-erp5-cluster
instance
[ipython_notebook]
; In the ipython notebook software, we use more eggs than in the minimal
; ipython notebook component
eggs +=
requests
${manpy:eggs}
initialization +=
${manpy:initialization}
[slapos.cookbook-repository]
recipe = slapos.recipe.build:gitclone
repository = http://git.erp5.org/repos/slapos.git
branch = wendelin_notebook
[eggs] [eggs]
initialization = initialization =
...@@ -29,6 +53,7 @@ initialization = ...@@ -29,6 +53,7 @@ initialization =
extra-paths += extra-paths +=
${wendelin:location} ${wendelin:location}
eggs += eggs +=
cns.recipe.symlink
${scikit-learn:egg} ${scikit-learn:egg}
${scipy:egg} ${scipy:egg}
${pandas:egg} ${pandas:egg}
...@@ -42,15 +67,113 @@ repository_id_list += wendelin ...@@ -42,15 +67,113 @@ repository_id_list += wendelin
[local-bt5-repository] [local-bt5-repository]
# we need to override it # we need to override it
list = ${erp5:location}/bt5 ${erp5:location}/product/ERP5/bootstrap ${wendelin:location}/bt5/ list = ${erp5:location}/bt5 ${erp5:location}/product/ERP5/bootstrap ${wendelin:location}/bt5/ ${jupyter_wendelin:location}/bt5/
bt5_list = erp5_full_text_myisam_catalog erp5_configurator_standard erp5_configurator_maxma_demo erp5_configurator_ung erp5_configurator_run_my_doc erp5_configurator_ebusiness_lotse erp5_wendelin_configurator bt5_list = erp5_full_text_myisam_catalog erp5_configurator_standard erp5_configurator_maxma_demo erp5_configurator_ung erp5_configurator_run_my_doc erp5_configurator_ebusiness_lotse erp5_wendelin_configurator erp5_data_notebook
[wendelin] [wendelin]
<= erp5 <= erp5
repository = https://lab.nexedi.cn/nexedi/wendelin.git repository = https://lab.nexedi.cn/nexedi/wendelin.git
branch = master branch = master
[jupyter_wendelin]
<= erp5
repository = https://lab.nexedi.cn/tiwariayush/erp5.git
branch = erp5-data-notebook
[ipython_notebook_config]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
download-only = true
destination = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = ipython_notebook_config.py.jinja
mode = 0644
md5sum = f10b145fb15a35ffd6b3d1a6ecfef86f
[ipython_notebook_set_password]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
download-only = true
destination = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = ipython_set_password.py.jinja
mode = 0644
md5sum = ffd4b98e4665ce7ea52cdaec02aefa4e
[erp5-kernel]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
download-only = true
destination = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = ERP5kernel.py.jinja
mode = 0644
md5sum = 2508d67bec241e27e0c696a61f325876
[kernel-json]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename}
download-only = true
destination = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = kernel.json.jinja
mode = 0644
md5sum = ab6e78ea20855e07d388b5b86d1770fe
[instance]
recipe = slapos.recipe.template:jinja2
template = ${:_profile_base_location_}/instance.cfg.in
rendered = ${buildout:directory}/template.cfg
mode = 0644
md5sum = bad629610dd6e12e87f1a72aa12f968b
context =
key slapos_core_version versions:slapos.core
key bin_directory buildout:bin-directory
key develop_eggs_directory buildout:develop-eggs-directory
key eggs_directory buildout:eggs-directory
key template_notebook template-notebook:target
key template_default template-default:target
key template_erp5_cluster template-erp5-cluster:rendered
key template_publish_information template-publish-information:target
key monitor_template monitor-template:output
key openssl_output openssl-output:openssl
key ipython_notebook_config_location ipython_notebook_config:location
key ipython_notebook_config_filename ipython_notebook_config:filename
key ipython_notebook_set_password_location ipython_notebook_set_password:location
key ipython_notebook_set_password_filename ipython_notebook_set_password:filename
key erp5_kernel_location erp5-kernel:location
key erp5_kernel_filename erp5-kernel:filename
key kernel_json_location kernel-json:location
key kernel_json_filename kernel-json:filename
[template-erp5-cluster]
<= template
#recipe = slapos.recipe.template:jinja2
#template = ${:_profile_base_location_}/../../stack/erp5/instance.cfg.in
rendered = ${buildout:directory}/template-erp5-cluster.cfg
[template-notebook]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/instance-notebook.cfg.in
md5sum = b18be2954fd3a7986068a9657398bb9e
mode = 644
[template-default]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/instance-default.cfg.in
md5sum = d9a6c2ed8b165e5f1c28e04c73227a19
mode = 644
[template-publish-information]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/template/publish-default-information.cfg.in
mode = 644
md5sum = ca49685a82883538346361cc0a1fee22
[versions] [versions]
PyRSS2Gen = 1.1
cns.recipe.symlink = 0.2.3
matplotlib = 1.4.3
mistune = 0.5.1
nose = 1.3.6
pandas = 0.16.1
pyzmq = 14.6.0
scikit-learn = 0.16.1 scikit-learn = 0.16.1
scipy = 0.15.1 scipy = 0.15.1
pandas = 0.16.1 pandas = 0.16.1
...@@ -59,3 +182,63 @@ numpy = 1.9.2 ...@@ -59,3 +182,63 @@ numpy = 1.9.2
wendelin.core = 0.4 wendelin.core = 0.4
ipython = 3.2.0 ipython = 3.2.0
matplotlib = 1.4.3 matplotlib = 1.4.3
simpy = 3.0.7
terminado = 0.5
tornado = 4.1
# Required by:
# dream==0.0.1
# MySQL-python = 1.2.5
# Required by:
# tornado==4.1
# backports.ssl-match-hostname = 3.4.0.2
# Required by:
# tornado==4.1
certifi = 2015.4.28
# Required by:
# matplotlib==1.4.3
mock = 1.0.1
# Required by:
# dream==0.0.1
# numpy = 1.9.2
# Required by:
# terminado==0.5
ptyprocess = 0.4
# Required by:
# dream==0.0.1
pydot = 1.0.28
# Required by:
# matplotlib==1.4.3
# pandas==0.16.0
python-dateutil = 2.4.2
# Required by:
# dream==0.0.1
rpy2 = 2.5.6
# Required by:
# rpy2==2.5.6
singledispatch = 3.4.0.3
# Required by:
# dream==0.0.1
tablib = 0.10.0
# Required by:
# dream==0.0.1
xlrd = 0.9.3
# Required by:
# dream==0.0.1
xlwt = 1.0.0
# Required by:
# dream==0.0.1
zope.dottedname = 4.1.0
#!{{ python_executable }}
from IPython.kernel.zmq.kernelbase import Kernel
from IPython.core.display import HTML
import requests
import logging
import json
erp5_url = "{{ erp5_url }}"
erp5_url = "%s/erp5/Base_executeJupyter"%erp5_url
class ERP5Kernel(Kernel):
implementation = 'ERP5'
implementation_version = '1.0'
language = 'ERP5'
language_version = '0.1'
language_info = {'mimetype': 'text/plain', 'name':'python'}
banner = "ERP5 integration with ipython notebook"
def __init__(self, user=None, pwd=None, url=None, status_code=None,
*args, **kwargs):
super(ERP5Kernel, self).__init__(*args, **kwargs)
self.user = user
self.pwd = pwd
self.url = erp5_url
self.status_code = status_code
self.reference = None
def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
status = 'ok'
if not silent:
if code.startswith('%erp5_user'):
self.user = code.split()[1]
resp = 'Your erp5 username is %s' %self.user
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
elif code.startswith('%erp5_password'):
self.pwd = code.split()[1]
if self.user:
try:
# Dirty hack here just to send some random parameter
# Should be removed with better way to get 200 status
# code for correct credentials, or yet better make 204
# also accepatble
res = requests.get(
self.url, verify=False,
auth=(self.user, self.pwd),
params={'python_expression': None},
)
self.status_code = res.status_code
if self.status_code != 200:
resp = '''Error code %s on request to ERP5, check
credentials or ERP5 family URL'''%self.status_code
else:
resp = 'Please proceed'
if not self.reference:
resp = '''There is no reference or title set for
this notebook. Please set one using
%notebook_set_reference or use one already
existing by %use_notebook magics'''
except requests.exceptions.RequestException as e:
resp = str(e)
else:
resp = 'Please enter your username in next cell'
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
elif code.startswith('%erp5_url'):
self.url = code.split()[1]
resp = 'Your erp5-url username is %s' %self.url
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
elif code.startswith('%notebook_set_reference'):
self.reference = code.split()[1]
resp = '''Your notebook reference is %s. Please use the magics
%%use_notebook %s when you restart the
notebook.'''%(self.reference, self.reference)
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
elif code.startswith('%use_notebook'):
self.reference = code.split()[1]
resp = '''Your notebook reference is %s.'''%self.reference
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
elif code.startswith('%notebook_set_title'):
self.reference = code.split()[1]
resp = '''Your notebook title is set to %s.'''%self.title
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
elif code.startswith('%my_notebooks'):
if self.status_code==200:
res = requests.get(
self.url, verify=False,
auth=(self.user, self.pwd),
params={
'python_expression': None,
'request_reference': True,
}
)
# code_result = res.text
# mime_type = 'text/plain'
# data = {
# 'data': {'': code_result},
# 'metadata': {}
# }
# self.send_response(self.iopub_socket, 'display_data', data)
resp = res.text
stream_content = {'name': 'stdout', 'text': resp}
self.send_response(self.iopub_socket, 'stream', stream_content)
else:
if self.status_code == 200:
if not self.reference:
code_result = '''There is no reference set for this
notebook. Please set one using
%notebook_set_reference or use already existing
one using %%use_notebook magics'''
else:
res = requests.get(
self.url, verify=False,
auth=(self.user, self.pwd),
params={
'python_expression': code,
'reference': self.reference,
}
)
content = json.loads(res.content)
if content['status']=='error':
reply_content = {
'status': 'error',
'execution_count': self.execution_count,
'ename': content['ename'],
'evalue': content['evalue'],
'traceback': content['traceback']}
self.send_response(self.iopub_socket, u'error', reply_content)
return reply_content
code_result = content['code_result']
mime_type = 'text/plain'
else:
code_result = 'Unauthorized access'
mime_type = 'text/plain'
data = {
'data': {mime_type: code_result},
'metadata': {}
}
self.send_response(self.iopub_socket, 'display_data', data)
reply_content = {
'status': status,
# The base class increments the execution count
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {},
}
return reply_content
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=ERP5Kernel)
else:
from IPython.kernel.zmq.kernelapp import IPKernelApp
import ConfigParser
knowledge_0 = '{{ config_cfg }}'
c = get_config()
parser = ConfigParser.ConfigParser()
parser.read(knowledge_0)
if parser.has_option("ipython_notebook", "password"):
c.NotebookApp.password = parser.get("ipython_notebook", "password")
# The name of the IPython directory. This directory is used for logging
# configuration (through profiles), history storage, etc. The default is usually
# $HOME/.ipython. This options can also be specified through the environment
# variable IPYTHONDIR.
c.IPKernelApp.ipython_dir = unicode('{{ ipython_dir }}')
c.NotebookApp.ipython_dir = unicode('{{ ipython_dir }}')
#!{{ python_executable }}
import cgi
import cgitb
import ConfigParser
import os
import re
import subprocess
from IPython.lib import passwd
#cgitb.enable(display=0, logdir="/tmp/cgi.log")
cgitb.enable()
form = cgi.FieldStorage()
config_file = "{{ config_cfg }}"
if not os.path.exists(config_file):
print "Your software does <b>not</b> embed 0-knowledge. \
This interface is useless in this case</body></html>"
exit(0)
parser = ConfigParser.ConfigParser()
parser.read(config_file)
if not parser.has_section("ipython_notebook"):
parser.add_section("ipython_notebook")
if not parser.has_option("ipython_notebook", "password"):
parser.set("ipython_notebook", "password", "")
if "password" in form:
parser.set("ipython_notebook", "password", passwd(form["password"].value))
# subprocess.call('{{ httpd_graceful }}')
# TODO: we should restart ipython
with open(config_file, 'w') as file:
parser.write(file)
# TODO cleanup
print "<html><head>"
print "<link rel=\"stylesheet\" href=\"static/pure-min.css\">"
print "<link rel=\"stylesheet\" href=\"static/style.css\">"
print "</head><body>"
print "<h1>IPython Notebook Password :</h1>"
print "<form action=\"/index.cgi\" method=\"post\" class=\"pure-form-aligned\">"
print "<input type=\"hidden\" name=\"posting-script\" value=\"{{ pwd }}/{{ this_file }}\">"
print """<div class="pure-control-group">
<label for="password">Password*:</label>
<input placeholder="Set your password" type="password" name="password" id="password"></br>
</div><div class="pure-control-group">
<label for="password">Verify Password*:</label>
<input placeholder="Verify password" type="password" name="password_2" id="password_2"></br>
</div><p id="validate-status" style="color:red"></p>
<div class="pure-controls">
<button id="register-button" type="submit" class="pure-button pure-button-primary" disabled>Access</button></div>
</form>
<script type="text/javascript" src="static/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="static/monitor-register.js"></script>
</body></html>
"""
{
"argv": [
"{{python_executable}}",
"{{kernel_dir}}",
"-f",
"{connection_file}"
],
"display_name": "{{display_name}}",
"language": "{{language_name}}",
"language_info": {"name": "python"}
}
[buildout]
parts =
request-notebook
publish-default-connection-parameters
eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true
{% set erp5_request_parameters = json_module.loads(erp5_published_values.get('erp5_request_parameters')) -%}
{% set publish_dict = {} -%}
{% for name, value in erp5_request_parameters.iteritems() -%}
{% do publish_dict.__setitem__(name, value) -%}
{% endfor %}
{% set jupyter_family_name = 'family-' ~ jupyter_family -%}
{% set jupyter_family_url = publish_dict.get(jupyter_family_name) -%}
[request-notebook]
<= slap-connection
recipe = slapos.cookbook:request.serialised
name = IPython Notebook
software-url = ${slap-connection:software-release-url}
software-type = notebook
sla-computer_guid = ${slap-connection:computer-id}
return = url
config-erp5_url = {{ jupyter_family_url }}
[publish-default-connection-parameters]
recipe = slapos.cookbook:publish.serialised
{% for name, value in publish_dict.items() -%}
{{ name }} = {{ value }}
{% endfor -%}
notebook-url = ${request-notebook:connection-url}
{% if jupyter_family=="None" -%}
error-message = No jupyter-family defined in parameters
# None here is an identifier, not a string
{% elif jupyter_family_url==none -%}
{% set error_message = 'No family exist with the family name ' ~ jupyter_family -%}
error-message = {{ error_message }}
{% else -%}
jupyter-family-url = {{ jupyter_family_url }}
{% endif -%}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment