Commit 9a6e913d authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

apache-frontend: add slave-control interface and monitor

parent 548d2f09
......@@ -165,3 +165,12 @@ location = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = records.config.jinja2
download-only = true
mode = 0644
[template-slave-control-interface]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/templates/monitor/${:filename}
download-only = true
#md5sum = e43d79bec8824265e22df7960744113a
destination = ${buildout:directory}/parts/template-slave-control-interface
filename = slave-control-interface.cgi.in
mode = 0644
......@@ -354,12 +354,34 @@ cert-content = ${slap-parameter:apache-certificate}
# Put domain name
name = ${slap-parameter:domain}
####################
# Monitor and control
#
[publish-information]
root-monitor-url = ${monitor-parameters:url}
[slave-control-interface]
recipe = slapos.recipe.template:jinja2
template = {{ build_path.get('template-slave-control-interface') }}
rendered = ${monitor-directory:monitoring-cgi}/${:filename}
filename = slave-control-interface.cgi
mode = 0744
context =
raw slave_configuration_json {{ slave_configuration_path }}
raw slave_status_stop {{ slave_stop }}
raw slave_status_deploy {{ slave_deploy }}
raw slave_status_test {{ slave_test }}
raw slave_status_ignore {{ slave_ignore }}
raw timestamp ${buildout:directory}/.timestamp
key pwd monitor-directory:monitoring-cgi
key this_file :filename
raw python_executable ${buildout:executable}
#####################
# Buidout elements
#
[buildout]
parts =
publish-slave-information
......@@ -370,7 +392,26 @@ parts =
{% for part in part_list -%}
{{ ' %s' % part }}
{% endfor -%}
# publish-information
###Parts to add for monitoring
certificate-authority
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 apache Root
slave-control-interface
extends = {{ build_path.get('monitor-template') }}
eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
......
......@@ -67,4 +67,5 @@ template-apache-frontend-configuration = ${template-apache-frontend-configuratio
template-default-slave-virtualhost = ${template-default-slave-virtualhost:target}
template-default-virtualhost = ${template-default-virtualhost:target}
template-empty = ${template-empty:target}
template-slave-configuration = ${template-slave-configuration:target}
\ No newline at end of file
template-slave-configuration = ${template-slave-configuration:target}
template-slave-control-interface = ${template-slave-control-interface:location}/${template-slave-control-interface:filename}
\ No newline at end of file
#!{{ python_executable }}
import cgi
import cgitb
import json
import os
cgitb.enable()
form = cgi.FieldStorage()
print "<html><head>"
print "<link rel=\"stylesheet\" href=\"static/pure-min.css\">"
print "<link rel=\"stylesheet\" href=\"static/style.css\">"
print "</head><body>"
slave_configuration_file = "{{ slave_configuration_json }}"
if not os.path.exists(slave_configuration_file):
print "No slave configuration file</body></html>"
exit(0)
slave_configuration_json = open(slave_configuration_file, 'r').read()
try:
slave_configuration = json.loads(slave_configuration_json)
except ValueError as e:
print "<pre>%s</pre></body></html>" % e
exit(0)
slave_status = {
'{{ slave_status_ignore }}': "Ignore",
'{{ slave_status_test }}': "Test",
'{{ slave_status_deploy }}': "Deploy",
'{{ slave_status_stop }}': "Stop",
}
def print_slave_line(slave_reference, current_state):
print """
<div class="pure-control-group">
<label for="%(slave_reference)s">%(slave_reference)s: </label>
<select name="%(slave_reference)s">
""" % {'slave_reference': slave_reference}
print '<option value="" selected></option>'
for state, title in slave_status.iteritems():
if current_state == state:
print '<option value="%s" selected>%s</option>' % (state, title)
else:
print '<option value="%s">%s</option>' % (state, title)
print """</select></div>"""
###
# Update Status
#
for name in form:
if slave_configuration.has_key(name):
slave_configuration.get(name)['state'] = form[name].value
if len(form) > 0:
json.dump(slave_configuration, open(slave_configuration_file, 'w'), indent=2)
try:
os.remove("{{ timestamp }}")
except OSError:
pass
print "<h1>Slave List status :</h1>"
print "<form action=\"/index.cgi\" method=\"post\" class=\"pure-form-aligned\">"
print "<input type=\"hidden\" name=\"posting-script\" value=\"{{ pwd }}/{{ this_file }}\">"
for slave_reference, slave in slave_configuration.iteritems():
print_slave_line(slave_reference, slave.get('state'))
print """<div class="pure-controls">
<button type="submit" class="pure-button pure-button-primary">Update</button>
</div></form>"""
print "</body></html>"
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