cli: Warn if disk path isn't searchable by qemu

This commit is contained in:
Cole Robinson 2014-02-10 18:08:59 -05:00
parent 9fe79627c1
commit d0f44491ff
5 changed files with 47 additions and 24 deletions

View File

@ -19,7 +19,6 @@
import logging
import os
import pwd
import statvfs
# pylint: disable=E0611
@ -139,25 +138,12 @@ class vmmAddStorage(vmmGObjectUI):
##############
@staticmethod
def check_path_search_for_qemu(src, conn, path):
if conn.is_remote() or not conn.is_qemu_system():
return
user = src.config.default_qemu_user
for i in conn.caps.host.secmodels:
if i.model == "dac":
label = i.baselabels.get("kvm") or i.baselabels.get("qemu")
if not label:
continue
pwuid = pwd.getpwuid(int(label.split(":")[0].replace("+", "")))
if pwuid:
user = pwuid[0]
def check_path_search(src, conn, path):
skip_paths = src.config.get_perms_fix_ignore()
broken_paths = virtinst.VirtualDisk.check_path_search_for_user(
conn.get_backend(), path, user)
for p in broken_paths:
user, broken_paths = virtinst.VirtualDisk.check_path_search(
conn.get_backend(), path)
for p in broken_paths[:]:
if p in skip_paths:
broken_paths.remove(p)
@ -178,8 +164,8 @@ class vmmAddStorage(vmmGObjectUI):
return
logging.debug("Attempting to correct permission issues.")
errors = virtinst.VirtualDisk.fix_path_search_for_user(conn.get_backend(),
path, user)
errors = virtinst.VirtualDisk.fix_path_search_for_user(
conn.get_backend(), path, user)
if not errors:
return
@ -380,7 +366,7 @@ class vmmAddStorage(vmmGObjectUI):
if not res:
return False
self.check_path_search_for_qemu(self, self.conn, disk.path)
self.check_path_search(self, self.conn, disk.path)
#############

View File

@ -125,7 +125,7 @@ class vmmChooseCD(vmmGObjectUI):
if not res:
return False
vmmAddStorage.check_path_search_for_qemu(self, self.conn, path)
vmmAddStorage.check_path_search(self, self.conn, path)
self.emit("cdrom-chosen", self.disk, path)
self.close()

View File

@ -1580,7 +1580,7 @@ class vmmCreate(vmmGObjectUI):
path = None
if path:
self.addstorage.check_path_search_for_qemu(
self.addstorage.check_path_search(
self, self.conn, path)
# Validation passed, store the install path (if there is one) in

View File

@ -326,9 +326,18 @@ def validate_disk(dev, warn_overwrite=False):
if not isfatal and errmsg:
_optional_fail(errmsg)
def check_path_search(dev):
user, broken_paths = dev.check_path_search(dev.conn, dev.path)
if not broken_paths:
return
logging.warning(_("%s may not be accessible by the hypervisor. "
"You will need to grant the '%s' user search permissions for "
"the following directories: %s"), dev.path, user, broken_paths)
check_path_exists(dev)
check_inuse_conflict(dev)
check_size_conflict(dev)
check_path_search(dev)
def _run_console(args):

View File

@ -273,6 +273,34 @@ class VirtualDisk(VirtualDevice):
return fixlist
@staticmethod
def check_path_search(conn, path):
# Only works for qemu and DAC
if conn.is_remote() or not conn.is_qemu_system():
return None, []
from virtcli import cliconfig
user = cliconfig.default_qemu_user
try:
for i in conn.caps.host.secmodels:
if i.model != "dac":
continue
label = (i.baselabels.get("kvm") or
i.baselabels.get("qemu"))
if not label:
continue
pwuid = pwd.getpwuid(
int(label.split(":")[0].replace("+", "")))
if pwuid:
user = pwuid[0]
except:
logging.debug("Exception grabbing qemu DAC user", exc_info=True)
return None, []
return user, VirtualDisk.check_path_search_for_user(conn, path, user)
@staticmethod
def fix_path_search_for_user(conn, path, username):
"""