something

This commit is contained in:
lulzette 2021-03-24 19:33:00 +00:00
parent af61dde196
commit d4347513f1
4 changed files with 4478 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

4425
bottle.py Normal file

File diff suppressed because it is too large Load Diff

50
index.py Normal file
View 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)

View File

@ -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()))