-
Notifications
You must be signed in to change notification settings - Fork 364
/
config.py.in
189 lines (147 loc) · 6.51 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#
# 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 wok.config import PluginConfig, PluginPaths
from wok.utils import load_plugin_conf
from wok.xmlutils.utils import xpath_get_text
kimchiLock = threading.Lock()
__with_spice__ = "@withspice@"
__with_spice_web_client__ = "@withspicewebclient@"
__version__ = "@kimchiversion@"
__release__ = "@kimchirelease@"
# Storage pool constant for read-only pool types
READONLY_POOL_TYPE = ['iscsi', 'scsi', 'mpath']
def get_libvirt_path():
run_state_dir = "@runstatedir@" if "@runstatedir@" else "@localstatedir@/run"
return os.path.join(run_state_dir, 'libvirt')
def get_kimchi_version():
return "-".join([__version__, __release__])
def with_spice_web_client():
return __with_spice_web_client__ == 'yes'
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():
return load_plugin_conf('kimchi')
config = get_config()
def find_qemu_binary(find_emulator=False):
try:
connect = libvirt.open(None)
except Exception as 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 as 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')
if __with_spice_web_client__ == 'yes':
self.spice_file = os.path.join(self.ui_dir,
'spice-web-client/index.html')
self.spice_dir = os.path.join(self.ui_dir, 'spice-web-client')
else:
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},
'/spice-web-client': {'type': 'dir',
'path': kimchiPaths.spice_dir},
'/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.items():
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)