forked from kimchi-project/kimchi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py.in
175 lines (135 loc) · 5.89 KB
/
config.py.in
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#
# Project Kimchi
#
# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import libvirt
import os
import platform
import threading
from cherrypy.lib.reprconf import Parser
from wok.config import PluginConfig, PluginPaths
from wok.xmlutils.utils import xpath_get_text
kimchiLock = threading.Lock()
__with_spice__ = "@withspice@"
__version__ = "@kimchiversion@"
__release__ = "@kimchirelease@"
# Storage pool constant for read-only pool types
READONLY_POOL_TYPE = ['iscsi', 'scsi', 'mpath']
def get_kimchi_version():
return "-".join([__version__, __release__])
def get_distros_store():
return os.path.join(kimchiPaths.sysconf_dir, 'distros.d')
def get_debugreports_path():
return os.path.join(PluginPaths('kimchi').state_dir, 'debugreports')
def get_object_store():
return os.path.join(PluginPaths('kimchi').state_dir, 'objectstore')
def get_screenshot_path():
return os.path.join(PluginPaths('kimchi').state_dir, 'screenshots')
def get_virtviewerfiles_path():
return os.path.join(PluginPaths('kimchi').state_dir, 'virtviewerfiles')
def get_config():
plugin_conf = PluginPaths('kimchi').conf_file
return Parser().dict_from_file(plugin_conf)
config = get_config()
def find_qemu_binary(find_emulator=False):
try:
connect = libvirt.open(None)
except Exception, e:
raise Exception("Unable to get qemu binary location: %s" % e)
try:
xml = connect.getCapabilities()
# On Little Endian system, the qemu binary is
# qemu-system-ppc64, not qemu-system-ppc64le as expected
arch = platform.machine()
if arch == "ppc64le":
arch = "ppc64"
if find_emulator:
expr = "/capabilities/guest/arch[@name='%s']\
/emulator" % arch
else:
expr = "/capabilities/guest/arch[@name='%s']\
/domain[@type='kvm']/emulator" % arch
res = xpath_get_text(xml, expr)
location = res[0]
except Exception, e:
raise Exception("Unable to get qemu binary location: %s" % e)
finally:
connect.close()
return location
class KimchiPaths(PluginPaths):
def __init__(self):
super(KimchiPaths, self).__init__('kimchi')
self.spice_file = os.path.join(self.ui_dir,
'spice-html5/pages/spice_auto.html')
if __with_spice__ == 'yes':
self.spice_dir = os.path.join(self.ui_dir, 'spice-html5')
elif os.path.exists('@datadir@/spice-html5'):
self.spice_dir = '@datadir@/spice-html5'
else:
self.spice_dir = '/usr/share/spice-html5'
if os.path.exists('@datadir@/novnc'):
self.novnc_dir = '@datadir@/novnc'
else:
self.novnc_dir = '/usr/share/novnc'
if self.installed:
self.spice_css_file = os.path.join(self.spice_dir, 'spice.css')
# Expose system configuration directory
self.sysconf_dir = os.path.join('@sysconfdir@', 'kimchi')
else:
self.spice_css_file = os.path.join(self.spice_dir, 'css/spice.css')
self.sysconf_dir = self.add_prefix(self.plugin_dir)
self.serial_dir = os.path.join(self.ui_dir, 'serial')
kimchiPaths = KimchiPaths()
class KimchiConfig(PluginConfig):
def __init__(self):
super(KimchiConfig, self).__init__('kimchi')
static_config = {
'/novnc': {'type': 'dir',
'path': kimchiPaths.novnc_dir},
'/spice-html5': {'type': 'dir',
'path': kimchiPaths.spice_dir},
'/spice_auto.html': {'type': 'file',
'path': kimchiPaths.spice_file},
'/spice-html5/spice.css': {'type': 'file',
'path': kimchiPaths.spice_css_file},
'/serial': {'type': 'dir',
'path': kimchiPaths.serial_dir}}
custom_config = {
'/help': {'tools.nocache.on': True,
'tools.staticdir.dir':
os.path.join(kimchiPaths.ui_dir, 'pages/help'),
'tools.staticdir.on': True},
'/data/screenshots': {'tools.nocache.on': False,
'tools.staticdir.dir':
get_screenshot_path(),
'tools.staticdir.on': True},
'/data/virtviewerfiles': {'tools.nocache.on': False,
'tools.staticdir.dir':
get_virtviewerfiles_path(),
'tools.staticdir.on': True}}
for uri, data in static_config.iteritems():
custom_config[uri] = {'tools.nocache.on': True,
'tools.wokauth.on': True}
path = data['path']
if data['type'] == 'dir':
custom_config[uri].update({'tools.staticdir.on': True,
'tools.staticdir.dir': path})
elif data['type'] == 'file':
custom_config[uri].update({'tools.staticfile.on': True,
'tools.staticfile.filename': path})
self.update(custom_config)