2006-06-29 03:50:17 +08:00
|
|
|
#
|
2013-10-28 04:59:46 +08:00
|
|
|
# Copyright (C) 2006, 2012-2013 Red Hat, Inc.
|
2006-06-29 03:50:17 +08:00
|
|
|
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program 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 General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2007-11-21 00:12:20 +08:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
2006-06-29 03:50:17 +08:00
|
|
|
#
|
2006-08-22 05:45:24 +08:00
|
|
|
import os
|
2011-01-08 03:59:31 +08:00
|
|
|
import logging
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2013-04-12 05:16:33 +08:00
|
|
|
# pylint: disable=E0611
|
2013-04-18 05:39:25 +08:00
|
|
|
from gi.repository import Gio
|
|
|
|
from gi.repository import GLib
|
2012-05-14 21:24:56 +08:00
|
|
|
from gi.repository import Gtk
|
2013-04-12 05:16:33 +08:00
|
|
|
# pylint: enable=E0611
|
2011-01-08 03:59:31 +08:00
|
|
|
|
2012-11-09 23:08:15 +08:00
|
|
|
from virtManager.keyring import vmmKeyring, vmmSecret
|
|
|
|
|
2013-08-09 21:23:01 +08:00
|
|
|
running_config = None
|
|
|
|
|
2006-07-20 02:33:23 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
class SettingsWrapper(object):
|
|
|
|
def __init__(self, settings_id):
|
|
|
|
self._root = settings_id
|
|
|
|
self._settings = Gio.Settings.new(self._root)
|
|
|
|
|
|
|
|
self._settingsmap = {"": self._settings}
|
|
|
|
self._handler_map = {}
|
|
|
|
for child in self._settings.list_children():
|
|
|
|
childschema = self._root + "." + child
|
|
|
|
self._settingsmap[child] = Gio.Settings.new(childschema)
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_key(self, key):
|
|
|
|
value = key.strip("/")
|
|
|
|
settingskey = ""
|
|
|
|
if "/" in value:
|
|
|
|
settingskey, value = value.rsplit("/", 1)
|
|
|
|
return settingskey, value
|
|
|
|
|
|
|
|
def make_vm_settings(self, key):
|
|
|
|
settingskey = self._parse_key(key)[0]
|
|
|
|
|
|
|
|
if settingskey in self._settingsmap:
|
|
|
|
return True
|
|
|
|
|
|
|
|
schema = self._root + ".vm"
|
|
|
|
path = "/" + self._root.replace(".", "/") + key.rsplit("/", 1)[0] + "/"
|
|
|
|
self._settingsmap[settingskey] = Gio.Settings.new_with_path(schema,
|
|
|
|
path)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _find_settings(self, key):
|
|
|
|
settingskey, value = self._parse_key(key)
|
|
|
|
return self._settingsmap[settingskey], value
|
|
|
|
|
|
|
|
def _cmd_helper(self, cmd, key, *args, **kwargs):
|
|
|
|
settings, key = self._find_settings(key)
|
|
|
|
return getattr(settings, cmd)(key, *args, **kwargs)
|
|
|
|
|
|
|
|
def notify_add(self, key, cb, *args, **kwargs):
|
|
|
|
settings, key = self._find_settings(key)
|
|
|
|
def wrapcb(*ignore):
|
|
|
|
return cb(*args, **kwargs)
|
|
|
|
ret = settings.connect("changed::%s" % key, wrapcb, *args, **kwargs)
|
|
|
|
self._handler_map[ret] = settings
|
|
|
|
return ret
|
|
|
|
def notify_remove(self, h):
|
|
|
|
settings = self._handler_map.pop(h)
|
|
|
|
return settings.disconnect(h)
|
|
|
|
|
|
|
|
def get(self, key):
|
|
|
|
return self._cmd_helper("get_value", key).unpack()
|
|
|
|
def set(self, key, value, *args, **kwargs):
|
|
|
|
fmt = self._cmd_helper("get_value", key).get_type_string()
|
|
|
|
return self._cmd_helper("set_value", key,
|
|
|
|
GLib.Variant(fmt, value),
|
|
|
|
*args, **kwargs)
|
2009-02-24 07:50:47 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
|
|
|
|
class vmmConfig(object):
|
|
|
|
# key names for saving last used paths
|
2009-06-24 07:30:12 +08:00
|
|
|
CONFIG_DIR_IMAGE = "image"
|
2011-07-23 07:12:48 +08:00
|
|
|
CONFIG_DIR_ISO_MEDIA = "isomedia"
|
|
|
|
CONFIG_DIR_FLOPPY_MEDIA = "floppymedia"
|
2009-06-24 07:30:12 +08:00
|
|
|
CONFIG_DIR_SAVE = "save"
|
|
|
|
CONFIG_DIR_RESTORE = "restore"
|
|
|
|
CONFIG_DIR_SCREENSHOT = "screenshot"
|
2011-06-09 06:37:35 +08:00
|
|
|
CONFIG_DIR_FS = "fs"
|
2009-06-24 07:30:12 +08:00
|
|
|
|
2009-11-11 03:30:51 +08:00
|
|
|
# Metadata mapping for browse types. Prob shouldn't go here, but works
|
|
|
|
# for now.
|
|
|
|
browse_reason_data = {
|
|
|
|
CONFIG_DIR_IMAGE : {
|
|
|
|
"enable_create" : True,
|
|
|
|
"storage_title" : _("Locate or create storage volume"),
|
|
|
|
"local_title" : _("Locate existing storage"),
|
2012-05-14 21:24:56 +08:00
|
|
|
"dialog_type" : Gtk.FileChooserAction.SAVE,
|
|
|
|
"choose_button" : Gtk.STOCK_OPEN,
|
2009-11-11 03:30:51 +08:00
|
|
|
},
|
|
|
|
|
2011-07-23 07:12:48 +08:00
|
|
|
CONFIG_DIR_ISO_MEDIA : {
|
2009-11-11 03:30:51 +08:00
|
|
|
"enable_create" : False,
|
|
|
|
"storage_title" : _("Locate ISO media volume"),
|
|
|
|
"local_title" : _("Locate ISO media"),
|
2011-06-09 06:37:35 +08:00
|
|
|
},
|
|
|
|
|
2011-07-23 07:12:48 +08:00
|
|
|
CONFIG_DIR_FLOPPY_MEDIA : {
|
|
|
|
"enable_create" : False,
|
|
|
|
"storage_title" : _("Locate floppy media volume"),
|
|
|
|
"local_title" : _("Locate floppy media"),
|
|
|
|
},
|
|
|
|
|
2011-06-09 06:37:35 +08:00
|
|
|
CONFIG_DIR_FS : {
|
|
|
|
"enable_create" : False,
|
|
|
|
"storage_title" : _("Locate directory volume"),
|
|
|
|
"local_title" : _("Locate directory volume"),
|
2012-05-14 21:24:56 +08:00
|
|
|
"dialog_type" : Gtk.FileChooserAction.SELECT_FOLDER,
|
2011-06-09 06:37:35 +08:00
|
|
|
},
|
2009-11-11 03:30:51 +08:00
|
|
|
}
|
|
|
|
|
2009-02-24 07:50:47 +08:00
|
|
|
CONSOLE_SCALE_NEVER = 0
|
|
|
|
CONSOLE_SCALE_FULLSCREEN = 1
|
|
|
|
CONSOLE_SCALE_ALWAYS = 2
|
|
|
|
|
2009-05-12 00:37:47 +08:00
|
|
|
_PEROBJ_FUNC_SET = 0
|
|
|
|
_PEROBJ_FUNC_GET = 1
|
|
|
|
_PEROBJ_FUNC_LISTEN = 2
|
|
|
|
|
2011-04-19 01:14:14 +08:00
|
|
|
DEFAULT_XEN_IMAGE_DIR = "/var/lib/xen/images"
|
|
|
|
DEFAULT_XEN_SAVE_DIR = "/var/lib/xen/dump"
|
|
|
|
|
|
|
|
DEFAULT_VIRT_IMAGE_DIR = "/var/lib/libvirt/images"
|
|
|
|
DEFAULT_VIRT_SAVE_DIR = "/var/lib/libvirt"
|
|
|
|
|
2013-10-03 02:53:41 +08:00
|
|
|
def __init__(self, appname, cliconfig, test_first_run=False):
|
2006-06-14 22:59:40 +08:00
|
|
|
self.appname = appname
|
2013-10-03 02:53:41 +08:00
|
|
|
self.appversion = cliconfig.__version__
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf_dir = "/org/virt-manager/%s/" % self.appname
|
2013-10-03 02:53:41 +08:00
|
|
|
self.ui_dir = os.path.join(cliconfig.asset_dir, "ui")
|
2012-10-29 06:49:48 +08:00
|
|
|
self.test_first_run = bool(test_first_run)
|
2011-07-14 06:48:02 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf = SettingsWrapper("org.virt-manager.virt-manager")
|
2010-12-14 00:22:01 +08:00
|
|
|
|
2006-08-22 05:45:24 +08:00
|
|
|
# We don't create it straight away, since we don't want
|
2006-07-20 02:33:23 +08:00
|
|
|
# to block the app pending user authorizaation to access
|
|
|
|
# the keyring
|
|
|
|
self.keyring = None
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2013-10-03 02:53:41 +08:00
|
|
|
self.default_qemu_user = cliconfig.default_qemu_user
|
|
|
|
self.rhel6_defaults = not cliconfig.rhel_enable_unsupported_opts
|
|
|
|
self.preferred_distros = cliconfig.preferred_distros
|
|
|
|
self.hv_packages = cliconfig.hv_packages
|
|
|
|
self.libvirt_packages = cliconfig.libvirt_packages
|
|
|
|
self.askpass_package = cliconfig.askpass_package
|
|
|
|
self.default_graphics_from_config = cliconfig.default_graphics
|
2013-10-03 03:17:15 +08:00
|
|
|
self.default_storage_format_from_config = "qcow2"
|
2010-12-14 03:31:27 +08:00
|
|
|
|
2011-04-12 00:54:47 +08:00
|
|
|
self._objects = []
|
|
|
|
|
2013-07-07 03:39:00 +08:00
|
|
|
self.support_inspection = self.check_inspection()
|
2011-07-19 02:53:54 +08:00
|
|
|
|
2011-04-19 01:01:22 +08:00
|
|
|
self._spice_error = None
|
2011-04-15 03:43:31 +08:00
|
|
|
|
2013-10-03 02:53:41 +08:00
|
|
|
global running_config
|
|
|
|
running_config = self
|
|
|
|
|
2012-05-14 21:24:56 +08:00
|
|
|
|
2013-07-07 03:39:00 +08:00
|
|
|
def check_inspection(self):
|
2011-07-19 02:53:54 +08:00
|
|
|
try:
|
|
|
|
# Check we can open the Python guestfs module.
|
2013-04-14 02:34:52 +08:00
|
|
|
from guestfs import GuestFS # pylint: disable=F0401
|
2013-12-19 05:34:10 +08:00
|
|
|
GuestFS(close_on_exit=False)
|
2013-06-14 04:00:33 +08:00
|
|
|
return True
|
2011-07-19 02:53:54 +08:00
|
|
|
except:
|
2013-06-14 04:00:33 +08:00
|
|
|
return False
|
2006-06-15 05:09:08 +08:00
|
|
|
|
2013-01-14 03:41:25 +08:00
|
|
|
# General app wide helpers (gconf agnostic)
|
2009-07-21 03:09:32 +08:00
|
|
|
|
2006-06-14 22:59:40 +08:00
|
|
|
def get_appname(self):
|
|
|
|
return self.appname
|
2006-08-05 03:46:06 +08:00
|
|
|
def get_appversion(self):
|
|
|
|
return self.appversion
|
2012-02-02 06:26:46 +08:00
|
|
|
def get_ui_dir(self):
|
|
|
|
return self.ui_dir
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2011-01-08 03:59:31 +08:00
|
|
|
def embeddable_graphics(self):
|
2012-05-14 21:24:56 +08:00
|
|
|
ret = ["vnc", "spice"]
|
2011-01-08 03:59:31 +08:00
|
|
|
return ret
|
|
|
|
|
2011-04-11 23:00:57 +08:00
|
|
|
def remove_notifier(self, h):
|
|
|
|
self.conf.notify_remove(h)
|
|
|
|
|
2011-04-12 00:54:47 +08:00
|
|
|
# Used for debugging reference leaks, we keep track of all objects
|
|
|
|
# come and go so we can do a leak report at app shutdown
|
|
|
|
def add_object(self, obj):
|
|
|
|
self._objects.append(obj)
|
|
|
|
def remove_object(self, obj):
|
|
|
|
self._objects.remove(obj)
|
|
|
|
def get_objects(self):
|
|
|
|
return self._objects[:]
|
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
def _make_pervm_key(self, uuid, key):
|
|
|
|
return "/vms/%s%s" % (uuid.replace("-", ""), key)
|
2009-05-12 00:37:47 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
def listen_pervm(self, uuid, key, *args, **kwargs):
|
|
|
|
key = self._make_pervm_key(uuid, key)
|
|
|
|
self.conf.make_vm_settings(key)
|
|
|
|
return self.conf.notify_add(key, *args, **kwargs)
|
2009-05-12 00:37:47 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
def set_pervm(self, uuid, key, *args, **kwargs):
|
|
|
|
key = self._make_pervm_key(uuid, key)
|
|
|
|
self.conf.make_vm_settings(key)
|
|
|
|
ret = self.conf.set(key, *args, **kwargs)
|
2009-05-12 00:37:47 +08:00
|
|
|
return ret
|
2013-04-18 05:39:25 +08:00
|
|
|
|
|
|
|
def get_pervm(self, uuid, key):
|
|
|
|
key = self._make_pervm_key(uuid, key)
|
|
|
|
self.conf.make_vm_settings(key)
|
|
|
|
return self.conf.get(key)
|
|
|
|
|
|
|
|
|
|
|
|
###################
|
|
|
|
# General helpers #
|
|
|
|
###################
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
# Manager stats view preferences
|
2011-07-12 20:49:47 +08:00
|
|
|
def is_vmlist_guest_cpu_usage_visible(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/vmlist-fields/cpu-usage")
|
2011-07-12 20:49:47 +08:00
|
|
|
def is_vmlist_host_cpu_usage_visible(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/vmlist-fields/host-cpu-usage")
|
2013-12-18 21:42:42 +08:00
|
|
|
def is_vmlist_memory_usage_visible(self):
|
|
|
|
return self.conf.get("/vmlist-fields/memory-usage")
|
2009-11-12 00:02:57 +08:00
|
|
|
def is_vmlist_disk_io_visible(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/vmlist-fields/disk-usage")
|
2009-11-12 00:02:57 +08:00
|
|
|
def is_vmlist_network_traffic_visible(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/vmlist-fields/network-traffic")
|
2009-11-12 00:02:57 +08:00
|
|
|
|
2011-07-12 20:49:47 +08:00
|
|
|
def set_vmlist_guest_cpu_usage_visible(self, state):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/vmlist-fields/cpu-usage", state)
|
2011-07-12 20:49:47 +08:00
|
|
|
def set_vmlist_host_cpu_usage_visible(self, state):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/vmlist-fields/host-cpu-usage", state)
|
2013-12-18 21:42:42 +08:00
|
|
|
def set_vmlist_memory_usage_visible(self, state):
|
|
|
|
self.conf.set("/vmlist-fields/memory-usage", state)
|
2009-11-12 00:02:57 +08:00
|
|
|
def set_vmlist_disk_io_visible(self, state):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/vmlist-fields/disk-usage", state)
|
2009-11-12 00:02:57 +08:00
|
|
|
def set_vmlist_network_traffic_visible(self, state):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/vmlist-fields/network-traffic", state)
|
|
|
|
|
|
|
|
def on_vmlist_guest_cpu_usage_visible_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/vmlist-fields/cpu-usage", cb)
|
|
|
|
def on_vmlist_host_cpu_usage_visible_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/vmlist-fields/host-cpu-usage", cb)
|
2013-12-18 21:42:42 +08:00
|
|
|
def on_vmlist_memory_usage_visible_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/vmlist-fields/memory-usage", cb)
|
2013-04-18 05:39:25 +08:00
|
|
|
def on_vmlist_disk_io_visible_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/vmlist-fields/disk-usage", cb)
|
|
|
|
def on_vmlist_network_traffic_visible_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/vmlist-fields/network-traffic", cb)
|
2009-06-24 07:30:12 +08:00
|
|
|
|
2010-08-23 23:50:36 +08:00
|
|
|
# Keys preferences
|
2012-01-30 10:51:20 +08:00
|
|
|
def get_keys_combination(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
ret = self.conf.get("/console/grab-keys")
|
2012-01-30 10:51:20 +08:00
|
|
|
if not ret:
|
|
|
|
# Left Control + Left Alt
|
|
|
|
return "65507,65513"
|
|
|
|
return ret
|
2010-08-23 23:50:36 +08:00
|
|
|
def set_keys_combination(self, val):
|
|
|
|
# Val have to be a list of integers
|
2013-04-12 04:32:00 +08:00
|
|
|
val = ','.join([str(v) for v in val])
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/console/grab-keys", val)
|
|
|
|
def on_keys_combination_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/console/grab-keys", cb)
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2009-11-19 05:11:17 +08:00
|
|
|
# Confirmation preferences
|
|
|
|
def get_confirm_forcepoweroff(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/forcepoweroff")
|
2009-11-19 05:11:17 +08:00
|
|
|
def get_confirm_poweroff(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/poweroff")
|
2009-11-19 05:11:17 +08:00
|
|
|
def get_confirm_pause(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/pause")
|
2009-11-19 05:46:36 +08:00
|
|
|
def get_confirm_removedev(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/removedev")
|
2010-02-09 11:34:23 +08:00
|
|
|
def get_confirm_interface(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/interface-power")
|
2011-07-20 08:29:07 +08:00
|
|
|
def get_confirm_unapplied(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/unapplied-dev")
|
2012-12-04 00:12:59 +08:00
|
|
|
def get_confirm_delstorage(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/confirm/delete-storage")
|
2010-02-09 11:34:23 +08:00
|
|
|
|
2009-11-19 05:11:17 +08:00
|
|
|
|
|
|
|
def set_confirm_forcepoweroff(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/forcepoweroff", val)
|
2009-11-19 05:11:17 +08:00
|
|
|
def set_confirm_poweroff(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/poweroff", val)
|
2009-11-19 05:11:17 +08:00
|
|
|
def set_confirm_pause(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/pause", val)
|
2009-11-19 05:46:36 +08:00
|
|
|
def set_confirm_removedev(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/removedev", val)
|
2010-02-09 11:34:23 +08:00
|
|
|
def set_confirm_interface(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/interface-power", val)
|
2011-07-20 08:29:07 +08:00
|
|
|
def set_confirm_unapplied(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/unapplied-dev", val)
|
2012-12-04 00:12:59 +08:00
|
|
|
def set_confirm_delstorage(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/confirm/delete-storage", val)
|
2009-11-19 05:11:17 +08:00
|
|
|
|
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
# System tray visibility
|
2013-04-18 05:39:25 +08:00
|
|
|
def on_view_system_tray_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/system-tray", cb)
|
2009-07-28 10:30:01 +08:00
|
|
|
def get_view_system_tray(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/system-tray")
|
2009-07-28 10:30:01 +08:00
|
|
|
def set_view_system_tray(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/system-tray", val)
|
2009-07-28 10:30:01 +08:00
|
|
|
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
# Stats history and interval length
|
2013-04-24 01:18:21 +08:00
|
|
|
def get_stats_history_length(self):
|
|
|
|
return 120
|
2006-06-14 22:59:40 +08:00
|
|
|
def get_stats_update_interval(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
interval = self.conf.get("/stats/update-interval")
|
2006-06-14 22:59:40 +08:00
|
|
|
if interval < 1:
|
|
|
|
return 1
|
|
|
|
return interval
|
|
|
|
def set_stats_update_interval(self, interval):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/stats/update-interval", interval)
|
|
|
|
def on_stats_update_interval_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/stats/update-interval", cb)
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2008-12-18 04:27:06 +08:00
|
|
|
|
|
|
|
# Disable/Enable different stats polling
|
|
|
|
def get_stats_enable_disk_poll(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/stats/enable-disk-poll")
|
2008-12-18 04:27:06 +08:00
|
|
|
def get_stats_enable_net_poll(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/stats/enable-net-poll")
|
2014-01-13 06:39:21 +08:00
|
|
|
def get_stats_enable_memory_poll(self):
|
|
|
|
return self.conf.get("/stats/enable-memory-poll")
|
2008-12-18 04:27:06 +08:00
|
|
|
|
|
|
|
def set_stats_enable_disk_poll(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/stats/enable-disk-poll", val)
|
2008-12-18 04:27:06 +08:00
|
|
|
def set_stats_enable_net_poll(self, val):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/stats/enable-net-poll", val)
|
2014-01-13 06:39:21 +08:00
|
|
|
def set_stats_enable_memory_poll(self, val):
|
|
|
|
self.conf.set("/stats/enable-memory-poll", val)
|
2008-12-18 04:27:06 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
def on_stats_enable_disk_poll_changed(self, cb, row=None):
|
|
|
|
return self.conf.notify_add("/stats/enable-disk-poll", cb, row)
|
|
|
|
def on_stats_enable_net_poll_changed(self, cb, row=None):
|
|
|
|
return self.conf.notify_add("/stats/enable-net-poll", cb, row)
|
2014-01-13 06:39:21 +08:00
|
|
|
def on_stats_enable_memory_poll_changed(self, cb, row=None):
|
|
|
|
return self.conf.notify_add("/stats/enable-memory-poll", cb, row)
|
2008-12-18 04:27:06 +08:00
|
|
|
|
|
|
|
# VM Console preferences
|
2013-04-18 05:39:25 +08:00
|
|
|
def on_console_accels_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/console/enable-accels", cb)
|
2010-12-03 02:41:22 +08:00
|
|
|
def get_console_accels(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
console_pref = self.conf.get("/console/enable-accels")
|
2012-11-08 21:15:02 +08:00
|
|
|
if console_pref is None:
|
2010-12-03 02:41:22 +08:00
|
|
|
console_pref = False
|
2006-11-01 03:29:22 +08:00
|
|
|
return console_pref
|
2010-12-03 02:41:22 +08:00
|
|
|
def set_console_accels(self, pref):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/console/enable-accels", pref)
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
def on_console_scaling_changed(self, cb):
|
|
|
|
return self.conf.notify_add("/console/scaling", cb)
|
2009-02-24 07:50:47 +08:00
|
|
|
def get_console_scaling(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/console/scaling")
|
2009-02-24 07:50:47 +08:00
|
|
|
def set_console_scaling(self, pref):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/console/scaling", pref)
|
2009-02-24 07:50:47 +08:00
|
|
|
|
2013-07-02 02:32:21 +08:00
|
|
|
def get_auto_redirection(self):
|
|
|
|
return self.conf.get("/console/auto-redirect")
|
|
|
|
def set_auto_redirection(self, state):
|
|
|
|
self.conf.set("/console/auto-redirect", state)
|
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
# Show VM details toolbar
|
2008-09-06 04:34:14 +08:00
|
|
|
def get_details_show_toolbar(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
res = self.conf.get("/details/show-toolbar")
|
2012-11-08 21:15:02 +08:00
|
|
|
if res is None:
|
2008-09-08 06:43:33 +08:00
|
|
|
res = True
|
|
|
|
return res
|
2008-09-06 04:34:14 +08:00
|
|
|
def set_details_show_toolbar(self, state):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/details/show-toolbar", state)
|
2008-09-06 04:34:14 +08:00
|
|
|
|
2009-11-29 09:07:01 +08:00
|
|
|
# VM details default size
|
|
|
|
def get_details_window_size(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
w = self.conf.get("/details/window_width")
|
|
|
|
h = self.conf.get("/details/window_height")
|
2009-11-29 09:07:01 +08:00
|
|
|
return (w, h)
|
|
|
|
def set_details_window_size(self, w, h):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/details/window_width", w)
|
|
|
|
self.conf.set("/details/window_height", h)
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
# Create sound device for default guest
|
2013-04-24 02:02:46 +08:00
|
|
|
def get_new_vm_sound(self):
|
|
|
|
return self.conf.get("/new-vm/add-sound")
|
|
|
|
def set_new_vm_sound(self, state):
|
|
|
|
self.conf.set("/new-vm/add-sound", state)
|
2009-02-13 02:32:55 +08:00
|
|
|
|
2013-10-03 02:47:21 +08:00
|
|
|
def get_graphics_type(self, raw=False):
|
2013-04-18 05:39:25 +08:00
|
|
|
ret = self.conf.get("/new-vm/graphics-type")
|
2013-10-03 02:47:21 +08:00
|
|
|
if ret not in ["system", "vnc", "spice"]:
|
|
|
|
ret = "system"
|
|
|
|
if ret == "system" and not raw:
|
2013-03-17 09:32:29 +08:00
|
|
|
return self.default_graphics_from_config
|
2011-03-24 23:37:26 +08:00
|
|
|
return ret
|
2011-03-18 20:59:14 +08:00
|
|
|
def set_graphics_type(self, gtype):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/new-vm/graphics-type", gtype.lower())
|
2011-03-18 20:59:14 +08:00
|
|
|
|
2013-10-03 03:17:15 +08:00
|
|
|
def get_default_storage_format(self, raw=False):
|
2013-04-18 05:39:25 +08:00
|
|
|
ret = self.conf.get("/new-vm/storage-format")
|
2012-02-14 03:49:00 +08:00
|
|
|
if ret not in ["default", "raw", "qcow2"]:
|
2013-10-03 02:47:21 +08:00
|
|
|
ret = "default"
|
|
|
|
if ret == "default" and not raw:
|
|
|
|
return self.default_storage_format_from_config
|
2012-02-14 03:49:00 +08:00
|
|
|
return ret
|
|
|
|
def set_storage_format(self, typ):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/new-vm/storage-format", typ.lower())
|
2012-02-14 03:49:00 +08:00
|
|
|
|
2006-10-11 21:07:45 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
# URL/Media path history
|
2009-05-11 23:00:03 +08:00
|
|
|
def _url_add_helper(self, gconf_path, url):
|
2013-04-24 00:42:22 +08:00
|
|
|
maxlength = 10
|
2013-04-18 05:39:25 +08:00
|
|
|
urls = self.conf.get(gconf_path)
|
2012-11-08 21:15:02 +08:00
|
|
|
if urls is None:
|
2006-10-11 21:07:45 +08:00
|
|
|
urls = []
|
2009-05-11 23:00:03 +08:00
|
|
|
|
|
|
|
if urls.count(url) == 0 and len(url) > 0 and not url.isspace():
|
|
|
|
# The url isn't already in the list, so add it
|
2010-11-30 03:06:43 +08:00
|
|
|
urls.insert(0, url)
|
2013-04-24 00:42:22 +08:00
|
|
|
if len(urls) > maxlength:
|
2010-12-11 00:47:07 +08:00
|
|
|
del urls[len(urls) - 1]
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set(gconf_path, urls)
|
2009-05-11 23:00:03 +08:00
|
|
|
|
|
|
|
def add_media_url(self, url):
|
2013-04-24 00:27:49 +08:00
|
|
|
self._url_add_helper("/urls/urls", url)
|
2006-10-11 21:07:45 +08:00
|
|
|
def add_kickstart_url(self, url):
|
2013-04-24 00:27:49 +08:00
|
|
|
self._url_add_helper("/urls/kickstarts", url)
|
2009-05-11 23:00:03 +08:00
|
|
|
def add_iso_path(self, path):
|
2013-04-18 05:39:25 +08:00
|
|
|
self._url_add_helper("/urls/isos", path)
|
2006-10-11 21:07:45 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
def get_media_urls(self):
|
2013-04-24 00:27:49 +08:00
|
|
|
return self.conf.get("/urls/urls")
|
2009-11-19 04:16:57 +08:00
|
|
|
def get_kickstart_urls(self):
|
2013-04-24 00:27:49 +08:00
|
|
|
return self.conf.get("/urls/kickstarts")
|
2009-11-19 04:16:57 +08:00
|
|
|
def get_iso_paths(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/urls/isos")
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
|
2009-12-02 01:23:19 +08:00
|
|
|
# Whether to ask about fixing path permissions
|
|
|
|
def add_perms_fix_ignore(self, pathlist):
|
|
|
|
current_list = self.get_perms_fix_ignore() or []
|
|
|
|
for path in pathlist:
|
|
|
|
if path in current_list:
|
|
|
|
continue
|
|
|
|
current_list.append(path)
|
2013-05-10 08:07:29 +08:00
|
|
|
self.conf.set("/paths/perms-fix-ignore", current_list)
|
2009-12-02 01:23:19 +08:00
|
|
|
def get_perms_fix_ignore(self):
|
2013-05-10 08:07:29 +08:00
|
|
|
return self.conf.get("/paths/perms-fix-ignore")
|
2009-12-02 01:23:19 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
# Manager view connection list
|
2011-07-23 04:43:26 +08:00
|
|
|
def add_conn(self, uri):
|
2012-10-29 06:49:48 +08:00
|
|
|
if self.test_first_run:
|
|
|
|
return
|
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
uris = self.conf.get("/connections/uris")
|
2012-11-08 21:15:02 +08:00
|
|
|
if uris is None:
|
2007-08-29 05:57:25 +08:00
|
|
|
uris = []
|
2008-03-24 23:39:19 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
if uris.count(uri) == 0:
|
|
|
|
uris.insert(len(uris) - 1, uri)
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/connections/uris", uris)
|
2011-07-23 04:43:26 +08:00
|
|
|
def remove_conn(self, uri):
|
2013-04-18 05:39:25 +08:00
|
|
|
uris = self.conf.get("/connections/uris")
|
2012-05-14 21:24:56 +08:00
|
|
|
|
2012-11-08 21:15:02 +08:00
|
|
|
if uris is None:
|
2007-08-29 05:57:25 +08:00
|
|
|
return
|
2009-11-19 04:16:57 +08:00
|
|
|
|
2007-08-29 05:57:25 +08:00
|
|
|
if uris.count(uri) != 0:
|
|
|
|
uris.remove(uri)
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/connections/uris", uris)
|
2009-11-19 04:16:57 +08:00
|
|
|
|
2008-03-24 23:39:19 +08:00
|
|
|
if self.get_conn_autoconnect(uri):
|
2013-04-18 05:39:25 +08:00
|
|
|
uris = self.conf.get("/connections/autoconnect")
|
2008-03-24 23:39:19 +08:00
|
|
|
uris.remove(uri)
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/connections/autoconnect", uris)
|
2008-03-24 23:39:19 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def get_conn_uris(self):
|
2012-10-29 06:49:48 +08:00
|
|
|
if self.test_first_run:
|
|
|
|
return []
|
2013-04-18 05:39:25 +08:00
|
|
|
return self.conf.get("/connections/uris")
|
2008-03-24 23:39:19 +08:00
|
|
|
|
2009-11-29 10:00:46 +08:00
|
|
|
# Manager default window size
|
|
|
|
def get_manager_window_size(self):
|
2013-04-18 05:39:25 +08:00
|
|
|
w = self.conf.get("/manager-window-width")
|
|
|
|
h = self.conf.get("/manager-window-height")
|
2009-11-29 10:00:46 +08:00
|
|
|
return (w, h)
|
|
|
|
def set_manager_window_size(self, w, h):
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/manager-window-width", w)
|
|
|
|
self.conf.set("/manager-window-height", h)
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
# URI autoconnect
|
2008-03-24 23:39:19 +08:00
|
|
|
def get_conn_autoconnect(self, uri):
|
2013-04-18 05:39:25 +08:00
|
|
|
uris = self.conf.get("/connections/autoconnect")
|
2008-03-24 23:39:19 +08:00
|
|
|
return ((uris is not None) and (uri in uris))
|
|
|
|
|
2009-11-26 03:16:31 +08:00
|
|
|
def set_conn_autoconnect(self, uri, val):
|
2012-10-29 06:49:48 +08:00
|
|
|
if self.test_first_run:
|
|
|
|
return
|
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
uris = self.conf.get("/connections/autoconnect")
|
2008-03-24 23:39:19 +08:00
|
|
|
if uris is None:
|
|
|
|
uris = []
|
2009-11-26 03:16:31 +08:00
|
|
|
if not val and uri in uris:
|
2008-03-24 23:39:19 +08:00
|
|
|
uris.remove(uri)
|
2009-11-26 03:16:31 +08:00
|
|
|
elif val and uri not in uris:
|
2008-03-24 23:39:19 +08:00
|
|
|
uris.append(uri)
|
2009-11-26 03:16:31 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
self.conf.set("/connections/autoconnect", uris)
|
2007-08-29 05:57:25 +08:00
|
|
|
|
2009-05-11 23:00:03 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
# Default directory location dealings
|
2013-04-24 02:16:54 +08:00
|
|
|
def _get_default_dir_key(self, _type):
|
|
|
|
if (_type in [self.CONFIG_DIR_ISO_MEDIA,
|
|
|
|
self.CONFIG_DIR_FLOPPY_MEDIA]):
|
2011-07-23 07:12:48 +08:00
|
|
|
return "media"
|
2013-04-24 02:16:54 +08:00
|
|
|
if (_type in [self.CONFIG_DIR_IMAGE,
|
|
|
|
self.CONFIG_DIR_SCREENSHOT]):
|
|
|
|
return _type
|
|
|
|
return None
|
2011-07-23 07:12:48 +08:00
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
def get_default_directory(self, conn, _type):
|
2011-07-23 07:12:48 +08:00
|
|
|
key = self._get_default_dir_key(_type)
|
2013-04-24 02:16:54 +08:00
|
|
|
path = None
|
|
|
|
|
|
|
|
if key:
|
|
|
|
path = self.conf.get("/paths/%s-default" % key)
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
if not path:
|
|
|
|
if (_type == self.CONFIG_DIR_IMAGE or
|
2011-07-23 07:12:48 +08:00
|
|
|
_type == self.CONFIG_DIR_ISO_MEDIA or
|
|
|
|
_type == self.CONFIG_DIR_FLOPPY_MEDIA):
|
2009-11-19 04:16:57 +08:00
|
|
|
path = self.get_default_image_dir(conn)
|
|
|
|
if (_type == self.CONFIG_DIR_SAVE or
|
|
|
|
_type == self.CONFIG_DIR_RESTORE):
|
|
|
|
path = self.get_default_save_dir(conn)
|
|
|
|
|
2013-04-24 02:16:54 +08:00
|
|
|
logging.debug("directory for type=%s returning=%s", _type, path)
|
2009-11-19 04:16:57 +08:00
|
|
|
return path
|
|
|
|
|
|
|
|
def set_default_directory(self, folder, _type):
|
2013-04-24 02:16:54 +08:00
|
|
|
key = self._get_default_dir_key(_type)
|
|
|
|
if not key:
|
2009-11-19 04:16:57 +08:00
|
|
|
return
|
|
|
|
|
2013-04-24 02:16:54 +08:00
|
|
|
logging.debug("saving directory for type=%s to %s", key, folder)
|
|
|
|
self.conf.set("/paths/%s-default" % key, folder)
|
2007-04-12 23:46:51 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def get_default_image_dir(self, conn):
|
|
|
|
if conn.is_xen():
|
2011-04-19 01:14:14 +08:00
|
|
|
return self.DEFAULT_XEN_IMAGE_DIR
|
2008-09-05 21:42:25 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
if (conn.is_qemu_session() or
|
2011-04-19 01:14:14 +08:00
|
|
|
not os.access(self.DEFAULT_VIRT_IMAGE_DIR, os.W_OK)):
|
2008-10-11 00:06:41 +08:00
|
|
|
return os.getcwd()
|
2009-04-23 03:44:07 +08:00
|
|
|
|
2008-09-05 21:42:25 +08:00
|
|
|
# Just return the default dir since the intention is that it
|
|
|
|
# is a managed pool and the user will be able to install to it.
|
2011-04-19 01:14:14 +08:00
|
|
|
return self.DEFAULT_VIRT_IMAGE_DIR
|
2007-04-12 23:46:51 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def get_default_save_dir(self, conn):
|
|
|
|
if conn.is_xen():
|
2011-04-19 01:14:14 +08:00
|
|
|
return self.DEFAULT_XEN_SAVE_DIR
|
|
|
|
elif os.access(self.DEFAULT_VIRT_SAVE_DIR, os.W_OK):
|
|
|
|
return self.DEFAULT_VIRT_SAVE_DIR
|
2007-04-12 23:46:51 +08:00
|
|
|
else:
|
|
|
|
return os.getcwd()
|
|
|
|
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
# Keyring / VNC password dealings
|
|
|
|
def get_secret_name(self, vm):
|
|
|
|
return "vm-console-" + vm.get_uuid()
|
|
|
|
|
|
|
|
def has_keyring(self):
|
2012-11-08 21:15:02 +08:00
|
|
|
if self.keyring is None:
|
2009-11-19 04:16:57 +08:00
|
|
|
self.keyring = vmmKeyring()
|
|
|
|
return self.keyring.is_available()
|
|
|
|
|
2012-11-09 23:08:15 +08:00
|
|
|
def get_console_password(self, vm):
|
2013-04-18 05:39:25 +08:00
|
|
|
if not self.has_keyring():
|
|
|
|
return ("", "")
|
|
|
|
|
|
|
|
username, keyid = vm.get_console_password()
|
2012-11-09 23:08:15 +08:00
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
if keyid == -1:
|
2012-11-09 23:08:15 +08:00
|
|
|
return ("", "")
|
2009-11-19 04:16:57 +08:00
|
|
|
|
2012-11-09 23:08:15 +08:00
|
|
|
secret = self.keyring.get_secret(keyid)
|
|
|
|
if secret is None or secret.get_name() != self.get_secret_name(vm):
|
|
|
|
return ("", "")
|
2009-11-19 04:16:57 +08:00
|
|
|
|
2012-11-09 23:08:15 +08:00
|
|
|
if (secret.attributes.get("hvuri", None) != vm.conn.get_uri() or
|
|
|
|
secret.attributes.get("uuid", None) != vm.get_uuid()):
|
|
|
|
return ("", "")
|
|
|
|
|
|
|
|
return (secret.get_secret(), username or "")
|
2009-11-19 04:16:57 +08:00
|
|
|
|
|
|
|
def set_console_password(self, vm, password, username=""):
|
2012-11-09 23:08:15 +08:00
|
|
|
if not self.has_keyring():
|
2009-11-19 04:16:57 +08:00
|
|
|
return
|
|
|
|
|
2010-12-11 00:47:07 +08:00
|
|
|
secret = vmmSecret(self.get_secret_name(vm), password,
|
|
|
|
{"uuid" : vm.get_uuid(),
|
2011-07-23 04:43:26 +08:00
|
|
|
"hvuri": vm.conn.get_uri()})
|
2012-11-09 23:08:15 +08:00
|
|
|
keyid = self.keyring.add_secret(secret)
|
|
|
|
if keyid is None:
|
|
|
|
return
|
|
|
|
|
2013-04-18 05:39:25 +08:00
|
|
|
vm.set_console_password(username, keyid)
|