From c555e5a4063e78e6795eb9fb27fda03a01f7bd33 Mon Sep 17 00:00:00 2001 From: lulzette Date: Thu, 15 Apr 2021 18:04:33 +0000 Subject: [PATCH] concated and it works! --- main.py | 12 +++++++++--- views/footer.tpl | 5 +++++ views/header.tpl | 9 +++++++++ views/index.tpl | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 views/footer.tpl create mode 100644 views/header.tpl create mode 100644 views/index.tpl diff --git a/main.py b/main.py index d561c8a..74754ee 100644 --- a/main.py +++ b/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') diff --git a/views/footer.tpl b/views/footer.tpl new file mode 100644 index 0000000..f5d8f82 --- /dev/null +++ b/views/footer.tpl @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/views/header.tpl b/views/header.tpl new file mode 100644 index 0000000..7cb2271 --- /dev/null +++ b/views/header.tpl @@ -0,0 +1,9 @@ + + + + libvirt domctl + + + + + diff --git a/views/index.tpl b/views/index.tpl new file mode 100644 index 0000000..45d7301 --- /dev/null +++ b/views/index.tpl @@ -0,0 +1,39 @@ +%include ('header.tpl') + + + +
+
+ + + + +
+ %for i in domainList: +
+
+
+
{{i['name']}}
+

State: {{i['state']}}

+
+ + + + +
+
+
+
+ %end +
+
+
+ + +%include ('footer.tpl') \ No newline at end of file