From 8a3bbcdcd790e7239b02dab83360105d664c9d4f Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 21 Mar 2018 12:56:03 +0300 Subject: [PATCH] upd --- static/rbmd/script.js | 241 +++++++++++++++++++++----------------- templates/rbmd/index.html | 189 +++++++++++++++--------------- 2 files changed, 229 insertions(+), 201 deletions(-) diff --git a/static/rbmd/script.js b/static/rbmd/script.js index 234e31d..bcd0c90 100644 --- a/static/rbmd/script.js +++ b/static/rbmd/script.js @@ -1,9 +1,10 @@ $(function() { - $('#mountFormTrigger').click(function(event){ + $('#mountFormTrigger').click(function(event){ var htmlSelect = ''; - a.quorum.forEach(function(item) {htmlSelect += "";}) + a.quorum.forEach(function(item) { + htmlSelect += ""; + }) $('#selectNode').html(htmlSelect); - /* $.ajax({ url:"status", @@ -15,112 +16,132 @@ $(function() { } }) */ - }) - + }) }); - function resolve() { - $.ajax({ - url:"resolve", - data:{"node":deadNode}, - success:function(data){$('#details').css("display", "none");} - }) - } - - function unmount(a, b, c) { - var u = confirm(a + ": confirm unmount of " + b); - if (u == true) { - console.log('1'); - $.ajax({ - url:"unmount", - data:{"node":a, "mountpoint":b, "block":c}, - success:function(data){console.log(data); - - var res = JSON.parse(data); - message = "

" + res["state"] + "

"+ res["message"] +"

"; - $("#rspContainer").css("display", "block"); - $("#rsp").html(message) - if (res["state"] == 'OK'){$("#rspContainer").css("background-color", "#4CAF50" );} - else {$("#rspContainer").css("background-color", "#f44336" )} - } - }) - } - } - - function displayData(a){ - $("#status").html("

"+a.health+"

"); - if (a.health == 'deadly.') { - $('#showDeadlyDetails').css("display","block"); - $('#resolve').css("display","block"); - $("#mountFormTrigger").addClass("w3-disabled") - } else { - $('#showDeadlyDetails').css("display","none"); - $('#resolve').css("display","none"); - $("#mountFormTrigger").removeClass("w3-disabled") - $('#details').css("border", "0"); - } - $( "#statusContainer:contains('alive')" ).css("background-color", "#4CAF50" ); - $( "#statusContainer:contains('resizing')" ).css("background-color", "#ff9800" ); - $( "#statusContainer:contains('deadly')" ).css("background-color", "#f44336" );; - var node2 = a; - w3DisplayData("id01", node2); - $('.tablink').css('display', 'block'); - if (selected_node != undefined && selected_node != 'dead'){ - //a.quorum.forEach(function(item) {if (item.node == selected_node) { console.log(item.node)}}) - var selected_node_body = a.quorum.find(function(node) { return node.node == selected_node}); - var t = new Date(selected_node_body["updated"] * 1000) - var up_formatted = t.getFullYear() + "/" - + (t.getMonth() + 1) + "/" - + t.getDate() + " " - + t.getHours() + ":" - + t.getMinutes() + ":" - + t.getSeconds(); - $("#name").html(selected_node); - $("#ipv4").html(selected_node_body["ip"]["v4"].join("
")); - $("#ipv6").html(selected_node_body["ip"]["v6"].join("
")); - $("#updated").html(up_formatted); - if (selected_node_body["mounts"] != null) { - var mnt_block = ""; - for (i in selected_node_body.mounts) { - var mnt = selected_node_body.mounts[i]; - mnt_block += 'unmount
Mountpoint: ' - + mnt.mountpoint + '
Mountopts: ' - + mnt.mountopts + '
Fstype: ' - + mnt.fstype - + '
Pool: ' + mnt.pool - + '
Image: ' + mnt.image - + '
Block: ' + mnt.block + '
'; - } - $("#mon").html(mnt_block); - } - else { $("#mon").html("")} +function resolve() { + $.ajax({ + url:"resolve", + data:{"node": deadNode}, + success:function(data){ + $('#details').css("display", "none"); } - if (selected_node =='dead') { - var t, up_formatted - console.log(a.deadlyreason); - if (a.deadlyreason["updated"] != 0) { - t = new Date(a.deadlyreason["updated"] * 1000) - up_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds(); - } else { up_formatted=0 } - deadNode = a.deadlyreason["node"]; - $("#name").html(a.deadlyreason["node"]); - $("#ipv4").html(a.deadlyreason["ip"]["v4"].join("
")); - $("#ipv6").html(a.deadlyreason["ip"]["v6"].join("
")); - $("#updated").html(up_formatted); - if (a.deadlyreason["mounts"] != null) { - var mnt_block = ""; - for (i in a.deadlyreason.mounts) { - var mnt = a.deadlyreason.mounts[i]; - mnt_block += mnt.mountpoint + "
" + mnt.mountopts + "
" + mnt.fstype + "
" + mnt.pool + "
" + mnt.image + "

"; - } - $("#mon").html(mnt_block); - } else { $("#mon").html("") } - } - $("#leader").html(a.leader); + }) +} +function unmount(a, b, c) { + var u = confirm(a + ": confirm unmount of " + b); + if (u == true) { + $.ajax({ + url:"unmount", + data:{"node":a, "mountpoint":b, "block":c}, + success:function(data){ + var res = JSON.parse(data); + message = "

" + res["state"] + "

"+ res["message"] +"

"; + $("#rspContainer").css("display", "block"); + $("#rsp").html(message) + if (res["state"] == 'OK'){ + $("#rspContainer").css("background-color", "#4CAF50" ); + } + else { + $("#rspContainer").css("background-color", "#f44336" ); + } } + }) + } +} + +function displayData(a){ + $("#status").html("

"+a.health+"

"); + if (a.health == 'deadly.') { + $('#showDeadlyDetails').css("display","block"); + $('#resolve').css("display","block"); + $("#mountFormTrigger").addClass("w3-disabled") + } else { + $('#showDeadlyDetails').css("display","none"); + $('#resolve').css("display","none"); + $("#mountFormTrigger").removeClass("w3-disabled") + $('#details').css("border", "0"); + } + $( "#statusContainer:contains('alive')" ).css("background-color", "#4CAF50" ); + $( "#statusContainer:contains('resizing')" ).css("background-color", "#ff9800" ); + $( "#statusContainer:contains('deadly')" ).css("background-color", "#f44336" );; + var node2 = a; + w3DisplayData("id01", node2); + $('.tablink').css('display', 'block'); + if (selected_node != undefined && selected_node != 'dead'){ + + //a.quorum.forEach(function(item) {if (item.node == selected_node) { console.log(item.node)}}) + var selected_node_body = a.quorum.find(function(node) { + return node.node == selected_node + }); + var t = new Date(selected_node_body["updated"] * 1000) + var up_formatted = t.getFullYear() + "/" + + (t.getMonth() + 1) + "/" + + t.getDate() + " " + + t.getHours() + ":" + + t.getMinutes() + ":" + + t.getSeconds(); + $("#name").html(selected_node); + $("#ipv4").html(selected_node_body["ip"]["v4"].join("
")); + $("#ipv6").html(selected_node_body["ip"]["v6"].join("
")); + $("#updated").html(up_formatted); + if (selected_node_body["mounts"] != null) { + var mnt_block = ""; + for (i in selected_node_body.mounts) { + var mnt = selected_node_body.mounts[i]; + mnt_block += 'unmount
Mountpoint: ' + + mnt.mountpoint + '
Mountopts: ' + + mnt.mountopts + '
Fstype: ' + + mnt.fstype + + '
Pool: ' + mnt.pool + + '
Image: ' + mnt.image + + '
Block: ' + mnt.block + '
'; + } + $("#mon").html(mnt_block); + } else { + $("#mon").html(""); + } + } + if (selected_node =='dead') { + var t, up_formatted; + if (a.deadlyreason["updated"] != 0) { + t = new Date(a.deadlyreason["updated"] * 1000) + up_formatted = t.getFullYear() + "/" + + (t.getMonth() + 1) + "/" + + t.getDate() + " " + + t.getHours() + ":" + + t.getMinutes() + ":" + + t.getSeconds(); + } else { + up_formatted=0; + } + deadNode = a.deadlyreason["node"]; + $("#name").html(a.deadlyreason["node"]); + $("#ipv4").html(a.deadlyreason["ip"]["v4"].join("
")); + $("#ipv6").html(a.deadlyreason["ip"]["v6"].join("
")); + $("#updated").html(up_formatted); + if (a.deadlyreason["mounts"] != null) { + var mnt_block = ""; + for (i in a.deadlyreason.mounts) { + var mnt = a.deadlyreason.mounts[i]; + mnt_block += mnt.mountpoint + "
" + + mnt.mountopts + "
" + + mnt.fstype + "
" + + mnt.pool + "
" + + mnt.image + "

"; + } + $("#mon").html(mnt_block); + } else { + $("#mon").html(""); + } + } + $("#leader").html(a.leader); +} function openNode(evt, nodeName) { var i, x, tablinks; @@ -130,11 +151,13 @@ function openNode(evt, nodeName) { if (selected_node == 'dead') { $('#details').css("border", "2px solid #f44336"); if ($('#showDeadlyDetails').html() == "Show details") { - $('#details').css("display", "block"); - $('#showDeadlyDetails').text('Hide details'); + $('#details').css("display", "block"); + $('#showDeadlyDetails').text('Hide details'); } else { - $('#details').css("display", "none"); - $('#showDeadlyDetails').text('Show details'); + $('#details').css("display", "none"); + $('#showDeadlyDetails').text('Show details'); } - } else {$('#details').css("border", "").css("display", "block"); displayData(a) } + } else { + $('#details').css("border", "").css("display", "block"); displayData(a); + } } diff --git a/templates/rbmd/index.html b/templates/rbmd/index.html index 2fff30d..91d4d14 100644 --- a/templates/rbmd/index.html +++ b/templates/rbmd/index.html @@ -1,104 +1,109 @@ - + RBMD - - - - - - - - -
- Mount - -
+ + + + + + + + +
+ + Mount + + +
+
+
+
+

Leader:

+

Nodes:

+ +

Metrics:

+ {% for k, v in metrics.items() %} {{k}} {{v}}
+ {% end %} +
+
+ + + -
-
-
- × -

Mount

-
-
{% module xsrf_form_html() %} -
- -
-
-
-
-
- -
-
-
-
-
-
- +
+
+
+ × +

Mount

+
+
{% module xsrf_form_html() %} +
+ +
+
+
+
+
+ +
+
+
+
+
+ - + event.preventDefault(); + $.ajax({ + url:"mount", + data:$(this).serialize(), + method:'POST', + success:function(data){ + $('#mount').css('display', 'none'); + $('input[type = "text"]').val(''); + var res = JSON.parse(data); + message = "

" + res["state"] + "

"+ res["message"] +"

"; + $("#rspContainer").css("display", "block"); + $("#rsp").html(message) + if (res["state"] == 'OK'){ + $("#rspContainer").css("background-color", "#4CAF50" ); + } + else { + $("#rspContainer").css("background-color", "#f44336" ) + } + } + }) + }) + +