something
This commit is contained in:
parent
af61dde196
commit
d4347513f1
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
50
index.py
Normal file
50
index.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from bottle import run, route, request, template,get ,post
|
||||||
|
import libvirt
|
||||||
|
session = libvirt.open('qemu:///system')
|
||||||
|
|
||||||
|
def listVDS():
|
||||||
|
VdsListVar = list()
|
||||||
|
for i in session.listDefinedDomains():
|
||||||
|
VdsListVar.append(i)
|
||||||
|
return VdsListVar
|
||||||
|
|
||||||
|
# Главная страница
|
||||||
|
@route('/')
|
||||||
|
def index():
|
||||||
|
# return template('index.html')
|
||||||
|
# return 'Привет, мир!'
|
||||||
|
return listVDS()
|
||||||
|
|
||||||
|
|
||||||
|
@get('/action') # or @route('/login')
|
||||||
|
def login():
|
||||||
|
return '''
|
||||||
|
<form action="/action" method="post">
|
||||||
|
VDS Name: <input name="username" 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>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
@post('/action') # or @route('/login', method='POST')
|
||||||
|
def do_action():
|
||||||
|
act = request.forms.get('act')
|
||||||
|
dom = session.lookupByName(request.forms.get('username'))
|
||||||
|
|
||||||
|
|
||||||
|
if (act == "start"):
|
||||||
|
dom.create()
|
||||||
|
return "<p>Started succesfully!</p>"
|
||||||
|
elif (act == "stop"):
|
||||||
|
dom.shutdown()
|
||||||
|
return "<p>Stopped</p> <button href='action'>"
|
||||||
|
else:
|
||||||
|
return "Error"
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run(host='0.0.0.0', port=5000, debug=True)
|
2
main.py
2
main.py
@ -47,6 +47,7 @@ def main():
|
|||||||
for i in session.listDefinedDomains():
|
for i in session.listDefinedDomains():
|
||||||
print(i)
|
print(i)
|
||||||
dom = session.lookupByName(i)
|
dom = session.lookupByName(i)
|
||||||
|
|
||||||
print("Is active? "+ str(dom.isActive()))
|
print("Is active? "+ str(dom.isActive()))
|
||||||
dom.create()
|
dom.create()
|
||||||
sleep(15)
|
sleep(15)
|
||||||
@ -55,6 +56,7 @@ def main():
|
|||||||
print("Active? "+str(dom.isActive()))
|
print("Active? "+str(dom.isActive()))
|
||||||
sleep(15)
|
sleep(15)
|
||||||
dom.shutdown()
|
dom.shutdown()
|
||||||
|
|
||||||
sleep(15)
|
sleep(15)
|
||||||
print("Active? "+str(dom.isActive()))
|
print("Active? "+str(dom.isActive()))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user