Commit 7bd79e3d authored by Ayush Tiwari's avatar Ayush Tiwari

Removed hardcoded url for ERP5Kernel jinja file and moved to the instance file

parent d21fc169
...@@ -133,9 +133,11 @@ monitor_url = $${monitor-parameters:url} ...@@ -133,9 +133,11 @@ monitor_url = $${monitor-parameters:url}
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = ${erp5-kernel:location}/${erp5-kernel:filename} template = ${erp5-kernel:location}/${erp5-kernel:filename}
rendered = $${directory:erp5_kernel_dir}/ERP5kernel.py rendered = $${directory:erp5_kernel_dir}/ERP5kernel.py
erp5_url = https://softinst60318.host.vifib.net/erp5/Base_executePython
mode = 0744 mode = 0744
context = context =
raw python_executable ${buildout:bin-directory}/pythonwitheggs raw python_executable ${buildout:bin-directory}/pythonwitheggs
key erp5_url :erp5_url
[kernel-json] [kernel-json]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
......
...@@ -55,7 +55,7 @@ output = ${buildout:directory}/instance.cfg ...@@ -55,7 +55,7 @@ output = ${buildout:directory}/instance.cfg
recipe = hexagonit.recipe.download recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/template/${:filename} url = ${:_profile_base_location_}/template/${:filename}
download-only = true download-only = true
md5sum = c74ced2f5e20f5509a3aca8d00952499 md5sum = 0e9c5070725c3a10125a9b658bd4eb5c
destination = ${buildout:parts-directory}/${:_buildout_section_name_} destination = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = ERP5kernel.py.jinja filename = ERP5kernel.py.jinja
mode = 0644 mode = 0644
......
#!{{python_executable}} #!{{ python_executable }}
from IPython.kernel.zmq.kernelbase import Kernel from IPython.kernel.zmq.kernelbase import Kernel
from IPython.core.display import HTML from IPython.core.display import HTML
...@@ -6,6 +6,8 @@ from IPython.core.display import HTML ...@@ -6,6 +6,8 @@ from IPython.core.display import HTML
import requests import requests
import logging import logging
global erp5_url = "{{ erp5_url }}"
class ERP5Kernel(Kernel): class ERP5Kernel(Kernel):
implementation = 'ERP5' implementation = 'ERP5'
implementation_version = '1.0' implementation_version = '1.0'
...@@ -14,11 +16,12 @@ class ERP5Kernel(Kernel): ...@@ -14,11 +16,12 @@ class ERP5Kernel(Kernel):
language_info = {'mimetype': 'text/plain', 'name':'python'} language_info = {'mimetype': 'text/plain', 'name':'python'}
banner = "ERP5 integration with ipython notebook" banner = "ERP5 integration with ipython notebook"
def __init__(self, user=None, pwd=None, url=None, status_code=None, *args, **kwargs): def __init__(self, user=None, pwd=None, url=None, status_code=None,
*args, **kwargs):
super(ERP5Kernel, self).__init__(*args, **kwargs) super(ERP5Kernel, self).__init__(*args, **kwargs)
self.user = user self.user = user
self.pwd = pwd self.pwd = pwd
self.url = url self.url = erp5_url
self.status_code = status_code self.status_code = status_code
def do_execute(self, code, silent, store_history=True, user_expressions=None, def do_execute(self, code, silent, store_history=True, user_expressions=None,
...@@ -33,11 +36,10 @@ class ERP5Kernel(Kernel): ...@@ -33,11 +36,10 @@ class ERP5Kernel(Kernel):
elif code.startswith('%erp5_password'): elif code.startswith('%erp5_password'):
self.pwd = code.split()[1] self.pwd = code.split()[1]
self.url = 'softinst60318.host.vifib.net/erp5/manage_main'
if self.user: if self.user:
url = 'https://%s:%s@%s' %(self.user, self.pwd, self.url)
try: try:
res = requests.get(url, verify=False) res = requests.get(self.url, verify=False,
auth=(self.user, self.pwd))
self.status_code = res.status_code self.status_code = res.status_code
if self.status_code != 200: if self.status_code != 200:
resp = 'Incorrect username or password' resp = 'Incorrect username or password'
...@@ -52,8 +54,9 @@ class ERP5Kernel(Kernel): ...@@ -52,8 +54,9 @@ class ERP5Kernel(Kernel):
else: else:
if self.status_code == 200: if self.status_code == 200:
url = 'https://%s:%s@softinst60318.host.vifib.net/erp5/data_set_module/wendelin_1/Base_executePython' %(self.user, self.pwd) res = requests.get(self.url, verify=False,
res = requests.get(url, verify=False, params={'python_expression': code}) auth=(self.user, self.pwd),
params={'python_expression': code})
code_result = res.text code_result = res.text
else: else:
...@@ -76,4 +79,4 @@ if __name__ == '__main__': ...@@ -76,4 +79,4 @@ if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=ERP5Kernel) IPKernelApp.launch_instance(kernel_class=ERP5Kernel)
else: else:
from IPython.kernel.zmq.kernelapp import IPKernelApp from IPython.kernel.zmq.kernelapp import IPKernelApp
\ No newline at end of file
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