2017-08-31 00:52:20 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-09-01 14:52:47 +03:00
|
|
|
from django.http import HttpResponse, JsonResponse
|
2017-08-31 00:52:20 +03:00
|
|
|
from django.shortcuts import render
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
|
2017-09-01 14:52:47 +03:00
|
|
|
def status():
|
2017-08-31 18:10:08 +03:00
|
|
|
with open('conf.json') as conf:
|
|
|
|
status = json.load(conf)["api"] + '/status'
|
2017-09-01 14:52:47 +03:00
|
|
|
try: res = requests.get(status).content
|
2017-08-31 18:10:08 +03:00
|
|
|
except: res = 'connection can\'t be established'
|
2017-09-01 14:52:47 +03:00
|
|
|
return res
|
2017-08-31 00:52:20 +03:00
|
|
|
|
2017-09-01 14:52:47 +03:00
|
|
|
def get_status(request):
|
|
|
|
my_status = status()
|
|
|
|
return JsonResponse(my_status, safe=False)
|
2017-08-31 00:52:20 +03:00
|
|
|
|
2017-09-01 14:52:47 +03:00
|
|
|
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)
|
2017-08-31 00:52:20 +03:00
|
|
|
|
2017-09-01 14:52:47 +03:00
|
|
|
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)
|
2017-08-31 00:52:20 +03:00
|
|
|
|
2017-08-31 18:10:08 +03:00
|
|
|
def resolve():
|
2017-09-01 14:52:47 +03:00
|
|
|
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)
|
|
|
|
|
2017-08-31 18:10:08 +03:00
|
|
|
def get_metrics():
|
|
|
|
with open('conf.json') as conf:
|
|
|
|
metrics = json.load(conf)["api"] + '/metrics'
|
2017-09-01 14:52:47 +03:00
|
|
|
try: res = requests.get(metrics).content
|
|
|
|
except: res = 'connection can\'t be established'
|
|
|
|
return res
|
2017-08-31 18:10:08 +03:00
|
|
|
|
|
|
|
def panel(request):
|
|
|
|
with open('conf.json') as conf:
|
|
|
|
ws = json.load(conf)["ws"]
|
|
|
|
metrics = json.loads(get_metrics())
|
2017-09-01 14:52:47 +03:00
|
|
|
my_status = status()
|
|
|
|
return render(request, 'rbmd/index.html', {'ws' : ws, 'metrics' : metrics, 'status' : my_status})
|
2017-08-31 18:10:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
|