This commit is contained in:
Anna Sudnitsina 2017-09-01 14:52:47 +03:00
parent 2a8e165efd
commit deacb40cae
5 changed files with 78 additions and 60 deletions

View File

@ -1,6 +1,6 @@
{
"api": "http://10.8.0.34:9076/v1/",
"api": "http://10.8.0.34:9076/v1",
"ws": "ws://php.difrex.ru/ws"
}

View File

@ -1,7 +1,7 @@
$(function() {
$('#mountFormTrigger').click(function(event){
$.ajax({
url:"get_status.php",
url:"status",
success:function(data){
var status = JSON.parse(data);
var htmlSelect = '';
@ -14,27 +14,9 @@ for (n in status["quorum"]) { htmlSelect += "<option value=" + n + ">" + n + "</
});
$('#mountFormTrigger').click(function(event){
$.ajax({
url:"get_status.php",
success:function(data){
var status = JSON.parse(data);
var htmlSelect = '';
for (n in status["quorum"]) { htmlSelect += "<option value=" + n + ">" + n + "</option>";}
$('#selectNode').html(htmlSelect);
console.log(htmlSelect);}
})
})
$(function() {
console.log( "ready!" );
});
function resolve() {
$.ajax({
url:"resolve.php",
url:"/resolve",
data:{"node":deadNode},
success:function(data){$('#details').css("display", "none");}
})
@ -44,7 +26,7 @@ $(function() {
var u = confirm(a + ": confirm unmount of " + b);
if (u == true) {
$.ajax({
url:"unmount.php",
url:"unmount",
data:{"node":a, "mountpoint":b, "block":c},
success:function(data){
var res = JSON.parse(data);
@ -58,6 +40,12 @@ $(function() {
}
}
function displayData(a){
$("#status").html("<p>"+a.health+"</p>");
if (a.health == 'deadly.') {

View File

@ -15,12 +15,14 @@
<a href='/'><img src={% static 'images-logo.png' %} class="w3-right w3-hover-opacity" height="33.82em" ></a>
</header>
{% verbatim %}
<div class="w3-container">
<div class="w3-row">
<div class="sidenav w3-container w3-light-grey w3-col m3" id="id01">
<h4> Leader: </h4> <span id='leader' class="tablink"></span>
<h4>Nodes: </h4>
<a w3-repeat="node in quorum" href="javascript:void(0)" class="tablink" onclick="openNode(event, '{{node}}')" style='display:none'>{{node}}</a>
{% endverbatim %}
<h4>Metrics: </h4>
{% for k,v in metrics.items %} {{k}} {{v}}<br> {% endfor %}
@ -30,11 +32,13 @@
<div class="w3-padding w3-display-left" id="status">Status... </div>
<a href="javascript:void(0)" class="w3-right" id="showDeadlyDetails" onClick="openNode(event, 'dead')" style="display: none; padding:15px;">Show details</a>
</div>
<div id="rspContainer" class="w3-container w3-animate-opacity" style="display: none">
<span onclick="this.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
<div id="rsp">
</div>
</div>
<div id = "details" class="w3-container" style="display:none;">
<table class='w3-table w3-bordered' id="id02">
<tr><td> Node:</td> <td> <span id='name'></span></td> </tr>
@ -54,7 +58,7 @@
<span onclick="document.getElementById('mount').style.display='none'" class="w3-closebtn">&times;</span>
<h2>Mount</h2>
</header>
<form method="post" action="/" role="form" class="w3-container form">
<form method="post" action="/" role="form" class="w3-container form" id="mountForm"> {% csrf_token %}
<label class="w3-label w3-text-black">Node: <select name="node" class="w3-select" id='selectNode'></select> </label><br>
<!--label class="w3-label w3-text-black">Node: <input name="node" class="w3-input" type="text" required> </label><br-->
<label class="w3-label w3-text-black">Pool: <input name="pool" class="w3-input" type="text"> </label><br>
@ -69,13 +73,7 @@
</div>
</div>
<script>
console.log('{{status|escapejs}}')
var res = '{{status|escapejs}}';
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
$("#rspContainer").css("display", "block");
$("#rsp").html(message)
if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );}
else {$("#rspContainer").css("background-color", "#f44336" )}
//var res = '{{status|escapejs}}';
</script>
<script>
@ -87,5 +85,28 @@
a = JSON.parse(evt.data);
displayData(a);
};
$('#mountForm').submit(function(event){
event.preventDefault();
$.ajax({
url:"mount",
data:$(this).serialize(),
method:'POST',
success:function(data){
console.log(data);
$('#mount').css('display', 'none');
$('input').val('');
var res = JSON.parse(data);
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
$("#rspContainer").css("display", "block");
$("#rsp").html(message)
if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );}
else {$("#rspContainer").css("background-color", "#f44336" )}
}
})
})
</script>
</body></html>

View File

@ -21,10 +21,8 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.panel),
url(r'^status$', views.get_status),
url(r'^node$', views.node),
url(r'^health$', views.health),
url(r'^mount$', views.mount),
url(r'^unmount$', views.get_status),
url(r'^unmount$', views.unmount),
url(r'^resolve$', views.resolve),
url(r'^metrics$', views.get_metrics),
]

View File

@ -1,51 +1,62 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
import json
import requests
def get_status():
def status():
with open('conf.json') as conf:
status = json.load(conf)["api"] + '/status'
try: res = requests.get(status)
try: res = requests.get(status).content
except: res = 'connection can\'t be established'
return res.content
return res
def node():
pass
def get_status(request):
my_status = status()
return JsonResponse(my_status, safe=False)
def health():
pass
def mount(request):
if request.method == 'POST':
data = request.POST.dict()
#s = mount(data)
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/mount'
res = requests.post(url, json.dumps(data))
print res
return JsonResponse(res.content, safe=False)
def mount():
pass
def unmount():
pass
def unmount(request):
print request.GET.dict()
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/umount'
#data = json.dumps({'node': 'ceph1', 'mountpoint': '/mnt', 'block': 'rbd0'})
data = request.GET.dict()
try: res = requests.post(url, json.dumps(data)).content
except: res = 'connection can\'t be established'
return JsonResponse(res, safe=False)
def resolve():
pass
with open('conf.json') as conf:
url = json.load(conf)["api"] + '/resolve'
data = request.GET.dict()
res = requests.post(metrics, json.dumps(data))
return JsonResponse(res.content, safe=False)
def get_metrics():
#with open('conf.json') as conf:
# api = json.load(conf)["api"]
#try: res = requests.get(api + metrics)
#return api
with open('conf.json') as conf:
metrics = json.load(conf)["api"] + '/metrics'
res = requests.get(metrics)
print res
#except: res = 'connection can\'t be established'
return res.content
try: res = requests.get(metrics).content
except: res = 'connection can\'t be established'
return res
def panel(request):
with open('conf.json') as conf:
ws = json.load(conf)["ws"]
metrics = json.loads(get_metrics())
status = get_status()
return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics, 'status' : status})
my_status = status()
return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics, 'status' : my_status})