okay it works and it supports json
This commit is contained in:
parent
36f3118b94
commit
61a44db2f9
20
main.py
20
main.py
@ -6,8 +6,9 @@ session = libvirt.open('qemu:///system')
|
|||||||
|
|
||||||
def listVDS():
|
def listVDS():
|
||||||
VdsListVar = list()
|
VdsListVar = list()
|
||||||
for i in session.listDefinedDomains():
|
for i, vdsName in enumerate(session.listDefinedDomains()):
|
||||||
VdsListVar.append(i)
|
dom = session.lookupByName(vdsName)
|
||||||
|
VdsListVar.append(dict(name=vdsName,state=dom.isActive()))
|
||||||
return VdsListVar
|
return VdsListVar
|
||||||
|
|
||||||
@route('/')
|
@route('/')
|
||||||
@ -20,7 +21,7 @@ def index():
|
|||||||
def login():
|
def login():
|
||||||
return '''
|
return '''
|
||||||
<form action="/action" method="post">
|
<form action="/action" method="post">
|
||||||
VDS Name: <input name="username" type="text" /> <br>
|
VDS Name: <input name="name" type="text" /> <br>
|
||||||
Action (start/stop): <br>
|
Action (start/stop): <br>
|
||||||
<input type="radio" name="act" value="start"> Start<Br>
|
<input type="radio" name="act" value="start"> Start<Br>
|
||||||
<input type="radio" name="act" value="stop"> Stop<Br>
|
<input type="radio" name="act" value="stop"> Stop<Br>
|
||||||
@ -33,20 +34,19 @@ def login():
|
|||||||
@post('/action') # or @route('/login', method='POST')
|
@post('/action') # or @route('/login', method='POST')
|
||||||
def do_action():
|
def do_action():
|
||||||
act = request.forms.get('act')
|
act = request.forms.get('act')
|
||||||
dom = session.lookupByName(request.forms.get('username'))
|
dom = session.lookupByName(request.forms.get('name'))
|
||||||
|
|
||||||
|
|
||||||
if (act == "start"):
|
if (act == "start"):
|
||||||
dom.create()
|
dom.create()
|
||||||
return "<p>Started "+request.forms.get('username')+" succesfully!</p><a href='/action'>back</a>"
|
return dict(name=request.forms.get('name'),state="started")
|
||||||
elif (act == "stop"):
|
elif (act == "stop"):
|
||||||
dom.shutdown()
|
dom.shutdown()
|
||||||
return "<p>Stopped "+request.forms.get('username')+"</p> <a href='/action'>back</a>"
|
return dict(name=request.forms.get('name'),state="shutdown")
|
||||||
elif (act == "destroy"):
|
elif (act == "destroy"):
|
||||||
dom.destroy()
|
dom.destroy()
|
||||||
return "<p>Destroyed "+request.forms.get('username')+"</p> <a href='/action'>back</a>"
|
return dict(name=request.forms.get('name'),state="destroyed")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return "Error"
|
return dict(state="error")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run(host='0.0.0.0', port=5000, debug=True)
|
run(host='0.0.0.0', port=5000, debug=True)
|
Loading…
Reference in New Issue
Block a user