Commit 5edf26b1 authored by Roque's avatar Roque

Fix panel monitoring links

See merge request nexedi/slapos.core!639
parents 5c050627 cbc7ddca
# TODO how to avoid hardcode here? from InstanceTree_getConnectionParameterList? from ZTUtils import make_query
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_landing' request = context.REQUEST
try: # TODO how to avoid hardcode here?
instance_tree = context base_url = 'https://monitor.app.officejs.com/#/?'
if context.getPortalType() in ["Software Instance", "Slave Instance"]: url_parameter_kw = { 'page': 'ojsm_landing' }
instance_tree = context.getSpecialise()
connection_parameter_dict = instance_tree.InstanceTree_getMonitorParameterDict() if request is not None :
connection_url = '&url=%s'% connection_parameter_dict['url'] + '&username=%s'% connection_parameter_dict['username'] + '&password=%s'% connection_parameter_dict['password'] url_parameter_kw['slapos_master_url'] = request["BASE0"]
except (AttributeError, TypeError) as _:
connection_url = '' instance_tree = context
if context.getPortalType() in ["Software Instance", "Slave Instance"]:
instance_tree = context.getSpecialiseValue(portal_type="Instance Tree")
connection_parameter_dict = instance_tree.InstanceTree_getMonitorParameterDict()
if all(key in connection_parameter_dict for key in ('username', 'password', 'url')):
url_parameter_kw['username'] = connection_parameter_dict['username']
url_parameter_kw['password'] = connection_parameter_dict['password']
url_parameter_kw['url'] = connection_parameter_dict['url']
else:
return ''
if context.getPortalType() == "Instance Tree": if context.getPortalType() == "Instance Tree":
for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True): url_parameter_kw['query'] = 'portal_type:"Instance Tree" AND title:"%s"' % context.getTitle()
if connection_parameter['connection_key'] == "monitor-setup-url":
# connection_parameter['connection_value'] looks like #page=settings_configurator&url=xx/public/feeds&username=admin&password=yy
# workaround until settings_configurator is c on software releases / buildout cfg files are updated
return connection_parameter['connection_value'].replace("settings_configurator", "ojsm_landing")
return base_url + '&query=portal_type:"Instance Tree" AND title:"%s"' % context.getTitle() + connection_url
if context.getPortalType() in ["Software Instance", "Slave Instance"]: if context.getPortalType() in ["Software Instance", "Slave Instance"]:
return base_url + '&query=portal_type:"Software Instance" AND title:"%s" AND ' % context.getTitle() + 'specialise_title:"%s"' % context.getSpecialiseTitle() + connection_url url_parameter_kw['query'] = 'portal_type:"Software Instance" AND title:"%s" AND ' % context.getTitle() + 'specialise_title:"%s"' % context.getSpecialiseTitle()
return base_url + make_query(url_parameter_kw)
import json
def getCredentialFromUrl(url_string): def getCredentialFromUrl(url_string):
username = password = url = '' username = password = url = ''
param_list = url_string.split('#') param_list = url_string.split('#')
...@@ -13,17 +11,16 @@ def getCredentialFromUrl(url_string): ...@@ -13,17 +11,16 @@ def getCredentialFromUrl(url_string):
username = value username = value
elif key == 'password': elif key == 'password':
password = value password = value
return (url, username, password,) return (url, username, password,)
instance_tree = context instance_tree = context
if instance_tree.getSlapState() == 'destroy_requested': if instance_tree.getSlapState() == 'destroy_requested':
return json.dumps({}) return {}
instance = instance_tree.getSuccessorValue() instance = instance_tree.getSuccessorValue()
if instance is None or instance.getSlapState() == 'destroy_requested': if instance is None or instance.getSlapState() == 'destroy_requested':
return json.dumps({}) return {}
parameter_dict = instance.getConnectionXmlAsDict() parameter_dict = instance.getConnectionXmlAsDict()
...@@ -38,10 +35,10 @@ if url_string: ...@@ -38,10 +35,10 @@ if url_string:
else: else:
url, username, password = getCredentialFromUrl(url_string) url, username, password = getCredentialFromUrl(url_string)
else: else:
return json.dumps({}) return {}
return json.dumps({ return {
'username': username, 'username': username,
'password': password, 'password': password,
'url': url 'url': url
}) }
\ No newline at end of file
...@@ -234,10 +234,6 @@ ...@@ -234,10 +234,6 @@
options.hasOwnProperty('result'))) { options.hasOwnProperty('result'))) {
return domsugar(this.element); return domsugar(this.element);
} }
if (options.result.hasOwnProperty('monitor_url')) {
options.result.monitor_url +=
'&slapos_master_url=' + window.location.host;
}
// Save will force the gadget to be updated so // Save will force the gadget to be updated so
// result is empty. // result is empty.
var state_dict = options.result || {}; var state_dict = options.result || {};
......
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