예제 #1
0
def renderDashboard(request, pyraptord=None, cmd=None, response=None):
    if pyraptord is None:
        pyraptord = getPyraptordClient()

    logDir = getattr(settings, 'SERVICES_LOG_DIR_URL', None)

    status = pyraptord.getStatusAll()
    serviceConfig = pyraptord.getConfig('SERVICES')

    configItems = serviceConfig.items()
    configItems.sort()
    tb = []
    tb.append('<h1 style="font-weight: bold;">Service Manager</h1>')
    if cmd is not None:
        tb.append('<div style="margin: 0.5em; font-size: 1.2em; background-color: #ccc;"><i>command:</i> %s <i>response:</i> %s</div>'
                  % (cmd, response))
    tb.append('<div style="margin: 0.5em; font-size: 1.2em; "><a href="." style="font-size: 1.2em;">refresh</a></div>')
    tb.append('<form method="post" action=".">')
    tb.append('<input type="hidden" name="csrfmiddlewaretoken" value="%s"/>' % get_token(request))
    tb.append('<table>')
    for name, _cfg in configItems:
        procStatus = status.get(name, {'status': 'notStarted'})
        procMode = procStatus.get('status')
        procColor = statuslib.getColor(procMode)
        tb.append('<tr>')
        tb.append('<td>%s</td>' % name)
        tb.append('<td style="background-color: %s;">%s</td>' % (procColor, procMode))
        tb.append('<td>%s</td>' % commandButton('start', name, disabled=not statuslib.isStartable(procMode)))
        tb.append('<td>%s</td>' % commandButton('stop', name, disabled=not statuslib.isActive(procMode)))
        tb.append('<td>%s</td>' % commandButton('restart', name))
        if logDir:
            tb.append('<td><a href="%s%s_latest.txt">latest log</a></td>'
                      % (logDir, name))
            tb.append('<td><a href="%s%s_previous.txt">previous log</a></td>'
                      % (logDir, name))
        tb.append('</tr>')

    tb.append('<tr>')
    if logDir:
        tb.append('<td style="font-weight: bold;">pyraptord</td>')
        tb.append('<td colspan="4"></td>')
        tb.append('<td><a href="%spyraptord_latest.txt">latest log</a></td>'
                  % logDir)
        tb.append('<td><a href="%spyraptord_previous.txt">previous log</a></td>'
                  % logDir)
    tb.append('</tr>')

    tb.append('</table>')
    tb.append('<div style="margin-top: 0.5em;"><a href="%s">all logs</a></div>' % logDir)
    tb.append('</form>')

    return render(request,
                  'geocamPycroraptor2/dashboard.html',
                  {'html': ''.join(tb)},
                  )
예제 #2
0
 def isStartable(self):
     return statuslib.isStartable(self._status)