-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminPage.py
125 lines (106 loc) · 3.85 KB
/
AdminPage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import os, os.path
import string
import cherrypy
import random
import getInfo
import cgi
import json
from VMMEditor import VMMEditor
class Table(object):
#HTML header.
head = """
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/style.css" rel="stylesheet">
<title>
DAaaS VM Manager
</title>
</head>
"""
#HTML Body
body = """
<body>
<div>
<img src="/static/images/RAL.png" alt="Logo"
width="261" height="57">
</div>
<div class="dropdown">
<button class="dropbtn">Navigation</button>
<div class="dropdown-content">
<a href="index">Virtual Machine Manager</a>
<a href="VMPools">Virtual Machine Pools</a>
</div>
</div>
<h1>DAaaS Virtual Machine Manager</h1>
{}
</body>
"""
@cherrypy.expose
def index(self):
machines = getInfo.getMachines()
machineTypes = getInfo.getMachineTypes()
typeNames = {}
name = {}
for machineType in machineTypes:
typeNames[machineType['id']] = machineType['name']
#Adding if statement so if no data then instead of doing table, it will print an error message.
if not machines:
contents = "Error - No Data: We are working hard to fix this issue now"
else:
table = "<table>"
table += "<th>" + "Type Of Virtual Machine" + "</th>"
table += "<th>" + "Hostname " + "</th>"
table += "<th>" + "VM ID" + "</th>"
table += "<th>" + "State" + "</th>"
table += "<th>" + "Last Updated At ..." + "</th>"
table += "<th>" + "Update ?" + "<th>"
#Putting all lists into a table.
for machine in machines:
table += "<tr>"
table += "<td>" + typeNames[machine['machine_type_id']] + "</td>"
table += "<td>" + machine['hostname'] + "</td>"
table += "<td>" + str(machine['id']) + "</td>"
table += "<td>" + machine['state'] + "</td>"
table += "<td>" + str(machine['acquired_time']) + "</td>"
table += "<th>" + "<button>UpdateNow</button>" + "</th>"
table += "</table>"
contents = table
#Add all component strings together to make html.
html = "<html>" + self.head +self.body.format(contents) + "</html>"
return html
@cherrypy.expose
def VMPools(self):
with open('form.html', 'r') as content_file:
contents = content_file.read()
#Add all component strings together to make html.
html = "<html>" + self.head + self.body.format(contents) + "</html>"
return html
@cherrypy.expose
def handleForm(self, **params):
editor = VMMEditor()
params['parameters']= json.loads(params['parameters'])
params['tags']= json.loads(params['tags'])
parameters = json.dumps(params)
code, response = editor.add_new_pool(parameters)
if code == 200:
contents = "New VM Pool created."
else:
contents = """
Response = {1}
"""
#Add all component strings together to make html.
html = "<html>" + self.head + self.body.format(contents.format(code,response)) + "</html>"
return html
if __name__ == '__main__':
conf = {
'/': {
'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': './public'
}
}
cherrypy.server.socket_host = '0.0.0.0'
cherrypy.quickstart(Table(), '/', conf)