32
34
DEFAULT_POOL_PATH = "/var/lib/libvirt/images"
34
36
def build_default_pool(conn):
35
"""Helper to build the 'default' storage pool"""
38
Helper to build the 'default' storage pool
36
40
# FIXME: This should use config.get_default_image_path ?
38
42
if not virtinst.util.is_storage_capable(conn):
39
43
# VirtualDisk will raise an error for us
43
48
pool = conn.storagePoolLookupByName(DEFAULT_POOL_NAME)
59
64
raise RuntimeError(_("Couldn't create default storage pool '%s': %s") %
60
65
(DEFAULT_POOL_PATH, str(e)))
67
def get_ideal_path_info(conn, config, name):
68
path = get_default_dir(conn, config)
70
return (path, name, suffix)
72
def get_ideal_path(conn, config, name):
73
target, name, suffix = get_ideal_path_info(conn, config, name)
74
return os.path.join(target, name) + suffix
76
def get_default_pool(conn):
78
for uuid in conn.list_pool_uuids():
79
p = conn.get_pool(uuid)
80
if p.get_name() == DEFAULT_POOL_NAME:
85
def get_default_dir(conn, config):
86
pool = get_default_pool(conn)
89
return pool.get_target_path()
91
return config.get_default_image_dir(conn)
93
def get_default_path(conn, config, name):
94
pool = get_default_pool(conn)
96
default_dir = get_default_dir(conn, config)
99
# Use old generating method
100
origf = os.path.join(default_dir, name + ".img")
104
while os.path.exists(f) and n < 100:
105
f = os.path.join(default_dir, name +
106
"-" + str(n) + ".img")
109
if os.path.exists(f):
114
target, ignore, suffix = get_ideal_path_info(conn, config, name)
116
path = virtinst.Storage.StorageVolume.find_free_name(name,
117
pool_object=pool.pool, suffix=suffix)
119
path = os.path.join(target, path)
62
124
def tooltip_wrapper(obj, txt, func="set_tooltip_text"):
63
125
# Catch & ignore errors - set_tooltip_* is in gtk >= 2.12
64
126
# and we can easily work with lower versions
303
def connect_once(obj, signal, func, *args):
306
def wrap_func(*wrapargs):
308
obj.disconnect(id_list[0])
310
return func(*wrapargs)
312
conn_id = obj.connect(signal, wrap_func, *args)
313
id_list.append(conn_id)
317
def connect_opt_out(obj, signal, func, *args):
320
def wrap_func(*wrapargs):
321
ret = func(*wrapargs)
323
obj.disconnect(id_list[0])
325
conn_id = obj.connect(signal, wrap_func, *args)
326
id_list.append(conn_id)
241
330
def idle_emit(self, signal, *args):
243
332
Safe wrapper for using 'self.emit' with gobject.idle_add
245
334
self.emit(signal, *args)
337
def _safe_wrapper(func, *args):
338
gtk.gdk.threads_enter()
342
gtk.gdk.threads_leave()
344
def safe_idle_add(func, *args):
346
Make sure idle functions are run thread safe
348
return gobject.idle_add(_safe_wrapper, func, *args)
350
def safe_timeout_add(timeout, func, *args):
352
Make sure timeout functions are run thread safe
354
return gobject.timeout_add(timeout, _safe_wrapper, func, *args)
248
356
def uuidstr(rawuuid):
249
357
hx = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']