initial
This commit is contained in:
parent
bed04d55f3
commit
98c174de56
0
rbmd/__init__.py
Normal file
0
rbmd/__init__.py
Normal file
7
rbmd/conf.json
Normal file
7
rbmd/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
|
||||
"mount":"http://127.0.0.1:9076/mount",
|
||||
"api": "http://127.0.0.1:9076/v1/",
|
||||
"ws": "ws://php.difrex.ru/ws"
|
||||
|
||||
}
|
125
rbmd/settings.py
Normal file
125
rbmd/settings.py
Normal file
@ -0,0 +1,125 @@
|
||||
"""
|
||||
Django settings for rbmd project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 1.9.7.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.9/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.9/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'mpcqsg+e*wiw%^-x%1kv%pq-fi3@9hrp)n@+iz&q8&=)m3v_$z'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'rbmd.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': ['templates'],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'rbmd.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.9/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.9/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
#PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
#STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, "rbmd/static"), ]
|
BIN
rbmd/static/images-logo.png
Normal file
BIN
rbmd/static/images-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
147
rbmd/static/script.js
Normal file
147
rbmd/static/script.js
Normal file
@ -0,0 +1,147 @@
|
||||
$(function() {
|
||||
$('#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);}
|
||||
})
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
$('#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",
|
||||
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) {
|
||||
$.ajax({
|
||||
url:"unmount.php",
|
||||
data:{"node":a, "mountpoint":b, "block":c},
|
||||
success:function(data){
|
||||
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" )}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function displayData(a){
|
||||
$("#status").html("<p>"+a.health+"</p>");
|
||||
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");
|
||||
}
|
||||
$("#leader").text(a.leader);
|
||||
$( "#statusContainer:contains('alive')" ).css("background-color", "#4CAF50" );
|
||||
$( "#statusContainer:contains('resizing')" ).css("background-color", "#ff9800" );
|
||||
$( "#statusContainer:contains('deadly')" ).css("background-color", "#f44336" );;
|
||||
var node2 = {"quorum":[]};
|
||||
for (var node in a.quorum){
|
||||
node2.quorum.push(node)
|
||||
};
|
||||
w3DisplayData("id01", node2);
|
||||
$('.tablink').css('display', 'block');
|
||||
if (n != undefined && n != 'dead'){
|
||||
var t = new Date(a.quorum[n]["updated"] * 1000)
|
||||
var up_formatted = t.getFullYear() + "/" +
|
||||
(t.getMonth() + 1) + "/" +
|
||||
t.getDate() + " " +
|
||||
t.getHours() + ":" +
|
||||
t.getMinutes() + ":" +
|
||||
t.getSeconds();
|
||||
$("#name").html(n);
|
||||
$("#ipv4").html(a.quorum[n]["ip"]["v4"].join("<br>"));
|
||||
$("#ipv6").html(a.quorum[n]["ip"]["v6"].join("<br>"));
|
||||
$("#updated").html(up_formatted);
|
||||
if (a.quorum[n]["mounts"] != null) {
|
||||
var mnt_block = "";
|
||||
for (i in a.quorum[n].mounts) {
|
||||
var mnt = a.quorum[n].mounts[i];
|
||||
mnt_block += "<a href='javascript:void(0)' onClick='unmount(n, a.quorum[n].mounts[i].mountpoint, a.quorum[n].mounts[i].block)' >unmount</a><br>Mountpoint: "
|
||||
+ mnt.mountpoint + "<br>Mountopts: "
|
||||
+ mnt.mountopts + "<br>Fstype: "
|
||||
+ mnt.fstype +
|
||||
"<br>Pool: " + mnt.pool +
|
||||
"<br>Image: " + mnt.image +
|
||||
"<br>Block: " + mnt.block +"<br>";
|
||||
}
|
||||
$("#mon").html(mnt_block);
|
||||
}
|
||||
else { $("#mon").html("")}
|
||||
}
|
||||
if (n =='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("<br>"));
|
||||
$("#ipv6").html(a.deadlyreason["ip"]["v6"].join("<br>"));
|
||||
$("#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 + "<br>" + mnt.mountopts + "<br>" + mnt.fstype + "<br>" + mnt.pool + "<br>" + mnt.image + "<br><br>";
|
||||
}
|
||||
$("#mon").html(mnt_block);
|
||||
} else { $("#mon").html("") }
|
||||
}
|
||||
}
|
||||
function openNode(evt, nodeName) {
|
||||
var i, x, tablinks;
|
||||
n = nodeName;
|
||||
x = document.getElementsByClassName("node");
|
||||
tablinks = document.getElementsByClassName("tablink");
|
||||
if (n == 'dead') {
|
||||
$('#details').css("border", "2px solid #f44336");
|
||||
if ($('#showDeadlyDetails').html() == "Show details") {
|
||||
$('#details').css("display", "block");
|
||||
$('#showDeadlyDetails').text('Hide details');
|
||||
} else {
|
||||
$('#details').css("display", "none");
|
||||
$('#showDeadlyDetails').text('Show details');
|
||||
}
|
||||
} else {$('#details').css("border", "").css("display", "block") }
|
||||
}
|
115
rbmd/templates/rbmd/index.html
Normal file
115
rbmd/templates/rbmd/index.html
Normal file
@ -0,0 +1,115 @@
|
||||
{% load staticfiles %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>RBMD</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"> <link rel="stylesheet" href="style.css">
|
||||
<script src="http://www.w3schools.com/lib/w3data.js"></script>
|
||||
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||
<script src={% static "script.js" %}></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<style>
|
||||
@media screen and (max-width: 600px){
|
||||
.sidenav {
|
||||
height:auto;
|
||||
}
|
||||
}
|
||||
.sidenav {height:90%;}
|
||||
#status {color: #fff;}
|
||||
header.w3-panel {height: 10%}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class = "w3-panel">
|
||||
<a onclick="$('#mount').css('display', 'block')" class="w3-btn w3-xlarge " id="mountFormTrigger">Mount <i class="fa fa-thumbs-up"></i></a>
|
||||
<a href='/'><img src={% static 'images-logo.png' %} class="w3-right w3-hover-opacity" width='20%' ></a>
|
||||
</header>
|
||||
|
||||
<div id="mount" class="w3-modal">
|
||||
<div class="w3-modal-content">
|
||||
<header class="w3-container w3-light-grey">
|
||||
<span onclick="$('#mount').css('display', 'none')" class="w3-closebtn">×</span>
|
||||
<h2>Mount</h2>
|
||||
</header>
|
||||
<form method="post" action="" role="form" class="w3-container form" > {% 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>
|
||||
<label class="w3-label w3-text-black">Image: <input name="image" class="w3-input" type="text"> </label><br>
|
||||
<label class="w3-label w3-text-black">mountpoint: <input name="mountpoint" class="w3-input" type="text"> </label><br>
|
||||
<label class="w3-label w3-text-black">mountopts: <input name="mountopts" class="w3-input" type="text"> </label><br>
|
||||
<label class="w3-label w3-text-black">fstype: <input name="fstype" class="w3-input" type="text"> </label><br>
|
||||
<button class="w3-btn w3-black" type="submit">Mount</button>
|
||||
</form>
|
||||
<footer class="w3-container w3-light-grey">
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w3-container">
|
||||
<div class="w3-row">
|
||||
<div class="sidenav w3-light-grey w3-col m3" id="id01">
|
||||
<div class="w3-container">
|
||||
<h4> Leader: </h4> <span id='leader' class="tablink"></span>
|
||||
<h4>Nodes: </h4>
|
||||
{% for node in nodes %}
|
||||
<a href="javascript:void(0)" class="tablink" onclick="openNode(event, '{{node}}')" style='display:none'>{{node}}</a>
|
||||
{% endfor %}
|
||||
<h4>Metrics: </h4>
|
||||
{{ metrics }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w3-col m9" >
|
||||
<div class="w3-container" style="height:50px; position:relative" id="statusContainer">
|
||||
<div class="w3-padding w3-display-left" id="status">Status... </div>
|
||||
<button class="w3-display-right w3-btn" id="showDeadlyDetails" onClick="openNode(event, 'dead')" style="display: none">Show details</button>
|
||||
</div>
|
||||
|
||||
|
||||
{% if node %}
|
||||
<div class="w3-container w3-red w3-animate-opacity">
|
||||
<span onclick="this.parentElement.style.display='none'" class="w3-closebtn">×</span>
|
||||
<div id="rsp">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<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>
|
||||
<tr><td> IPv4:</td> <td> <span id='ipv4'></span></td> </tr>
|
||||
<tr><td> IPv6:</td> <td> <span id='ipv6'></span></td> </tr>
|
||||
<tr><td> Updated:</td> <td> <span id='updated'></span></td> </tr>
|
||||
<tr><td>
|
||||
Mounts:</td> <td id="mon">
|
||||
</td> </tr>
|
||||
</table>
|
||||
</div>
|
||||
<div id='test' class="w3-col" style="height: 50px"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
{% if node %}
|
||||
<script>
|
||||
var res = <?=$response?>;
|
||||
message = "<h3>" + res["state"] + "</h3> <p>"+ res["message"] +"</p>";
|
||||
$("#rsp").html(message)
|
||||
</script>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</body>
|
||||
<script>
|
||||
var ws = new WebSocket("{{ws}}");
|
||||
var a, n;
|
||||
ws.onopen = function() {ws.send(""); };
|
||||
ws.onmessage = function (evt) {
|
||||
a = JSON.parse(evt.data);
|
||||
//document.getElementById("test").innerHTML = evt.data;
|
||||
displayData(a);
|
||||
|
||||
};
|
||||
</script>
|
24
rbmd/urls.py
Normal file
24
rbmd/urls.py
Normal file
@ -0,0 +1,24 @@
|
||||
"""rbmd URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/1.9/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
from django.contrib import admin
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^$', views.panel),
|
||||
url(r'^status$', views.get_status),
|
||||
]
|
34
rbmd/views.py
Normal file
34
rbmd/views.py
Normal file
@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
import json
|
||||
import requests
|
||||
|
||||
def get_metrics():
|
||||
with open('conf.json') as conf:
|
||||
api = json.load(conf)["api"]
|
||||
print api
|
||||
#try: res = requests.get(api + metrics)
|
||||
return api
|
||||
|
||||
def panel(request):
|
||||
with open('conf.json') as conf:
|
||||
ws = json.load(conf)["ws"]
|
||||
metrics = get_metrics()
|
||||
return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics})
|
||||
|
||||
|
||||
def get_status(request):
|
||||
with open('conf.json') as conf:
|
||||
status = json.load(conf)["status"]
|
||||
#try: res = requests.get(status)
|
||||
return HttpResponse(status)
|
||||
|
||||
def mount():
|
||||
pass
|
||||
|
||||
def unmount():
|
||||
pass
|
||||
|
16
rbmd/wsgi.py
Normal file
16
rbmd/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for rbmd project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rbmd.settings")
|
||||
|
||||
application = get_wsgi_application()
|
Loading…
Reference in New Issue
Block a user