mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
cli: Warn if disk path isn't searchable by qemu
This commit is contained in:
parent
9fe79627c1
commit
d0f44491ff
@ -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)
|
||||
|
||||
|
||||
#############
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user