concated and it works!
This commit is contained in:
parent
b03ad0df9a
commit
c555e5a406
12
main.py
12
main.py
@ -2,18 +2,24 @@
|
||||
|
||||
from bottle import run, route, request, template,get ,post
|
||||
import libvirt, json
|
||||
import urllib.request, json
|
||||
session = libvirt.open('qemu:///system')
|
||||
|
||||
url_path = "http://localhost:5000/list"
|
||||
def listVDS():
|
||||
VdsListVar = list()
|
||||
for domain in session.listAllDomains(0):
|
||||
VdsListVar.append(dict(name=domain.name(),state=domain.isActive()))
|
||||
return json.dumps(VdsListVar)
|
||||
|
||||
# @route('/list')
|
||||
# def index():
|
||||
# return str(listVDS())
|
||||
|
||||
|
||||
@route('/')
|
||||
def index():
|
||||
return str(listVDS())
|
||||
|
||||
# domainList = json.loads(urllib.request.urlopen(url_path).read().decode())
|
||||
return template('index', domainList=json.loads(listVDS()))
|
||||
|
||||
|
||||
@post('/action') # or @route('/login', method='POST')
|
||||
|
5
views/footer.tpl
Normal file
5
views/footer.tpl
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
9
views/header.tpl
Normal file
9
views/header.tpl
Normal file
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
libvirt domctl
|
||||
</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
|
||||
</head>
|
||||
<body>
|
39
views/index.tpl
Normal file
39
views/index.tpl
Normal file
@ -0,0 +1,39 @@
|
||||
%include ('header.tpl')
|
||||
|
||||
<nav class="navbar navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Welcome to libvirt domain ctl</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<div class="alert alert-primary" role="alert">
|
||||
RAW: {{domainList}}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
%for i in domainList:
|
||||
<div class="col-sm-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{i['name']}}</h5>
|
||||
<p class="card-text">State: {{i['state']}}</p>
|
||||
<form method="POST" action="http://192.168.100.50:5000/action" id={{i['name']}}>
|
||||
<input name="name" value="{{i['name']}}" hidden>
|
||||
<button name="act" class="btn btn-success" value="start"><i class="bi bi-play"></i> Start</button>
|
||||
<button name="act" class="btn btn-danger" value="destroy"><i class="bi bi-x-octagon"></i> Destroy</button>
|
||||
<button name="act" class="btn btn-warning" value="stop"><i class="bi bi-slash-circle"></i> Stop</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
%end
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
%include ('footer.tpl')
|
Loading…
Reference in New Issue
Block a user