action func
This commit is contained in:
parent
deacb40cae
commit
3d057b8f9b
@ -6,32 +6,46 @@ from django.shortcuts import render
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def action(name, method):
|
||||||
|
|
||||||
|
with open('conf.json') as conf:
|
||||||
|
url = json.load(conf)["api"] + '/' + name
|
||||||
|
if method == 'get':
|
||||||
|
try: res = requests.get(url).content
|
||||||
|
except: res = 'connection can\'t be established'
|
||||||
|
elif method == 'post':
|
||||||
|
try: res = requests.post(url).content
|
||||||
|
except: res = 'connection can\'t be established'
|
||||||
|
return res
|
||||||
|
'''
|
||||||
def status():
|
def status():
|
||||||
with open('conf.json') as conf:
|
with open('conf.json') as conf:
|
||||||
status = json.load(conf)["api"] + '/status'
|
status = json.load(conf)["api"] + '/status'
|
||||||
try: res = requests.get(status).content
|
try: res = requests.get(status).content
|
||||||
except: res = 'connection can\'t be established'
|
except: res = 'connection can\'t be established'
|
||||||
return res
|
return res
|
||||||
|
'''
|
||||||
def get_status(request):
|
def get_status(request):
|
||||||
my_status = status()
|
my_status = action('status', 'get')
|
||||||
return JsonResponse(my_status, safe=False)
|
return JsonResponse(my_status, safe=False)
|
||||||
|
|
||||||
def mount(request):
|
def mount(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
data = request.POST.dict()
|
data = request.POST.dict()
|
||||||
#s = mount(data)
|
'''
|
||||||
with open('conf.json') as conf:
|
with open('conf.json') as conf:
|
||||||
url = json.load(conf)["api"] + '/mount'
|
url = json.load(conf)["api"] + '/mount'
|
||||||
res = requests.post(url, json.dumps(data))
|
res = requests.post(url, json.dumps(data))
|
||||||
print res
|
print res
|
||||||
return JsonResponse(res.content, safe=False)
|
'''
|
||||||
|
res = action('mount', 'post')
|
||||||
|
return JsonResponse(res, safe=False)
|
||||||
|
|
||||||
def unmount(request):
|
def unmount(request):
|
||||||
print request.GET.dict()
|
|
||||||
with open('conf.json') as conf:
|
with open('conf.json') as conf:
|
||||||
url = json.load(conf)["api"] + '/umount'
|
url = json.load(conf)["api"] + '/umount'
|
||||||
#data = json.dumps({'node': 'ceph1', 'mountpoint': '/mnt', 'block': 'rbd0'})
|
|
||||||
data = request.GET.dict()
|
data = request.GET.dict()
|
||||||
try: res = requests.post(url, json.dumps(data)).content
|
try: res = requests.post(url, json.dumps(data)).content
|
||||||
except: res = 'connection can\'t be established'
|
except: res = 'connection can\'t be established'
|
||||||
|
Loading…
Reference in New Issue
Block a user