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():
|
||||
VdsListVar = list()
|
||||
for i in session.listDefinedDomains():
|
||||
VdsListVar.append(i)
|
||||
for i, vdsName in enumerate(session.listDefinedDomains()):
|
||||
dom = session.lookupByName(vdsName)
|
||||
VdsListVar.append(dict(name=vdsName,state=dom.isActive()))
|
||||
return VdsListVar
|
||||
|
||||
@route('/')
|
||||
@ -20,7 +21,7 @@ def index():
|
||||
def login():
|
||||
return '''
|
||||
<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>
|
||||
<input type="radio" name="act" value="start"> Start<Br>
|
||||
<input type="radio" name="act" value="stop"> Stop<Br>
|
||||
@ -33,20 +34,19 @@ def login():
|
||||
@post('/action') # or @route('/login', method='POST')
|
||||
def do_action():
|
||||
act = request.forms.get('act')
|
||||
dom = session.lookupByName(request.forms.get('username'))
|
||||
|
||||
|
||||
dom = session.lookupByName(request.forms.get('name'))
|
||||
if (act == "start"):
|
||||
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"):
|
||||
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"):
|
||||
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:
|
||||
return "Error"
|
||||
return dict(state="error")
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(host='0.0.0.0', port=5000, debug=True)
|
Loading…
Reference in New Issue
Block a user