virtinst: connection: Add is_privileged
Replace the is_session and is_system distinction with variants of is_privileged. This matches what libvirt uses internally, and will help with supporting qemu:///embed at some point Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
9a0d49a718
commit
bea5e56c26
|
@ -39,6 +39,10 @@ class TestConn(unittest.TestCase):
|
|||
conn._uriobj = URI("qemu://example.com/system")
|
||||
assert conn.get_uri_transport() == "tls"
|
||||
|
||||
# Hit the qemu:///embed case privileged case check
|
||||
fakeuri = "__virtinst_test__test:///default,fakeuri=qemu:///embed"
|
||||
conn = cli.getConnection(fakeuri)
|
||||
assert conn.is_privileged() == (os.getuid() == 0)
|
||||
|
||||
# Hit fakuuri validation error, for old style opts
|
||||
with self.assertRaises(RuntimeError):
|
||||
|
|
|
@ -338,11 +338,11 @@ class vmmConnection(vmmGObject):
|
|||
is_xen = property(lambda s: getattr(s, "_backend").is_xen)
|
||||
is_remote = property(lambda s: getattr(s, "_backend").is_remote)
|
||||
is_qemu = property(lambda s: getattr(s, "_backend").is_qemu)
|
||||
is_qemu_system = property(lambda s: getattr(s, "_backend").is_qemu_system)
|
||||
is_qemu_session = property(lambda s:
|
||||
getattr(s, "_backend").is_qemu_session)
|
||||
is_qemu_privileged = property(lambda s: getattr(s, "_backend").is_qemu_privileged)
|
||||
is_qemu_unprivileged = property(lambda s:
|
||||
getattr(s, "_backend").is_qemu_unprivileged)
|
||||
is_test = property(lambda s: getattr(s, "_backend").is_test)
|
||||
is_session_uri = property(lambda s: getattr(s, "_backend").is_session_uri)
|
||||
is_unprivileged = property(lambda s: getattr(s, "_backend").is_unprivileged)
|
||||
|
||||
|
||||
def get_cache_dir(self):
|
||||
|
@ -397,12 +397,13 @@ class vmmConnection(vmmGObject):
|
|||
hv = pretty_map.get(self.get_driver(), self.get_driver())
|
||||
hostname = self.get_uri_hostname()
|
||||
path = self.get_backend().get_uri_path()
|
||||
is_session = self.get_backend().is_session_uri()
|
||||
|
||||
ret = hv
|
||||
|
||||
if is_session:
|
||||
if path == "/session":
|
||||
ret += " " + _("User session")
|
||||
elif path == "/embed":
|
||||
ret += " " + _("Embedded session")
|
||||
elif (path and path != "/system" and os.path.basename(path)):
|
||||
# Used by test URIs to report what XML file they are using
|
||||
ret += " %s" % os.path.basename(path)
|
||||
|
|
|
@ -220,7 +220,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
|
|||
elif not rendernode_supported:
|
||||
rendernode_warning = (
|
||||
_("Hypervisor/libvirt does not support manual rendernode"))
|
||||
if self.conn.is_qemu_system():
|
||||
if self.conn.is_qemu_privileged():
|
||||
opengl_warning = rendernode_warning
|
||||
|
||||
if not opengl_warning:
|
||||
|
|
|
@ -146,7 +146,7 @@ class vmmNetworkList(vmmGObjectUI):
|
|||
_nettype = virtinst.DeviceInterface.TYPE_DIRECT
|
||||
model.append(_build_manual_row(_nettype, _label))
|
||||
|
||||
if self.conn.is_qemu_session():
|
||||
if self.conn.is_qemu_unprivileged():
|
||||
nettype = virtinst.DeviceInterface.TYPE_USER
|
||||
label = _pretty_network_desc(nettype)
|
||||
model.append(_build_row(nettype, None, label, True))
|
||||
|
|
|
@ -338,9 +338,15 @@ class VirtinstConnection(object):
|
|||
###################
|
||||
|
||||
def is_remote(self):
|
||||
return self._uriobj.hostname
|
||||
def is_session_uri(self):
|
||||
return self.get_uri_path() == "/session"
|
||||
return bool(self._uriobj.hostname)
|
||||
def is_privileged(self):
|
||||
if self.get_uri_path() == "/session":
|
||||
return False
|
||||
if self.get_uri_path() == "/embed":
|
||||
return os.getuid() == 0
|
||||
return True
|
||||
def is_unprivileged(self):
|
||||
return not self.is_privileged()
|
||||
|
||||
def get_uri_hostname(self):
|
||||
return self._uriobj.hostname
|
||||
|
@ -362,10 +368,10 @@ class VirtinstConnection(object):
|
|||
|
||||
def is_qemu(self):
|
||||
return self._uriobj.scheme.startswith("qemu")
|
||||
def is_qemu_system(self):
|
||||
return (self.is_qemu() and self._uriobj.path == "/system")
|
||||
def is_qemu_session(self):
|
||||
return (self.is_qemu() and self.is_session_uri())
|
||||
def is_qemu_privileged(self):
|
||||
return (self.is_qemu() and self.is_privileged())
|
||||
def is_qemu_unprivileged(self):
|
||||
return (self.is_qemu() and self.is_unprivileged())
|
||||
|
||||
def is_really_test(self):
|
||||
return URI(self._open_uri).scheme.startswith("test")
|
||||
|
|
|
@ -118,7 +118,7 @@ class DeviceDisk(Device):
|
|||
|
||||
if conn.is_remote():
|
||||
return searchdata
|
||||
if not conn.is_qemu_system():
|
||||
if not conn.is_qemu_privileged():
|
||||
return searchdata
|
||||
if diskbackend.path_is_url(path):
|
||||
return searchdata
|
||||
|
|
|
@ -259,7 +259,7 @@ class DeviceInterface(Device):
|
|||
self.is_conflict_net(self.conn, self.macaddr)
|
||||
|
||||
def set_default_source(self):
|
||||
if self.conn.is_qemu_session() or self.conn.is_test():
|
||||
if self.conn.is_qemu_unprivileged() or self.conn.is_test():
|
||||
self.type = self.TYPE_USER
|
||||
return
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class InstallerTreeMedia(object):
|
|||
|
||||
# If we are a session URI, or we don't have access to the system
|
||||
# scratchdir, make sure the session scratchdir exists and use that.
|
||||
if (guest.conn.is_session_uri() or
|
||||
if (guest.conn.is_unprivileged() or
|
||||
not os.path.exists(system_scratchdir) or
|
||||
not os.access(system_scratchdir, os.W_OK)):
|
||||
if not os.path.exists(user_scratchdir):
|
||||
|
|
|
@ -136,7 +136,7 @@ def upload_kernel_initrd(conn, scratchdir, system_scratchdir,
|
|||
tmpvols = []
|
||||
|
||||
if (not conn.is_remote() and
|
||||
(conn.is_session_uri() or scratchdir == system_scratchdir)):
|
||||
(conn.is_unprivileged() or scratchdir == system_scratchdir)):
|
||||
# We have access to system scratchdir, don't jump through hoops
|
||||
log.debug("Have access to preferred scratchdir so"
|
||||
" nothing to upload") # pragma: no cover
|
||||
|
|
|
@ -49,7 +49,7 @@ class _StorageObject(XMLBuilder):
|
|||
|
||||
def _preferred_default_pool_path(conn):
|
||||
path = "/var/lib/libvirt/images"
|
||||
if conn.is_session_uri():
|
||||
if conn.is_unprivileged():
|
||||
path = os.path.expanduser("~/.local/share/libvirt/images")
|
||||
return path
|
||||
|
||||
|
|
Loading…
Reference in New Issue