mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
virtManager: Drop util, combine it with virtinst.util and uihelpers
This commit is contained in:
parent
952708f509
commit
7c55cfeb39
@ -32,7 +32,7 @@ from gi.repository import GObject
|
||||
from gi.repository import LibvirtGLib
|
||||
# pylint: enable=E0611
|
||||
|
||||
from virtinst import util as virtinstutil
|
||||
from virtinst import util as util
|
||||
from virtinst import cli as virtinstcli
|
||||
from virtcli import cliutils, cliconfig
|
||||
|
||||
@ -213,7 +213,6 @@ def main():
|
||||
leftovers = sys.argv[1:]
|
||||
|
||||
import virtManager.config
|
||||
import virtManager.util
|
||||
except:
|
||||
# Don't just let the exception raise here. abrt reports bugs
|
||||
# when users mess up su/sudo and DISPLAY isn't set. Printing
|
||||
@ -236,13 +235,13 @@ def main():
|
||||
os.path.join(cliconfig.asset_dir, "ui"),
|
||||
options.testfirstrun)
|
||||
|
||||
if not virtinstutil.local_libvirt_version() >= 6000:
|
||||
if not util.local_libvirt_version() >= 6000:
|
||||
# We need this version for threaded virConnect access
|
||||
_show_startup_error(
|
||||
_("virt-manager requires libvirt 0.6.0 or later."), "")
|
||||
return
|
||||
|
||||
virtManager.util.running_config = config
|
||||
virtManager.config.running_config = config
|
||||
config.default_qemu_user = cliconfig.default_qemu_user
|
||||
config.rhel6_defaults = not cliconfig.rhel_enable_unsupported_opts
|
||||
config.preferred_distros = cliconfig.preferred_distros
|
||||
|
@ -27,6 +27,7 @@ from gi.repository import Gdk
|
||||
# pylint: enable=E0611
|
||||
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
from virtinst import (VirtualChannelDevice, VirtualParallelDevice,
|
||||
VirtualSerialDevice,
|
||||
VirtualVideoDevice, VirtualWatchdog,
|
||||
@ -34,8 +35,7 @@ from virtinst import (VirtualChannelDevice, VirtualParallelDevice,
|
||||
VirtualRedirDevice, VirtualTPMDevice)
|
||||
from virtinst import VirtualController
|
||||
|
||||
import virtManager.util as util
|
||||
import virtManager.uihelpers as uihelpers
|
||||
from virtManager import uihelpers
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager.storagebrowse import vmmStorageBrowser
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
@ -589,7 +589,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
|
||||
if len(model) == 0:
|
||||
model.append([_("No Devices Available"), None])
|
||||
util.set_list_selection(devlist, 0)
|
||||
uihelpers.set_list_selection(devlist, 0)
|
||||
|
||||
########################
|
||||
# get_config_* methods #
|
||||
@ -612,7 +612,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
|
||||
if self.is_default_storage():
|
||||
pathlist = [d.path for d in self.vm.get_disk_devices()]
|
||||
path = util.get_default_path(self.conn,
|
||||
path = uihelpers.get_default_path(self.conn,
|
||||
self.vm.get_name(),
|
||||
collidelist=pathlist)
|
||||
logging.debug("Default storage path is: %s", path)
|
||||
@ -732,7 +732,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return usb_info
|
||||
|
||||
def get_config_host_device_info(self):
|
||||
devrow = util.get_list_selection(self.widget("host-device"))
|
||||
devrow = uihelpers.get_list_selection(self.widget("host-device"))
|
||||
if not devrow:
|
||||
return []
|
||||
return devrow
|
||||
@ -828,10 +828,10 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
################
|
||||
|
||||
def set_hw_selection(self, page):
|
||||
util.set_list_selection(self.widget("hardware-list"), page)
|
||||
uihelpers.set_list_selection(self.widget("hardware-list"), page)
|
||||
|
||||
def get_hw_selection(self):
|
||||
return util.get_list_selection(self.widget("hardware-list"))
|
||||
return uihelpers.get_list_selection(self.widget("hardware-list"))
|
||||
|
||||
def update_char_device_type_model(self):
|
||||
rhel6_blacklist = ["pipe", "udp"]
|
||||
@ -1310,8 +1310,8 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
if self.is_default_storage():
|
||||
# See if the ideal disk path (/default/pool/vmname.img)
|
||||
# exists, and if unused, prompt the use for using it
|
||||
ideal = util.get_ideal_path(self.conn,
|
||||
self.vm.get_name())
|
||||
ideal = uihelpers.get_ideal_path(self.conn,
|
||||
self.vm.get_name())
|
||||
do_exist = False
|
||||
ret = True
|
||||
|
||||
@ -1350,7 +1350,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
|
||||
if (disk.type == virtinst.VirtualDisk.TYPE_FILE and
|
||||
not self.vm.is_hvm() and
|
||||
virtinst.util.is_blktap_capable(self.conn.get_backend())):
|
||||
util.is_blktap_capable(self.conn.get_backend())):
|
||||
disk.driver_name = virtinst.VirtualDisk.DRIVER_TAP
|
||||
|
||||
disk.validate()
|
||||
|
@ -23,7 +23,7 @@ import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import virtManager
|
||||
from virtManager import config
|
||||
|
||||
# pylint: disable=E0611
|
||||
from gi.repository import Gdk
|
||||
@ -38,7 +38,7 @@ class vmmGObject(GObject.GObject):
|
||||
|
||||
def __init__(self):
|
||||
GObject.GObject.__init__(self)
|
||||
self.config = virtManager.util.running_config
|
||||
self.config = config.running_config
|
||||
|
||||
self._gobject_handles = []
|
||||
self._gobject_timeouts = []
|
||||
@ -195,7 +195,8 @@ class vmmGObjectUI(vmmGObject):
|
||||
self.builder = builder
|
||||
self.topwin = topwin
|
||||
|
||||
self.err = virtManager.error.vmmErrorDialog(self.topwin)
|
||||
from virtManager import error
|
||||
self.err = error.vmmErrorDialog(self.topwin)
|
||||
|
||||
def widget(self, name):
|
||||
return self.builder.get_object(name)
|
||||
|
@ -28,6 +28,8 @@ from gi.repository import Gtk
|
||||
|
||||
from virtManager.keyring import vmmKeyring, vmmSecret
|
||||
|
||||
running_config = None
|
||||
|
||||
|
||||
class SettingsWrapper(object):
|
||||
def __init__(self, settings_id):
|
||||
|
@ -28,7 +28,7 @@ from gi.repository import Gtk
|
||||
# pylint: enable=E0611
|
||||
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager import util
|
||||
from virtManager import uihelpers
|
||||
|
||||
HV_XEN = 0
|
||||
HV_QEMU = 1
|
||||
@ -153,7 +153,7 @@ class vmmConnect(vmmGObjectUI):
|
||||
return self.widget("connect-remote").get_active()
|
||||
|
||||
def set_default_hypervisor(self):
|
||||
default = util.default_uri(always_system=True)
|
||||
default = uihelpers.default_uri(always_system=True)
|
||||
if not default or default.startswith("qemu"):
|
||||
self.widget("hypervisor").set_active(1)
|
||||
elif default.startswith("xen"):
|
||||
|
@ -33,8 +33,9 @@ import traceback
|
||||
import libvirt
|
||||
import virtinst
|
||||
from virtinst import pollhelpers
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager import uihelpers
|
||||
from virtManager import connectauth
|
||||
from virtManager.baseclass import vmmGObject
|
||||
from virtManager.domain import vmmDomain
|
||||
@ -323,7 +324,7 @@ class vmmConnection(vmmGObject):
|
||||
return match_whole_string(orig, "[0-9.]+")
|
||||
|
||||
(scheme, username, hostname,
|
||||
path, ignore, ignore) = virtinst.util.uri_split(self.get_uri())
|
||||
path, ignore, ignore) = util.uri_split(self.get_uri())
|
||||
|
||||
hv = ""
|
||||
rest = ""
|
||||
@ -430,7 +431,7 @@ class vmmConnection(vmmGObject):
|
||||
else:
|
||||
# Try to create the default storage pool
|
||||
try:
|
||||
util.build_default_pool(self)
|
||||
uihelpers.build_default_pool(self)
|
||||
except Exception, e:
|
||||
logging.debug("Building default pool failed: %s", str(e))
|
||||
|
||||
|
@ -29,9 +29,9 @@ from gi.repository import Gdk
|
||||
# pylint: enable=E0611
|
||||
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
|
||||
import virtManager.uihelpers as uihelpers
|
||||
from virtManager import util
|
||||
from virtManager import uihelpers
|
||||
from virtManager.mediadev import MEDIA_CDROM
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
@ -622,7 +622,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
gtype = guest.os_type
|
||||
for dom in guest.domains:
|
||||
domtype = dom.hypervisor_type
|
||||
label = util.pretty_hv(gtype, domtype)
|
||||
label = uihelpers.pretty_hv(gtype, domtype)
|
||||
sensitive = True
|
||||
|
||||
# Don't add multiple rows for each arch
|
||||
@ -981,7 +981,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
if disks:
|
||||
return disks[0].path
|
||||
|
||||
return util.get_default_path(self.conn, name)
|
||||
return uihelpers.get_default_path(self.conn, name)
|
||||
|
||||
def is_default_storage(self):
|
||||
usedef = self.widget("config-storage-create").get_active()
|
||||
@ -1425,7 +1425,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
# Generate UUID (makes customize dialog happy)
|
||||
try:
|
||||
guest.uuid = virtinst.util.randomUUID(guest.conn)
|
||||
guest.uuid = util.randomUUID(guest.conn)
|
||||
except Exception, e:
|
||||
self.err.show_err(_("Error setting UUID: %s") % str(e))
|
||||
return None
|
||||
@ -1592,8 +1592,8 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
if not oldguest:
|
||||
if self.guest.installer.scratchdir_required():
|
||||
path = virtinst.util.make_scratchdir(self.guest.conn,
|
||||
self.guest.type)
|
||||
path = util.make_scratchdir(self.guest.conn,
|
||||
self.guest.type)
|
||||
elif instmethod == INSTALL_PAGE_ISO:
|
||||
path = self.guest.installer.location
|
||||
else:
|
||||
@ -1663,8 +1663,8 @@ class vmmCreate(vmmGObjectUI):
|
||||
elif self.is_default_storage() and not oldguest:
|
||||
# See if the ideal disk path (/default/pool/vmname.img)
|
||||
# exists, and if unused, prompt the use for using it
|
||||
ideal = util.get_ideal_path(self.conn,
|
||||
self.guest.name)
|
||||
ideal = uihelpers.get_ideal_path(self.conn,
|
||||
self.guest.name)
|
||||
do_exist = False
|
||||
ret = True
|
||||
|
||||
|
@ -27,7 +27,6 @@ import logging
|
||||
|
||||
from virtinst import Interface
|
||||
|
||||
from virtManager import util
|
||||
from virtManager import uihelpers
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
@ -548,8 +547,8 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
|
||||
for row in row_dict.values():
|
||||
name = row[INTERFACE_ROW_NAME]
|
||||
row[INTERFACE_ROW_IN_USE_BY] = util.iface_in_use_by(self.conn,
|
||||
name)
|
||||
row[INTERFACE_ROW_IN_USE_BY] = uihelpers.iface_in_use_by(self.conn,
|
||||
name)
|
||||
|
||||
for row in row_dict.values():
|
||||
model.append(row)
|
||||
|
@ -26,9 +26,9 @@ from gi.repository import Gdk
|
||||
import copy
|
||||
import logging
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager import uihelpers
|
||||
|
||||
from virtinst import Storage
|
||||
|
||||
@ -593,6 +593,6 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
if foldermode:
|
||||
mode = Gtk.FileChooserAction.SELECT_FOLDER
|
||||
|
||||
return util.browse_local(self.topwin, dialog_name, self.conn,
|
||||
dialog_type=mode,
|
||||
start_folder=startfolder)
|
||||
return uihelpers.browse_local(self.topwin, dialog_name, self.conn,
|
||||
dialog_type=mode,
|
||||
start_folder=startfolder)
|
||||
|
@ -29,10 +29,11 @@ import traceback
|
||||
import logging
|
||||
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager import uihelpers
|
||||
|
||||
STORAGE_ROW_CONFIRM = 0
|
||||
STORAGE_ROW_CANT_DELETE = 1
|
||||
@ -134,7 +135,7 @@ class vmmDeleteDialog(vmmGObjectUI):
|
||||
devs = self.get_paths_to_delete()
|
||||
|
||||
if devs:
|
||||
ret = util.chkbox_helper(self,
|
||||
ret = uihelpers.chkbox_helper(self,
|
||||
self.config.get_confirm_delstorage,
|
||||
self.config.set_confirm_delstorage,
|
||||
text1=_("Are you sure you want to delete "
|
||||
|
@ -29,7 +29,7 @@ from gi.repository import Gdk
|
||||
|
||||
import libvirt
|
||||
|
||||
import virtManager.uihelpers as uihelpers
|
||||
from virtManager import uihelpers
|
||||
from virtManager.storagebrowse import vmmStorageBrowser
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.addhardware import vmmAddHardware
|
||||
@ -37,9 +37,9 @@ from virtManager.choosecd import vmmChooseCD
|
||||
from virtManager.console import vmmConsolePages
|
||||
from virtManager.serialcon import vmmSerialConsole
|
||||
from virtManager.graphwidgets import Sparkline
|
||||
from virtManager import util as util
|
||||
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
|
||||
|
||||
# Parameters that can be editted in the details window
|
||||
@ -1262,7 +1262,7 @@ class vmmDetails(vmmGObjectUI):
|
||||
if not self.widget("config-apply").get_sensitive():
|
||||
return False
|
||||
|
||||
if not util.chkbox_helper(self,
|
||||
if not uihelpers.chkbox_helper(self,
|
||||
self.config.get_confirm_unapplied,
|
||||
self.config.set_confirm_unapplied,
|
||||
text1=(_("There are unapplied changes. Would you like to apply "
|
||||
@ -1653,7 +1653,7 @@ class vmmDetails(vmmGObjectUI):
|
||||
now = str(datetime.datetime.now()).split(".")[0].replace(" ", "_")
|
||||
default = "Screenshot_%s_%s.png" % (self.vm.get_name(), now)
|
||||
|
||||
path = util.browse_local(
|
||||
path = uihelpers.browse_local(
|
||||
self.topwin,
|
||||
_("Save Virtual Machine Screenshot"),
|
||||
self.vm.conn,
|
||||
@ -2522,7 +2522,7 @@ class vmmDetails(vmmGObjectUI):
|
||||
def remove_device(self, dev_type, dev_id_info):
|
||||
logging.debug("Removing device: %s %s", dev_type, dev_id_info)
|
||||
|
||||
if not util.chkbox_helper(self, self.config.get_confirm_removedev,
|
||||
if not uihelpers.chkbox_helper(self, self.config.get_confirm_removedev,
|
||||
self.config.set_confirm_removedev,
|
||||
text1=(_("Are you sure you want to remove this device?"))):
|
||||
return
|
||||
@ -2566,10 +2566,10 @@ class vmmDetails(vmmGObjectUI):
|
||||
Arguments can be a single arg or a list or appropriate arg type (e.g.
|
||||
a list of functions for define_funcs)
|
||||
"""
|
||||
define_funcs = virtinst.util.listify(define_funcs)
|
||||
define_funcs_args = virtinst.util.listify(define_funcs_args)
|
||||
hotplug_funcs = virtinst.util.listify(hotplug_funcs)
|
||||
hotplug_funcs_args = virtinst.util.listify(hotplug_funcs_args)
|
||||
define_funcs = util.listify(define_funcs)
|
||||
define_funcs_args = util.listify(define_funcs_args)
|
||||
hotplug_funcs = util.listify(hotplug_funcs)
|
||||
hotplug_funcs_args = util.listify(hotplug_funcs_args)
|
||||
|
||||
hotplug_err = []
|
||||
active = self.vm.is_active()
|
||||
|
@ -28,8 +28,9 @@ import threading
|
||||
|
||||
import libvirt
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager import uihelpers
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
|
||||
|
||||
@ -206,7 +207,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
try:
|
||||
self._backend.vcpus()
|
||||
except libvirt.libvirtError, err:
|
||||
if virtinst.util.is_error_nosupport(err):
|
||||
if util.is_error_nosupport(err):
|
||||
self._getvcpus_supported = False
|
||||
return self._getvcpus_supported
|
||||
getvcpus_supported = property(_get_getvcpus_supported)
|
||||
@ -959,7 +960,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
def get_hv_type(self):
|
||||
return self._get_guest().type
|
||||
def get_pretty_hv_type(self):
|
||||
return util.pretty_hv(self.get_abi_type(), self.get_hv_type())
|
||||
return uihelpers.pretty_hv(self.get_abi_type(), self.get_hv_type())
|
||||
def get_arch(self):
|
||||
return self._get_guest().os.arch
|
||||
def get_init(self):
|
||||
@ -1646,7 +1647,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
rx += io[0]
|
||||
tx += io[4]
|
||||
except libvirt.libvirtError, err:
|
||||
if virtinst.util.is_error_nosupport(err):
|
||||
if util.is_error_nosupport(err):
|
||||
logging.debug("Net stats not supported: %s", err)
|
||||
self._stats_net_supported = False
|
||||
else:
|
||||
@ -1683,7 +1684,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
rd += io[1]
|
||||
wr += io[3]
|
||||
except libvirt.libvirtError, err:
|
||||
if virtinst.util.is_error_nosupport(err):
|
||||
if util.is_error_nosupport(err):
|
||||
logging.debug("Disk stats not supported: %s", err)
|
||||
self._stats_disk_supported = False
|
||||
else:
|
||||
|
@ -30,10 +30,10 @@ import Queue
|
||||
import threading
|
||||
|
||||
import libvirt
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import packageutils
|
||||
from virtManager import util
|
||||
from virtManager import uihelpers
|
||||
from virtManager.about import vmmAbout
|
||||
from virtManager.baseclass import vmmGObject
|
||||
from virtManager.clone import vmmCloneVM
|
||||
@ -196,7 +196,7 @@ class vmmEngine(vmmGObject):
|
||||
if ret is not None:
|
||||
tryuri = "qemu:///system"
|
||||
else:
|
||||
tryuri = util.default_uri(always_system=True)
|
||||
tryuri = uihelpers.default_uri(always_system=True)
|
||||
|
||||
if tryuri is None:
|
||||
manager.set_startup_error(msg)
|
||||
@ -888,14 +888,14 @@ class vmmEngine(vmmGObject):
|
||||
"libvirt version or hypervisor."))
|
||||
return
|
||||
|
||||
if not util.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
if not uihelpers.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
self.config.set_confirm_poweroff,
|
||||
text1=_("Are you sure you want to save '%s'?" % vm.get_name())):
|
||||
return
|
||||
|
||||
path = None
|
||||
if not managed:
|
||||
path = util.browse_local(src.topwin,
|
||||
path = uihelpers.browse_local(src.topwin,
|
||||
_("Save Virtual Machine"),
|
||||
conn,
|
||||
dialog_type=Gtk.FileChooserAction.SAVE,
|
||||
@ -942,7 +942,7 @@ class vmmEngine(vmmGObject):
|
||||
"connections is not yet supported"))
|
||||
return
|
||||
|
||||
path = util.browse_local(src.topwin,
|
||||
path = uihelpers.browse_local(src.topwin,
|
||||
_("Restore Virtual Machine"),
|
||||
conn,
|
||||
browse_reason=self.config.CONFIG_DIR_RESTORE)
|
||||
@ -957,7 +957,8 @@ class vmmEngine(vmmGObject):
|
||||
conn = self._lookup_conn(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
|
||||
if not util.chkbox_helper(src, self.config.get_confirm_forcepoweroff,
|
||||
if not uihelpers.chkbox_helper(src,
|
||||
self.config.get_confirm_forcepoweroff,
|
||||
self.config.set_confirm_forcepoweroff,
|
||||
text1=_("Are you sure you want to force poweroff '%s'?" %
|
||||
vm.get_name()),
|
||||
@ -973,7 +974,7 @@ class vmmEngine(vmmGObject):
|
||||
conn = self._lookup_conn(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
|
||||
if not util.chkbox_helper(src, self.config.get_confirm_pause,
|
||||
if not uihelpers.chkbox_helper(src, self.config.get_confirm_pause,
|
||||
self.config.set_confirm_pause,
|
||||
text1=_("Are you sure you want to pause '%s'?" %
|
||||
vm.get_name())):
|
||||
@ -1036,7 +1037,7 @@ class vmmEngine(vmmGObject):
|
||||
conn = self._lookup_conn(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
|
||||
if not util.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
if not uihelpers.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
self.config.set_confirm_poweroff,
|
||||
text1=_("Are you sure you want to poweroff '%s'?" %
|
||||
vm.get_name())):
|
||||
@ -1050,7 +1051,7 @@ class vmmEngine(vmmGObject):
|
||||
conn = self._lookup_conn(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
|
||||
if not util.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
if not uihelpers.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
self.config.set_confirm_poweroff,
|
||||
text1=_("Are you sure you want to reboot '%s'?" %
|
||||
vm.get_name())):
|
||||
@ -1064,7 +1065,7 @@ class vmmEngine(vmmGObject):
|
||||
try:
|
||||
vm.reboot()
|
||||
except Exception, reboot_err:
|
||||
no_support = virtinst.util.is_error_nosupport(reboot_err)
|
||||
no_support = util.is_error_nosupport(reboot_err)
|
||||
if not no_support:
|
||||
raise RuntimeError(_("Error rebooting domain: %s" %
|
||||
str(reboot_err)))
|
||||
@ -1089,7 +1090,8 @@ class vmmEngine(vmmGObject):
|
||||
conn = self._lookup_conn(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
|
||||
if not util.chkbox_helper(src, self.config.get_confirm_forcepoweroff,
|
||||
if not uihelpers.chkbox_helper(src,
|
||||
self.config.get_confirm_forcepoweroff,
|
||||
self.config.set_confirm_forcepoweroff,
|
||||
text1=_("Are you sure you want to force reset '%s'?" %
|
||||
vm.get_name()),
|
||||
|
@ -30,7 +30,6 @@ from virtinst import Storage
|
||||
from virtinst import Interface
|
||||
|
||||
from virtManager import uihelpers
|
||||
from virtManager import util
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager.connection import vmmConnection
|
||||
from virtManager.createnet import vmmCreateNetwork
|
||||
@ -1019,7 +1018,7 @@ class vmmHost(vmmGObjectUI):
|
||||
if interface is None:
|
||||
return
|
||||
|
||||
if not util.chkbox_helper(self, self.config.get_confirm_interface,
|
||||
if not uihelpers.chkbox_helper(self, self.config.get_confirm_interface,
|
||||
self.config.set_confirm_interface,
|
||||
text1=_("Are you sure you want to stop the interface "
|
||||
"'%s'?" % interface.get_name())):
|
||||
@ -1034,7 +1033,7 @@ class vmmHost(vmmGObjectUI):
|
||||
if interface is None:
|
||||
return
|
||||
|
||||
if not util.chkbox_helper(self, self.config.get_confirm_interface,
|
||||
if not uihelpers.chkbox_helper(self, self.config.get_confirm_interface,
|
||||
self.config.set_confirm_interface,
|
||||
text1=_("Are you sure you want to start the interface "
|
||||
"'%s'?" % interface.get_name())):
|
||||
@ -1175,7 +1174,7 @@ class vmmHost(vmmGObjectUI):
|
||||
# This can fail if other interfaces are busted, so ignore errors
|
||||
used_by = None
|
||||
try:
|
||||
used_by = util.iface_in_use_by(self.conn, name)
|
||||
used_by = uihelpers.iface_in_use_by(self.conn, name)
|
||||
except Exception, e:
|
||||
logging.debug("Error looking up iface usage: %s", e)
|
||||
self.widget("interface-inuseby").set_text(used_by or "-")
|
||||
|
@ -27,11 +27,12 @@ from gi.repository import Gdk
|
||||
from gi.repository import GdkPixbuf
|
||||
# pylint: enable=E0611
|
||||
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import uihelpers
|
||||
from virtManager.connection import vmmConnection
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.graphwidgets import CellRendererSparkline
|
||||
from virtManager import util as util
|
||||
|
||||
|
||||
# Number of data points for performance graphs
|
||||
|
@ -29,9 +29,8 @@ from gi.repository import Gtk
|
||||
# pylint: enable=E0611
|
||||
|
||||
import libvirt
|
||||
from virtinst import util as virtinstutil
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager.domain import vmmDomain
|
||||
@ -275,7 +274,7 @@ class vmmMigrateDialog(vmmGObjectUI):
|
||||
return self.edit_uri(srcuri, desthost, None)
|
||||
|
||||
def edit_uri(self, uri, hostname, port):
|
||||
split = list(virtinstutil.uri_split(uri))
|
||||
split = list(util.uri_split(uri))
|
||||
|
||||
hostname = hostname or split[2]
|
||||
if port:
|
||||
|
@ -25,12 +25,12 @@ from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
# pylint: enable=E0611
|
||||
|
||||
import virtinst
|
||||
from virtinst import VirtualDisk
|
||||
|
||||
import virtManager.host
|
||||
import virtManager.util as util
|
||||
from virtManager import host
|
||||
from virtManager.createvol import vmmCreateVolume
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager import uihelpers
|
||||
|
||||
|
||||
class vmmStorageBrowser(vmmGObjectUI):
|
||||
@ -123,7 +123,7 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
|
||||
def set_initial_state(self):
|
||||
pool_list = self.widget("pool-list")
|
||||
virtManager.host.init_pool_list(pool_list, self.pool_selected)
|
||||
host.init_pool_list(pool_list, self.pool_selected)
|
||||
|
||||
# (Key, Name, Cap, Format, Used By, sensitive)
|
||||
vol_list = self.widget("vol-list")
|
||||
@ -171,7 +171,7 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
self.conn = conn
|
||||
|
||||
pool_list = self.widget("pool-list")
|
||||
virtManager.host.populate_storage_pools(pool_list, self.conn)
|
||||
host.populate_storage_pools(pool_list, self.conn)
|
||||
|
||||
ids = []
|
||||
ids.append(self.conn.connect("pool-added",
|
||||
@ -219,7 +219,7 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
return data["enable_create"]
|
||||
|
||||
def current_pool(self):
|
||||
row = util.get_list_selection(self.widget("pool-list"))
|
||||
row = uihelpers.get_list_selection(self.widget("pool-list"))
|
||||
if not row:
|
||||
return
|
||||
return self.conn.get_pool(row[0])
|
||||
@ -227,7 +227,7 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
def current_vol_row(self):
|
||||
if not self.current_pool():
|
||||
return
|
||||
return util.get_list_selection(self.widget("vol-list"))
|
||||
return uihelpers.get_list_selection(self.widget("vol-list"))
|
||||
|
||||
def current_vol(self):
|
||||
pool = self.current_pool()
|
||||
@ -238,7 +238,7 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
|
||||
def refresh_storage_pool(self, src_ignore, uuid):
|
||||
pool_list = self.widget("pool-list")
|
||||
virtManager.host.refresh_pool_in_list(pool_list, self.conn, uuid)
|
||||
host.refresh_pool_in_list(pool_list, self.conn, uuid)
|
||||
curpool = self.current_pool()
|
||||
if curpool.uuid != uuid:
|
||||
return
|
||||
@ -249,7 +249,7 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
|
||||
def repopulate_storage_pools(self, src_ignore, uuid_ignore):
|
||||
pool_list = self.widget("pool-list")
|
||||
virtManager.host.populate_storage_pools(pool_list, self.conn)
|
||||
host.populate_storage_pools(pool_list, self.conn)
|
||||
|
||||
|
||||
# Listeners
|
||||
@ -300,9 +300,9 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
if not self.local_args.get("dialog_name"):
|
||||
self.local_args["dialog_name"] = None
|
||||
|
||||
filename = util.browse_local(parent=self.topwin,
|
||||
conn=self.conn,
|
||||
**self.local_args)
|
||||
filename = uihelpers.browse_local(parent=self.topwin,
|
||||
conn=self.conn,
|
||||
**self.local_args)
|
||||
if filename:
|
||||
self._do_finish(path=filename)
|
||||
|
||||
@ -342,8 +342,8 @@ class vmmStorageBrowser(vmmGObjectUI):
|
||||
|
||||
try:
|
||||
if path:
|
||||
names = virtinst.VirtualDisk.path_in_use_by(
|
||||
self.conn.get_backend(), path)
|
||||
names = VirtualDisk.path_in_use_by(self.conn.get_backend(),
|
||||
path)
|
||||
namestr = ", ".join(names)
|
||||
if not namestr:
|
||||
namestr = None
|
||||
|
@ -22,10 +22,9 @@
|
||||
from gi.repository import GObject
|
||||
# pylint: enable=E0611
|
||||
|
||||
import virtinst
|
||||
from virtinst.util import xpath
|
||||
from virtinst import Storage
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
from virtManager.storagevol import vmmStorageVolume
|
||||
|
||||
@ -68,7 +67,7 @@ class vmmStoragePool(vmmLibvirtObject):
|
||||
|
||||
def can_change_alloc(self):
|
||||
typ = self.get_type()
|
||||
return (typ in [virtinst.Storage.StoragePool.TYPE_LOGICAL])
|
||||
return (typ in [Storage.StoragePool.TYPE_LOGICAL])
|
||||
|
||||
def get_uuid(self):
|
||||
return self._uuid
|
||||
@ -101,14 +100,14 @@ class vmmStoragePool(vmmLibvirtObject):
|
||||
return self._backend.autostart()
|
||||
|
||||
def get_target_path(self):
|
||||
return xpath(self.get_xml(), "/pool/target/path") or ""
|
||||
return util.xpath(self.get_xml(), "/pool/target/path") or ""
|
||||
|
||||
def get_allocation(self):
|
||||
return long(xpath(self.get_xml(), "/pool/allocation"))
|
||||
return long(util.xpath(self.get_xml(), "/pool/allocation"))
|
||||
def get_available(self):
|
||||
return long(xpath(self.get_xml(), "/pool/available"))
|
||||
return long(util.xpath(self.get_xml(), "/pool/available"))
|
||||
def get_capacity(self):
|
||||
return long(xpath(self.get_xml(), "/pool/capacity"))
|
||||
return long(util.xpath(self.get_xml(), "/pool/capacity"))
|
||||
|
||||
def get_pretty_allocation(self):
|
||||
return util.pretty_bytes(self.get_allocation())
|
||||
@ -118,7 +117,7 @@ class vmmStoragePool(vmmLibvirtObject):
|
||||
return util.pretty_bytes(self.get_capacity())
|
||||
|
||||
def get_type(self):
|
||||
return xpath(self.get_xml(), "/pool/@type")
|
||||
return util.xpath(self.get_xml(), "/pool/@type")
|
||||
|
||||
def get_volumes(self):
|
||||
self.update_volumes()
|
||||
|
@ -18,9 +18,8 @@
|
||||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
from virtinst.util import xpath
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
|
||||
|
||||
@ -48,15 +47,15 @@ class vmmStorageVolume(vmmLibvirtObject):
|
||||
self._backend = None
|
||||
|
||||
def get_target_path(self):
|
||||
return xpath(self.get_xml(), "/volume/target/path")
|
||||
return util.xpath(self.get_xml(), "/volume/target/path")
|
||||
|
||||
def get_format(self):
|
||||
return xpath(self.get_xml(), "/volume/target/format/@type")
|
||||
return util.xpath(self.get_xml(), "/volume/target/format/@type")
|
||||
|
||||
def get_allocation(self):
|
||||
return long(xpath(self.get_xml(), "/volume/allocation"))
|
||||
return long(util.xpath(self.get_xml(), "/volume/allocation"))
|
||||
def get_capacity(self):
|
||||
return long(xpath(self.get_xml(), "/volume/capacity"))
|
||||
return long(util.xpath(self.get_xml(), "/volume/capacity"))
|
||||
|
||||
def get_pretty_capacity(self):
|
||||
return util.pretty_bytes(self.get_capacity())
|
||||
@ -64,4 +63,4 @@ class vmmStorageVolume(vmmLibvirtObject):
|
||||
return util.pretty_bytes(self.get_allocation())
|
||||
|
||||
def get_type(self):
|
||||
return xpath(self.get_xml(), "/volume/format/@type")
|
||||
return util.xpath(self.get_xml(), "/volume/format/@type")
|
||||
|
@ -26,9 +26,11 @@ import statvfs
|
||||
from gi.repository import Gtk
|
||||
# pylint: enable=E0611
|
||||
|
||||
import virtinst
|
||||
import libvirt
|
||||
|
||||
from virtManager import util
|
||||
import virtinst
|
||||
from virtinst import util
|
||||
from virtManager import config
|
||||
|
||||
OPTICAL_DEV_PATH = 0
|
||||
OPTICAL_LABEL = 1
|
||||
@ -54,15 +56,15 @@ def set_sparse_tooltip(widget):
|
||||
|
||||
|
||||
def host_disk_space(conn):
|
||||
pool = util.get_default_pool(conn)
|
||||
path = util.get_default_dir(conn)
|
||||
pool = get_default_pool(conn)
|
||||
path = get_default_dir(conn)
|
||||
|
||||
avail = 0
|
||||
if pool and pool.is_active():
|
||||
# FIXME: make sure not inactive?
|
||||
# FIXME: use a conn specific function after we send pool-added
|
||||
pool.refresh()
|
||||
avail = int(virtinst.util.xpath(pool.get_xml(), "/pool/available"))
|
||||
avail = int(util.xpath(pool.get_xml(), "/pool/available"))
|
||||
|
||||
elif not conn.is_remote() and os.path.exists(path):
|
||||
vfs = os.statvfs(os.path.dirname(path))
|
||||
@ -88,7 +90,7 @@ def update_host_space(conn, widget):
|
||||
|
||||
|
||||
def check_default_pool_active(err, conn):
|
||||
default_pool = util.get_default_pool(conn)
|
||||
default_pool = get_default_pool(conn)
|
||||
if default_pool and not default_pool.is_active():
|
||||
res = err.yes_no(_("Default pool is not active."),
|
||||
_("Storage pool '%s' is not active. "
|
||||
@ -938,9 +940,9 @@ def check_path_search_for_qemu(err, conn, path):
|
||||
if conn.is_remote() or not conn.is_qemu_system():
|
||||
return
|
||||
|
||||
user = util.running_config.default_qemu_user
|
||||
user = config.running_config.default_qemu_user
|
||||
|
||||
skip_paths = util.running_config.get_perms_fix_ignore()
|
||||
skip_paths = config.running_config.get_perms_fix_ignore()
|
||||
broken_paths = virtinst.VirtualDisk.check_path_search_for_user(
|
||||
conn.get_backend(),
|
||||
path, user)
|
||||
@ -960,7 +962,7 @@ def check_path_search_for_qemu(err, conn, path):
|
||||
buttons=Gtk.ButtonsType.YES_NO)
|
||||
|
||||
if chkres:
|
||||
util.running_config.add_perms_fix_ignore(broken_paths)
|
||||
config.running_config.add_perms_fix_ignore(broken_paths)
|
||||
if not resp:
|
||||
return
|
||||
|
||||
@ -984,7 +986,7 @@ def check_path_search_for_qemu(err, conn, path):
|
||||
_("Don't ask about these directories again."))
|
||||
|
||||
if chkres:
|
||||
util.running_config.add_perms_fix_ignore(errors.keys())
|
||||
config.running_config.add_perms_fix_ignore(errors.keys())
|
||||
|
||||
|
||||
######################################
|
||||
@ -1042,3 +1044,304 @@ def spin_get_helper(widget):
|
||||
except:
|
||||
ret = adj.get_value()
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
def get_default_pool_path(conn):
|
||||
if conn.is_session_uri():
|
||||
return os.path.expanduser("~/VirtualMachines")
|
||||
return "/var/lib/libvirt/images"
|
||||
|
||||
|
||||
def get_default_pool_name(conn):
|
||||
ignore = conn
|
||||
return "default"
|
||||
|
||||
|
||||
def build_default_pool(vmmconn):
|
||||
"""
|
||||
Helper to build the 'default' storage pool
|
||||
"""
|
||||
conn = vmmconn.get_backend()
|
||||
|
||||
path = get_default_pool_path(vmmconn)
|
||||
name = get_default_pool_name(vmmconn)
|
||||
pool = None
|
||||
try:
|
||||
pool = conn.storagePoolLookupByName(name)
|
||||
except libvirt.libvirtError:
|
||||
pass
|
||||
|
||||
if pool:
|
||||
return
|
||||
|
||||
try:
|
||||
logging.debug("Attempting to build default pool with target '%s'",
|
||||
path)
|
||||
defpool = virtinst.Storage.DirectoryPool(conn=conn,
|
||||
name=name,
|
||||
target_path=path)
|
||||
newpool = defpool.install(build=True, create=True)
|
||||
newpool.setAutostart(True)
|
||||
except Exception, e:
|
||||
raise RuntimeError(_("Couldn't create default storage pool '%s': %s") %
|
||||
(path, str(e)))
|
||||
|
||||
|
||||
def get_ideal_path_info(conn, name):
|
||||
path = get_default_dir(conn)
|
||||
suffix = ".img"
|
||||
return (path, name, suffix)
|
||||
|
||||
|
||||
def get_ideal_path(conn, name):
|
||||
target, name, suffix = get_ideal_path_info(conn, name)
|
||||
return os.path.join(target, name) + suffix
|
||||
|
||||
|
||||
def get_default_pool(conn):
|
||||
pool = None
|
||||
default_name = get_default_pool_name(conn)
|
||||
for uuid in conn.list_pool_uuids():
|
||||
p = conn.get_pool(uuid)
|
||||
if p.get_name() == default_name:
|
||||
pool = p
|
||||
|
||||
return pool
|
||||
|
||||
|
||||
def get_default_dir(conn):
|
||||
pool = get_default_pool(conn)
|
||||
|
||||
if pool:
|
||||
return pool.get_target_path()
|
||||
else:
|
||||
return config.running_config.get_default_image_dir(conn)
|
||||
|
||||
|
||||
def get_default_path(conn, name, collidelist=None):
|
||||
collidelist = collidelist or []
|
||||
pool = get_default_pool(conn)
|
||||
|
||||
default_dir = get_default_dir(conn)
|
||||
|
||||
def path_exists(p):
|
||||
return os.path.exists(p) or p in collidelist
|
||||
|
||||
if not pool:
|
||||
# Use old generating method
|
||||
origf = os.path.join(default_dir, name + ".img")
|
||||
f = origf
|
||||
|
||||
n = 1
|
||||
while path_exists(f) and n < 100:
|
||||
f = os.path.join(default_dir, name +
|
||||
"-" + str(n) + ".img")
|
||||
n += 1
|
||||
|
||||
if path_exists(f):
|
||||
f = origf
|
||||
|
||||
path = f
|
||||
else:
|
||||
target, ignore, suffix = get_ideal_path_info(conn, name)
|
||||
|
||||
# Sanitize collidelist to work with the collision checker
|
||||
newcollidelist = []
|
||||
for c in collidelist:
|
||||
if c and os.path.dirname(c) == pool.get_target_path():
|
||||
newcollidelist.append(os.path.basename(c))
|
||||
|
||||
path = virtinst.Storage.StorageVolume.find_free_name(name,
|
||||
pool_object=pool.get_backend(), suffix=suffix,
|
||||
collidelist=newcollidelist)
|
||||
|
||||
path = os.path.join(target, path)
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def browse_local(parent, dialog_name, conn, start_folder=None,
|
||||
_type=None, dialog_type=None,
|
||||
confirm_func=None, browse_reason=None,
|
||||
choose_button=None, default_name=None):
|
||||
"""
|
||||
Helper function for launching a filechooser
|
||||
|
||||
@param parent: Parent window for the filechooser
|
||||
@param dialog_name: String to use in the title bar of the filechooser.
|
||||
@param conn: vmmConnection used by calling class
|
||||
@param start_folder: Folder the filechooser is viewing at startup
|
||||
@param _type: File extension to filter by (e.g. "iso", "png")
|
||||
@param dialog_type: Maps to FileChooserDialog 'action'
|
||||
@param confirm_func: Optional callback function if file is chosen.
|
||||
@param browse_reason: The vmmConfig.CONFIG_DIR* reason we are browsing.
|
||||
If set, this will override the 'folder' parameter with the gconf
|
||||
value, and store the user chosen path.
|
||||
|
||||
"""
|
||||
# Initial setup
|
||||
overwrite_confirm = False
|
||||
|
||||
if dialog_type is None:
|
||||
dialog_type = Gtk.FileChooserAction.OPEN
|
||||
if dialog_type == Gtk.FileChooserAction.SAVE:
|
||||
if choose_button is None:
|
||||
choose_button = Gtk.STOCK_SAVE
|
||||
overwrite_confirm = True
|
||||
|
||||
if choose_button is None:
|
||||
choose_button = Gtk.STOCK_OPEN
|
||||
|
||||
fcdialog = Gtk.FileChooserDialog(title=dialog_name,
|
||||
parent=parent,
|
||||
action=dialog_type,
|
||||
buttons=(Gtk.STOCK_CANCEL,
|
||||
Gtk.ResponseType.CANCEL,
|
||||
choose_button,
|
||||
Gtk.ResponseType.ACCEPT))
|
||||
fcdialog.set_default_response(Gtk.ResponseType.ACCEPT)
|
||||
|
||||
if default_name:
|
||||
fcdialog.set_current_name(default_name)
|
||||
|
||||
# If confirm is set, warn about a file overwrite
|
||||
if confirm_func:
|
||||
overwrite_confirm = True
|
||||
fcdialog.connect("confirm-overwrite", confirm_func)
|
||||
fcdialog.set_do_overwrite_confirmation(overwrite_confirm)
|
||||
|
||||
# Set file match pattern (ex. *.png)
|
||||
if _type is not None:
|
||||
pattern = _type
|
||||
name = None
|
||||
if type(_type) is tuple:
|
||||
pattern = _type[0]
|
||||
name = _type[1]
|
||||
|
||||
f = Gtk.FileFilter()
|
||||
f.add_pattern("*." + pattern)
|
||||
if name:
|
||||
f.set_name(name)
|
||||
fcdialog.set_filter(f)
|
||||
|
||||
# Set initial dialog folder
|
||||
if browse_reason:
|
||||
start_folder = config.running_config.get_default_directory(conn,
|
||||
browse_reason)
|
||||
|
||||
if start_folder is not None:
|
||||
if os.access(start_folder, os.R_OK):
|
||||
fcdialog.set_current_folder(start_folder)
|
||||
|
||||
# Run the dialog and parse the response
|
||||
ret = None
|
||||
if fcdialog.run() == Gtk.ResponseType.ACCEPT:
|
||||
ret = fcdialog.get_filename()
|
||||
fcdialog.destroy()
|
||||
|
||||
# Store the chosen directory in gconf if necessary
|
||||
if ret and browse_reason and not ret.startswith("/dev"):
|
||||
config.running_config.set_default_directory(os.path.dirname(ret),
|
||||
browse_reason)
|
||||
return ret
|
||||
|
||||
|
||||
def pretty_hv(gtype, domtype):
|
||||
"""
|
||||
Convert XML <domain type='foo'> and <os><type>bar</type>
|
||||
into a more human relevant string.
|
||||
"""
|
||||
|
||||
gtype = gtype.lower()
|
||||
domtype = domtype.lower()
|
||||
|
||||
label = domtype
|
||||
if domtype == "kvm":
|
||||
if gtype == "xen":
|
||||
label = "xenner"
|
||||
elif domtype == "xen":
|
||||
if gtype == "xen":
|
||||
label = "xen (paravirt)"
|
||||
elif gtype == "hvm":
|
||||
label = "xen (fullvirt)"
|
||||
elif domtype == "test":
|
||||
if gtype == "xen":
|
||||
label = "test (xen)"
|
||||
elif gtype == "hvm":
|
||||
label = "test (hvm)"
|
||||
|
||||
return label
|
||||
|
||||
|
||||
def iface_in_use_by(conn, name):
|
||||
use_str = ""
|
||||
for i in conn.list_interface_names():
|
||||
iface = conn.get_interface(i)
|
||||
if name in iface.get_slave_names():
|
||||
if use_str:
|
||||
use_str += ", "
|
||||
use_str += iface.get_name()
|
||||
|
||||
return use_str
|
||||
|
||||
|
||||
def chkbox_helper(src, getcb, setcb, text1, text2=None,
|
||||
alwaysrecord=False,
|
||||
default=True,
|
||||
chktext=_("Don't ask me again")):
|
||||
"""
|
||||
Helper to prompt user about proceeding with an operation
|
||||
Returns True if the 'yes' or 'ok' button was selected, False otherwise
|
||||
|
||||
@alwaysrecord: Don't require user to select 'yes' to record chkbox value
|
||||
@default: What value to return if getcb tells us not to prompt
|
||||
"""
|
||||
do_prompt = getcb()
|
||||
if not do_prompt:
|
||||
return default
|
||||
|
||||
res = src.err.warn_chkbox(text1=text1, text2=text2,
|
||||
chktext=chktext,
|
||||
buttons=Gtk.ButtonsType.YES_NO)
|
||||
response, skip_prompt = res
|
||||
if alwaysrecord or response:
|
||||
setcb(not skip_prompt)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def get_list_selection(widget):
|
||||
selection = widget.get_selection()
|
||||
active = selection.get_selected()
|
||||
|
||||
treestore, treeiter = active
|
||||
if treeiter is not None:
|
||||
return treestore[treeiter]
|
||||
return None
|
||||
|
||||
|
||||
def set_list_selection(widget, rownum):
|
||||
path = str(rownum)
|
||||
selection = widget.get_selection()
|
||||
|
||||
selection.unselect_all()
|
||||
widget.set_cursor(path)
|
||||
selection.select_path(path)
|
||||
|
||||
|
||||
def default_uri(always_system=False):
|
||||
if os.path.exists('/var/lib/xend'):
|
||||
if (os.path.exists('/dev/xen/evtchn') or
|
||||
os.path.exists("/proc/xen")):
|
||||
return 'xen:///'
|
||||
|
||||
if (os.path.exists("/usr/bin/qemu") or
|
||||
os.path.exists("/usr/bin/qemu-kvm") or
|
||||
os.path.exists("/usr/bin/kvm") or
|
||||
os.path.exists("/usr/libexec/qemu-kvm")):
|
||||
if always_system or os.geteuid() == 0:
|
||||
return "qemu:///system"
|
||||
else:
|
||||
return "qemu:///session"
|
||||
return None
|
||||
|
@ -1,350 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 Red Hat, Inc.
|
||||
# Copyright (C) 2008 Cole Robinson <crobinso@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
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import libvirt
|
||||
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
import virtinst
|
||||
|
||||
running_config = None
|
||||
|
||||
xml_escape = virtinst.util.xml_escape
|
||||
|
||||
|
||||
def get_default_pool_path(conn):
|
||||
if conn.is_session_uri():
|
||||
return os.path.expanduser("~/VirtualMachines")
|
||||
return "/var/lib/libvirt/images"
|
||||
|
||||
|
||||
def get_default_pool_name(conn):
|
||||
ignore = conn
|
||||
return "default"
|
||||
|
||||
|
||||
def build_default_pool(vmmconn):
|
||||
"""
|
||||
Helper to build the 'default' storage pool
|
||||
"""
|
||||
conn = vmmconn.get_backend()
|
||||
|
||||
path = get_default_pool_path(vmmconn)
|
||||
name = get_default_pool_name(vmmconn)
|
||||
pool = None
|
||||
try:
|
||||
pool = conn.storagePoolLookupByName(name)
|
||||
except libvirt.libvirtError:
|
||||
pass
|
||||
|
||||
if pool:
|
||||
return
|
||||
|
||||
try:
|
||||
logging.debug("Attempting to build default pool with target '%s'",
|
||||
path)
|
||||
defpool = virtinst.Storage.DirectoryPool(conn=conn,
|
||||
name=name,
|
||||
target_path=path)
|
||||
newpool = defpool.install(build=True, create=True)
|
||||
newpool.setAutostart(True)
|
||||
except Exception, e:
|
||||
raise RuntimeError(_("Couldn't create default storage pool '%s': %s") %
|
||||
(path, str(e)))
|
||||
|
||||
|
||||
def get_ideal_path_info(conn, name):
|
||||
path = get_default_dir(conn)
|
||||
suffix = ".img"
|
||||
return (path, name, suffix)
|
||||
|
||||
|
||||
def get_ideal_path(conn, name):
|
||||
target, name, suffix = get_ideal_path_info(conn, name)
|
||||
return os.path.join(target, name) + suffix
|
||||
|
||||
|
||||
def get_default_pool(conn):
|
||||
pool = None
|
||||
default_name = get_default_pool_name(conn)
|
||||
for uuid in conn.list_pool_uuids():
|
||||
p = conn.get_pool(uuid)
|
||||
if p.get_name() == default_name:
|
||||
pool = p
|
||||
|
||||
return pool
|
||||
|
||||
|
||||
def get_default_dir(conn):
|
||||
pool = get_default_pool(conn)
|
||||
|
||||
if pool:
|
||||
return pool.get_target_path()
|
||||
else:
|
||||
return running_config.get_default_image_dir(conn)
|
||||
|
||||
|
||||
def get_default_path(conn, name, collidelist=None):
|
||||
collidelist = collidelist or []
|
||||
pool = get_default_pool(conn)
|
||||
|
||||
default_dir = get_default_dir(conn)
|
||||
|
||||
def path_exists(p):
|
||||
return os.path.exists(p) or p in collidelist
|
||||
|
||||
if not pool:
|
||||
# Use old generating method
|
||||
origf = os.path.join(default_dir, name + ".img")
|
||||
f = origf
|
||||
|
||||
n = 1
|
||||
while path_exists(f) and n < 100:
|
||||
f = os.path.join(default_dir, name +
|
||||
"-" + str(n) + ".img")
|
||||
n += 1
|
||||
|
||||
if path_exists(f):
|
||||
f = origf
|
||||
|
||||
path = f
|
||||
else:
|
||||
target, ignore, suffix = get_ideal_path_info(conn, name)
|
||||
|
||||
# Sanitize collidelist to work with the collision checker
|
||||
newcollidelist = []
|
||||
for c in collidelist:
|
||||
if c and os.path.dirname(c) == pool.get_target_path():
|
||||
newcollidelist.append(os.path.basename(c))
|
||||
|
||||
path = virtinst.Storage.StorageVolume.find_free_name(name,
|
||||
pool_object=pool.get_backend(), suffix=suffix,
|
||||
collidelist=newcollidelist)
|
||||
|
||||
path = os.path.join(target, path)
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def browse_local(parent, dialog_name, conn, start_folder=None,
|
||||
_type=None, dialog_type=None,
|
||||
confirm_func=None, browse_reason=None,
|
||||
choose_button=None, default_name=None):
|
||||
"""
|
||||
Helper function for launching a filechooser
|
||||
|
||||
@param parent: Parent window for the filechooser
|
||||
@param dialog_name: String to use in the title bar of the filechooser.
|
||||
@param conn: vmmConnection used by calling class
|
||||
@param start_folder: Folder the filechooser is viewing at startup
|
||||
@param _type: File extension to filter by (e.g. "iso", "png")
|
||||
@param dialog_type: Maps to FileChooserDialog 'action'
|
||||
@param confirm_func: Optional callback function if file is chosen.
|
||||
@param browse_reason: The vmmConfig.CONFIG_DIR* reason we are browsing.
|
||||
If set, this will override the 'folder' parameter with the gconf
|
||||
value, and store the user chosen path.
|
||||
|
||||
"""
|
||||
from gi.repository import Gtk # pylint: disable=E0611
|
||||
|
||||
# Initial setup
|
||||
overwrite_confirm = False
|
||||
|
||||
if dialog_type is None:
|
||||
dialog_type = Gtk.FileChooserAction.OPEN
|
||||
if dialog_type == Gtk.FileChooserAction.SAVE:
|
||||
if choose_button is None:
|
||||
choose_button = Gtk.STOCK_SAVE
|
||||
overwrite_confirm = True
|
||||
|
||||
if choose_button is None:
|
||||
choose_button = Gtk.STOCK_OPEN
|
||||
|
||||
fcdialog = Gtk.FileChooserDialog(title=dialog_name,
|
||||
parent=parent,
|
||||
action=dialog_type,
|
||||
buttons=(Gtk.STOCK_CANCEL,
|
||||
Gtk.ResponseType.CANCEL,
|
||||
choose_button,
|
||||
Gtk.ResponseType.ACCEPT))
|
||||
fcdialog.set_default_response(Gtk.ResponseType.ACCEPT)
|
||||
|
||||
if default_name:
|
||||
fcdialog.set_current_name(default_name)
|
||||
|
||||
# If confirm is set, warn about a file overwrite
|
||||
if confirm_func:
|
||||
overwrite_confirm = True
|
||||
fcdialog.connect("confirm-overwrite", confirm_func)
|
||||
fcdialog.set_do_overwrite_confirmation(overwrite_confirm)
|
||||
|
||||
# Set file match pattern (ex. *.png)
|
||||
if _type is not None:
|
||||
pattern = _type
|
||||
name = None
|
||||
if type(_type) is tuple:
|
||||
pattern = _type[0]
|
||||
name = _type[1]
|
||||
|
||||
f = Gtk.FileFilter()
|
||||
f.add_pattern("*." + pattern)
|
||||
if name:
|
||||
f.set_name(name)
|
||||
fcdialog.set_filter(f)
|
||||
|
||||
# Set initial dialog folder
|
||||
if browse_reason:
|
||||
start_folder = running_config.get_default_directory(conn,
|
||||
browse_reason)
|
||||
|
||||
if start_folder is not None:
|
||||
if os.access(start_folder, os.R_OK):
|
||||
fcdialog.set_current_folder(start_folder)
|
||||
|
||||
# Run the dialog and parse the response
|
||||
ret = None
|
||||
if fcdialog.run() == Gtk.ResponseType.ACCEPT:
|
||||
ret = fcdialog.get_filename()
|
||||
fcdialog.destroy()
|
||||
|
||||
# Store the chosen directory in gconf if necessary
|
||||
if ret and browse_reason and not ret.startswith("/dev"):
|
||||
running_config.set_default_directory(os.path.dirname(ret),
|
||||
browse_reason)
|
||||
return ret
|
||||
|
||||
|
||||
def pretty_hv(gtype, domtype):
|
||||
"""
|
||||
Convert XML <domain type='foo'> and <os><type>bar</type>
|
||||
into a more human relevant string.
|
||||
"""
|
||||
|
||||
gtype = gtype.lower()
|
||||
domtype = domtype.lower()
|
||||
|
||||
label = domtype
|
||||
if domtype == "kvm":
|
||||
if gtype == "xen":
|
||||
label = "xenner"
|
||||
elif domtype == "xen":
|
||||
if gtype == "xen":
|
||||
label = "xen (paravirt)"
|
||||
elif gtype == "hvm":
|
||||
label = "xen (fullvirt)"
|
||||
elif domtype == "test":
|
||||
if gtype == "xen":
|
||||
label = "test (xen)"
|
||||
elif gtype == "hvm":
|
||||
label = "test (hvm)"
|
||||
|
||||
return label
|
||||
|
||||
|
||||
def iface_in_use_by(conn, name):
|
||||
use_str = ""
|
||||
for i in conn.list_interface_names():
|
||||
iface = conn.get_interface(i)
|
||||
if name in iface.get_slave_names():
|
||||
if use_str:
|
||||
use_str += ", "
|
||||
use_str += iface.get_name()
|
||||
|
||||
return use_str
|
||||
|
||||
|
||||
def pretty_mem(val):
|
||||
val = int(val)
|
||||
if val > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (val / 1024.0)
|
||||
|
||||
|
||||
def pretty_bytes(val):
|
||||
val = int(val)
|
||||
if val > (1024 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.2f MB" % (val / (1024.0 * 1024.0))
|
||||
|
||||
|
||||
def chkbox_helper(src, getcb, setcb, text1, text2=None,
|
||||
alwaysrecord=False,
|
||||
default=True,
|
||||
chktext=_("Don't ask me again")):
|
||||
"""
|
||||
Helper to prompt user about proceeding with an operation
|
||||
Returns True if the 'yes' or 'ok' button was selected, False otherwise
|
||||
|
||||
@alwaysrecord: Don't require user to select 'yes' to record chkbox value
|
||||
@default: What value to return if getcb tells us not to prompt
|
||||
"""
|
||||
from gi.repository import Gtk # pylint: disable=E0611
|
||||
|
||||
do_prompt = getcb()
|
||||
if not do_prompt:
|
||||
return default
|
||||
|
||||
res = src.err.warn_chkbox(text1=text1, text2=text2,
|
||||
chktext=chktext,
|
||||
buttons=Gtk.ButtonsType.YES_NO)
|
||||
response, skip_prompt = res
|
||||
if alwaysrecord or response:
|
||||
setcb(not skip_prompt)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def get_list_selection(widget):
|
||||
selection = widget.get_selection()
|
||||
active = selection.get_selected()
|
||||
|
||||
treestore, treeiter = active
|
||||
if treeiter is not None:
|
||||
return treestore[treeiter]
|
||||
return None
|
||||
|
||||
|
||||
def set_list_selection(widget, rownum):
|
||||
path = str(rownum)
|
||||
selection = widget.get_selection()
|
||||
|
||||
selection.unselect_all()
|
||||
widget.set_cursor(path)
|
||||
selection.select_path(path)
|
||||
|
||||
|
||||
def default_uri(always_system=False):
|
||||
if os.path.exists('/var/lib/xend'):
|
||||
if (os.path.exists('/dev/xen/evtchn') or
|
||||
os.path.exists("/proc/xen")):
|
||||
return 'xen:///'
|
||||
|
||||
if (os.path.exists("/usr/bin/qemu") or
|
||||
os.path.exists("/usr/bin/qemu-kvm") or
|
||||
os.path.exists("/usr/bin/kvm") or
|
||||
os.path.exists("/usr/libexec/qemu-kvm")):
|
||||
if always_system or os.geteuid() == 0:
|
||||
return "qemu:///system"
|
||||
else:
|
||||
return "qemu:///session"
|
||||
return None
|
@ -555,3 +555,19 @@ def make_scratchdir(conn, hvtype):
|
||||
os.makedirs(scratch, 0751)
|
||||
|
||||
return scratch
|
||||
|
||||
|
||||
def pretty_mem(val):
|
||||
val = int(val)
|
||||
if val > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (val / 1024.0)
|
||||
|
||||
|
||||
def pretty_bytes(val):
|
||||
val = int(val)
|
||||
if val > (1024 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.2f MB" % (val / (1024.0 * 1024.0))
|
||||
|
Loading…
Reference in New Issue
Block a user