Merge branch 'hera'
This commit is contained in:
Коммит
0e63c6b44a
|
@ -69,6 +69,7 @@
|
|||
<li class="top">
|
||||
<a href="#" class="controller">Server Config</a>
|
||||
<ul>
|
||||
<li><a href="{{ url('zadmin.hera') }}">Hera</a></li>
|
||||
<li><a href="{{ url('zadmin.settings') }}">Settings</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
{% extends "admin/base.html" %}
|
||||
|
||||
{% block title %}{{ page_title('Hera') }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Hera</h2>
|
||||
<div class="primary featured">
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
{% if message %}
|
||||
<div class="notification-box {{ message.tags }}">
|
||||
<h2>{{ message|safe }}</h2>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if form %}
|
||||
<form method="post" action="" class="featured-inner object-lead user-input">
|
||||
{{ csrf() }}
|
||||
<fieldset>
|
||||
<p class="instruct">Want to get a message to Zeus out on the front
|
||||
lines? You've come to the right place. The text area below accepts
|
||||
a new-line separated list of simple expressions (wildcards are
|
||||
supported) which will be flushed from the front end cache.
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
<label for="id_prefix">Prefix</label>
|
||||
{{ form.flushprefix|safe }}
|
||||
{{ form.flushprefix.errors|safe }}
|
||||
<p class="note">A prefix to prepend to all your patterns. I suggest <strong>{{ settings.SITE_URL }}</strong></p>
|
||||
</li>
|
||||
<li>
|
||||
{{ form.flushlist|safe }}
|
||||
{{ form.flushlist.errors|safe }}
|
||||
<p class="note">A new-line separated list of simple expressions (wildcards allowed) which will be flushed from
|
||||
the front end cache. Examples: <strong>/*addon/1865*</strong> or <strong>/de/jsi18n*</strong></p>
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
<div class="fm-control">
|
||||
<button type="submit">Go go go</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="secondary">
|
||||
<h3>Stats</h3>
|
||||
{% if stats.num_lookups > 0 %}
|
||||
{# Can't jinja2 detect a division by zero and just do something intelligent? #}
|
||||
{% set hit_percentage = stats.num_hits / stats.num_lookups %}
|
||||
{% else %}
|
||||
{% set hit_percentage = 0 %}
|
||||
{% endif %}
|
||||
<ul>
|
||||
<li>Using {{ stats.bytes_used|filesizeformat }} ({{ stats.percent_used }}% of total space) for {{ stats.entries }} objects.</li>
|
||||
<li>We've had {{ stats.num_hits }} hits out of {{ stats.num_lookups }} lookups ({{ hit_percentage }}%).</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -10,6 +10,7 @@ urlpatterns = patterns('',
|
|||
url('^$', lambda r: redirect('admin:index'), name='zadmin.home'),
|
||||
url('^env$', views.env, name='amo.env'),
|
||||
url('^flagged', views.flagged, name='zadmin.flagged'),
|
||||
url('^hera', views.hera, name='zadmin.hera'),
|
||||
url('^settings', views.settings, name='zadmin.settings'),
|
||||
|
||||
# The Django admin.
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
from django import http
|
||||
# I'm so glad we named a function in here settings...
|
||||
from django.conf import settings as site_settings
|
||||
from django.contrib import admin
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect
|
||||
from django.views import debug
|
||||
|
||||
import commonware.log
|
||||
from hera import Hera
|
||||
from hera.contrib.django_forms import FlushForm
|
||||
import jinja2
|
||||
import jingo
|
||||
|
||||
|
@ -11,6 +17,8 @@ from addons.models import Addon
|
|||
from files.models import Approval
|
||||
from versions.models import Version
|
||||
|
||||
log = commonware.log.getLogger('z.zadmin')
|
||||
|
||||
|
||||
@admin.site.admin_view
|
||||
def flagged(request):
|
||||
|
@ -53,6 +61,51 @@ def flagged(request):
|
|||
{'addons': addons})
|
||||
|
||||
|
||||
@admin.site.admin_view
|
||||
def hera(request):
|
||||
def _hera_fail(e):
|
||||
msg = "We had some trouble talking to zeus"
|
||||
messages.error(request, "%s: %s" % (msg, e))
|
||||
log.error("[Hera] (user:%s): %s" % (request.user, e))
|
||||
|
||||
form = FlushForm(initial={'flushprefix': site_settings.SITE_URL})
|
||||
|
||||
try:
|
||||
username = site_settings.HERA['username']
|
||||
password = site_settings.HERA['password']
|
||||
location = site_settings.HERA['location']
|
||||
except (KeyError, AttributeError):
|
||||
messages.error(request, "Sorry, Hera is not configured. :(")
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = FlushForm(request.POST)
|
||||
if form.is_valid():
|
||||
hera = Hera(username, password, location)
|
||||
expressions = request.POST['flushlist'].splitlines()
|
||||
|
||||
for i in expressions:
|
||||
pattern = "%s%s" % (request.POST['flushprefix'], i)
|
||||
total = len(hera.flushObjectsByPattern(pattern,
|
||||
return_list=True))
|
||||
|
||||
msg = "Flushing %s objects matching %s from cache" % (total,
|
||||
pattern)
|
||||
log.info("[Hera] (user:%s) %s" % (request.user, msg))
|
||||
messages.success(request, msg)
|
||||
|
||||
try:
|
||||
hera = Hera(username, password, location)
|
||||
stats = hera.getGlobalCacheInfo()
|
||||
except Exception, e:
|
||||
# suds throws generic exceptions...
|
||||
stats = None
|
||||
form = None
|
||||
_hera_fail(e)
|
||||
|
||||
return jingo.render(request, 'zadmin/hera.html',
|
||||
{'form': form, 'stats': stats})
|
||||
|
||||
|
||||
@admin.site.admin_view
|
||||
def settings(request):
|
||||
|
|
|
@ -6,6 +6,7 @@ phpserialize==1.2
|
|||
python-memcached==1.45
|
||||
pyquery==0.4
|
||||
South==0.7
|
||||
suds==0.3.9
|
||||
pytz==2010e
|
||||
GitPython==0.1.7
|
||||
celery==1.0.2
|
||||
|
@ -21,6 +22,7 @@ django-pylibmc==0.2.1
|
|||
-e git://github.com/jsocol/jingo-minify.git#egg=jingo-minify
|
||||
-e git://github.com/jsocol/bleach.git#egg=bleach
|
||||
-e git://github.com/jbalogh/schematic.git#egg=schematic
|
||||
-e git://github.com/clouserw/hera.git#egg=hera
|
||||
-e git://github.com/clouserw/tower.git#egg=tower
|
||||
-e git://github.com/jbalogh/django-queryset-transform.git#egg=django-queryset-transform
|
||||
-e git://github.com/jsocol/commonware.git#egg=commonware
|
||||
|
|
|
@ -488,6 +488,12 @@ CUSTOM_DUMPS = {
|
|||
}
|
||||
}
|
||||
|
||||
## Hera
|
||||
HERA = {'username': '',
|
||||
'password': '',
|
||||
'location': '',
|
||||
}
|
||||
|
||||
# Logging
|
||||
LOG_LEVEL = logging.DEBUG
|
||||
HAS_SYSLOG = True # syslog is used if HAS_SYSLOG and NOT DEBUG.
|
||||
|
@ -501,6 +507,7 @@ LOGGING = {
|
|||
'loggers': {
|
||||
'amqplib': {'handlers': ['null']},
|
||||
'caching': {'handlers': ['null']},
|
||||
'suds': {'handlers': ['null']},
|
||||
'z.sphinx': {'level': logging.INFO},
|
||||
'z.task': {'level': logging.INFO},
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче