-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.py
executable file
·107 lines (85 loc) · 2.95 KB
/
server.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
import os, sys, errno, pwd, grp
# change the current working directory and python path
location = os.path.dirname(os.path.abspath(__file__))
sys.path.append(location)
os.chdir(location)
import cherrypy
import subprocess
from subprocess import Popen
from controllers.home import Home
cherrypy.config.update("config/default.conf")
try:
cherrypy.config.update("config/global.conf")
except IOError:
pass
sessionsDir = os.path.join(location, cherrypy.config.get("tools.sessions.storage_path"))
try:
os.makedirs(sessionsDir)
except OSError as ex:
if ex.errno != errno.EEXIST:
raise ex
if not (os.access(sessionsDir, os.W_OK)):
raise cherrypy.HTTPError('500 Current user has no write access to ' + sessionsDir)
GOODWORDS = cherrypy.config.get("goodwords")
BADWORDS = cherrypy.config.get("badwords")
f = open(GOODWORDS)
goodwords = f.readlines()
cherrypy.config.goodwords = [w.strip() for w in goodwords]
f.close()
f = open(BADWORDS)
badwords = f.readlines()
cherrypy.config.badwords = [w.strip() for w in badwords]
f.close()
cloudPlatform = cherrypy.config.get("cloudPlatform")
# PAGES
home = Home()
if cloudPlatform == "opennebula":
from controllers.api.opennebula.machines import Machines
if cloudPlatform == "openstack":
from controllers.api.openstack.machines import Machines
home.machines = Machines()
cherrypy.tree.mount(home, "/", "config/pages.conf")
# API
api = lambda:None
if cloudPlatform == "opennebula":
from controllers.api.opennebula.vm import VM
from controllers.api.opennebula.quota import Quota
from controllers.api.opennebula.user import User
from controllers.api.opennebula.templatelist import TemplateList
if cloudPlatform == "openstack":
from controllers.api.openstack.vm import VM
from controllers.api.openstack.vnc import VNC
from controllers.api.openstack.quota import Quota
from controllers.api.openstack.user import User
from controllers.api.openstack.templatelist import TemplateList
from controllers.api.openstack.flavors import Flavors
from controllers.api.openstack.projects import Projects
from controllers.api.openstack.rename import Rename
api.flavors = Flavors()
api.projects = Projects()
api.rename = Rename()
api.vnc = VNC()
api.vm = VM()
api.quota = Quota()
api.user = User()
api.templatelist = TemplateList()
cherrypy.tree.mount(api, "/api", "config/api.conf")
# Launch websockify for NoVNC
#wsparams = [
# '/usr/bin/websockify',
# '-v',
# str(cherrypy.config.get("wsport")),
# '--target-config=' + cherrypy.config.get("wstokendir")
#]
#if cherrypy.config.get("wscert") != None:
# wsparams.append('--cert=' + cherrypy.config.get("wscert"))
# wsparams.append('--key=' + cherrypy.config.get("wskey"))
#websockify = Popen(wsparams)
if cherrypy.config.get("wsgi_enabled") == True:
# make WSGI compliant
application = cherrypy.tree
else:
# run as stand alone
cherrypy.engine.start()
cherrypy.engine.block()
websockify.terminate()