diff --git a/rbmd/__init__.py b/rbmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rbmd/conf.json b/rbmd/conf.json new file mode 100644 index 0000000..09026a0 --- /dev/null +++ b/rbmd/conf.json @@ -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" + +} diff --git a/rbmd/settings.py b/rbmd/settings.py new file mode 100644 index 0000000..45f797b --- /dev/null +++ b/rbmd/settings.py @@ -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"), ] diff --git a/rbmd/static/images-logo.png b/rbmd/static/images-logo.png new file mode 100644 index 0000000..9ab8646 Binary files /dev/null and b/rbmd/static/images-logo.png differ diff --git a/rbmd/static/script.js b/rbmd/static/script.js new file mode 100644 index 0000000..bc9e08c --- /dev/null +++ b/rbmd/static/script.js @@ -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 += "";} + + $('#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 += "";} + $('#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 = "

" + 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"); + } + $("#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("
")); + $("#ipv6").html(a.quorum[n]["ip"]["v6"].join("
")); + $("#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 += "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 (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("
")); + $("#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("") } + } + } +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") } +} diff --git a/rbmd/templates/rbmd/index.html b/rbmd/templates/rbmd/index.html new file mode 100644 index 0000000..879b3a1 --- /dev/null +++ b/rbmd/templates/rbmd/index.html @@ -0,0 +1,115 @@ +{% load staticfiles %} + + + + RBMD + + + + + + + + + + +
+Mount + +
+ +
+
+
+ × +

Mount

+
+
{% csrf_token %} +
+ +
+
+
+
+
+ +
+ +
+
+ +
+
+
+
+

Leader:

+

Nodes:

+ {% for node in nodes %} + + {% endfor %} +

Metrics:

+ {{ metrics }} +
+
+ +
+
+
Status...
+ +
+ + +{% if node %} +
+ × +
+
+
+{% endif %} + +
+
+
+ +{% if node %} + + +{% endif %} + + + diff --git a/rbmd/urls.py b/rbmd/urls.py new file mode 100644 index 0000000..4f79a34 --- /dev/null +++ b/rbmd/urls.py @@ -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), +] diff --git a/rbmd/views.py b/rbmd/views.py new file mode 100644 index 0000000..6329bae --- /dev/null +++ b/rbmd/views.py @@ -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 + diff --git a/rbmd/wsgi.py b/rbmd/wsgi.py new file mode 100644 index 0000000..4532479 --- /dev/null +++ b/rbmd/wsgi.py @@ -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()