mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
virtinst: Remove User module
I'm sure the solaris support is totally broken, so just drop this overcomplicated abstraction. Also fix a bug where we were using usermode networking in a bunch of places where it isn't supported.
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/libexec/libvirt_lxc</emulator>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<console type='pty'/>
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
<source dir='/source'/>
|
||||
<target dir='/'/>
|
||||
</filesystem>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<console type='pty'/>
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/libexec/libvirt_lxc</emulator>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<console type='pty'/>
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='xvda' bus='xen'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='xen'/>
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
<target dev='hdc' bus='ide'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='xvda' bus='xen'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='xen'/>
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
@@ -59,7 +60,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='xvda' bus='xen'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='xen'/>
|
||||
@@ -49,7 +50,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='xvda' bus='xen'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='xen'/>
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='xvda' bus='xen'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='xen'/>
|
||||
@@ -49,7 +50,8 @@
|
||||
<source file='/tmp/__virtinst_cli_exist1.img'/>
|
||||
<target dev='xvda' bus='xen'/>
|
||||
</disk>
|
||||
<interface type='user'>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
<mac address='00:11:22:33:44:55'/>
|
||||
</interface>
|
||||
<input type='mouse' bus='xen'/>
|
||||
|
||||
@@ -29,7 +29,6 @@ import urlgrabber.progress as progress
|
||||
import virtinst.cli as cli
|
||||
from virtinst import Cloner
|
||||
from virtinst.cli import fail, print_stdout, print_stderr
|
||||
from virtinst.User import User
|
||||
|
||||
|
||||
### General input gathering functions
|
||||
@@ -201,7 +200,6 @@ def parse_args():
|
||||
(options, parseargs) = parser.parse_args()
|
||||
return options, parseargs
|
||||
|
||||
### Let's do it!
|
||||
|
||||
|
||||
def main(conn=None):
|
||||
@@ -219,9 +217,6 @@ def main(conn=None):
|
||||
if conn is None:
|
||||
conn = cli.getConnection(options.connect)
|
||||
|
||||
if not User.current().has_priv(User.PRIV_CLONE, conn.getURI()):
|
||||
fail(_("Must be privileged to clone Xen guests"))
|
||||
|
||||
design = Cloner(conn)
|
||||
|
||||
design.clone_running = options.clone_running
|
||||
|
||||
@@ -30,7 +30,6 @@ from virtinst import support
|
||||
from virtinst import util
|
||||
from virtinst import Installer
|
||||
from virtinst.VirtualDisk import VirtualDisk
|
||||
from virtinst.User import User
|
||||
from virtinst import OSDistro
|
||||
|
||||
|
||||
@@ -252,11 +251,6 @@ class DistroInstaller(Installer.Installer):
|
||||
"or FTP network install source, or an existing "
|
||||
"file/device"))
|
||||
|
||||
if (not self._location_is_path and val.startswith("nfs:") and not
|
||||
User.current().has_priv(User.PRIV_NFS_MOUNT,
|
||||
(self.conn and self.get_uri()))):
|
||||
raise ValueError(_('Privilege is required for NFS installations'))
|
||||
|
||||
self._location = val
|
||||
location = property(get_location, set_location)
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
#
|
||||
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
||||
# Use is subject to license terms.
|
||||
#
|
||||
# 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 os
|
||||
import platform
|
||||
|
||||
from virtinst import uriutil
|
||||
|
||||
|
||||
class User(object):
|
||||
"""Defines a particular user account."""
|
||||
|
||||
PRIV_CLONE = 1
|
||||
PRIV_NFS_MOUNT = 2
|
||||
PRIV_QEMU_SYSTEM = 3
|
||||
PRIV_CREATE_DOMAIN = 4
|
||||
PRIV_CREATE_NETWORK = 5
|
||||
|
||||
_privs = [PRIV_CLONE, PRIV_NFS_MOUNT, PRIV_QEMU_SYSTEM,
|
||||
PRIV_CREATE_DOMAIN, PRIV_CREATE_NETWORK]
|
||||
|
||||
def __init__(self, euid):
|
||||
self._euid = euid
|
||||
|
||||
def get_euid(self):
|
||||
return self._euid
|
||||
euid = property(get_euid)
|
||||
|
||||
def has_priv(self, priv, conn=None):
|
||||
"""Return if the given user is privileged enough to perform the
|
||||
given operation. This isn't entirely accurate currently,
|
||||
especially on Solaris."""
|
||||
|
||||
if priv not in self._privs:
|
||||
raise ValueError('unknown privilege %s' % priv)
|
||||
|
||||
if priv == self.PRIV_QEMU_SYSTEM:
|
||||
return self._euid == 0
|
||||
|
||||
if priv == self.PRIV_CREATE_NETWORK:
|
||||
return (self._euid == 0) or uriutil.is_qemu_system(conn)
|
||||
|
||||
if platform.system() == 'SunOS':
|
||||
return self._sun_has_priv(priv)
|
||||
|
||||
# For all others, just assume that prescence of a connection
|
||||
# means we are privileged enough
|
||||
return True
|
||||
|
||||
def _sun_has_priv(self, priv):
|
||||
# Not easy to work out!
|
||||
if self._euid != User.current().euid:
|
||||
return self._euid == 0
|
||||
|
||||
import ucred # pylint: disable=F0401
|
||||
cred = ucred.get(os.getpid())
|
||||
if priv in [self.PRIV_CLONE,
|
||||
self.PRIV_CREATE_DOMAIN,
|
||||
self.PRIV_CREATE_NETWORK]:
|
||||
return cred.has_priv('Effective', 'virt_manage')
|
||||
if priv == self.PRIV_NFS_MOUNT:
|
||||
return (cred.has_priv('Effective', 'sys_mount') and
|
||||
cred.has_priv('Effective', 'net_privaddr'))
|
||||
|
||||
def current():
|
||||
"""Return the current user."""
|
||||
return User(os.geteuid())
|
||||
|
||||
current = staticmethod(current)
|
||||
@@ -46,7 +46,6 @@ from virtinst.ImportInstaller import ImportInstaller
|
||||
from virtinst.ImageInstaller import ImageInstaller
|
||||
from virtinst.Installer import ContainerInstaller
|
||||
from virtinst.CloneManager import Cloner
|
||||
from virtinst.User import User
|
||||
from virtinst.Clock import Clock
|
||||
from virtinst.CPU import CPU, CPUFeature
|
||||
from virtinst.Seclabel import Seclabel
|
||||
|
||||
@@ -35,6 +35,7 @@ import libvirt
|
||||
from virtcli import cliconfig
|
||||
|
||||
import virtinst
|
||||
from virtinst import uriutil
|
||||
from virtinst import util
|
||||
from virtinst.util import listify
|
||||
|
||||
@@ -44,7 +45,6 @@ from virtinst import VirtualGraphics
|
||||
from virtinst import VirtualAudio
|
||||
from virtinst import VirtualDisk
|
||||
from virtinst import VirtualCharDevice
|
||||
from virtinst import User
|
||||
|
||||
|
||||
DEFAULT_POOL_PATH = "/var/lib/libvirt/images"
|
||||
@@ -325,9 +325,6 @@ def open_test_uri(uri):
|
||||
|
||||
|
||||
def getConnection(uri):
|
||||
if (uri and not User.current().has_priv(User.PRIV_CREATE_DOMAIN, uri)):
|
||||
fail(_("Must be root to create Xen guests"))
|
||||
|
||||
# Hack to facilitate virtinst unit testing
|
||||
if is_virtinst_test_uri(uri):
|
||||
return open_test_uri(uri)
|
||||
@@ -879,11 +876,12 @@ def get_cpuset(guest, cpuset, memory):
|
||||
|
||||
def _default_network_opts(guest):
|
||||
opts = ""
|
||||
if User.current().has_priv(User.PRIV_CREATE_NETWORK, guest.get_uri()):
|
||||
if (uriutil.is_qemu_session(guest.conn) or
|
||||
uriutil.is_test(guest.conn)):
|
||||
opts = "user"
|
||||
else:
|
||||
net = util.default_network(guest.conn)
|
||||
opts = "%s=%s" % (net[0], net[1])
|
||||
else:
|
||||
opts = "user"
|
||||
|
||||
return opts
|
||||
|
||||
|
||||
@@ -137,6 +137,10 @@ def is_qemu_system(conn, uri=None):
|
||||
return False
|
||||
|
||||
|
||||
def is_qemu_session(conn):
|
||||
return is_qemu(conn) and is_session_uri(conn)
|
||||
|
||||
|
||||
def is_session_uri(conn, uri=None):
|
||||
uri = _get_uri_to_split(conn, uri)
|
||||
if not uri:
|
||||
@@ -147,6 +151,15 @@ def is_session_uri(conn, uri=None):
|
||||
return bool(path and path == "/session")
|
||||
|
||||
|
||||
def is_test(conn, uri=None):
|
||||
uri = _get_uri_to_split(conn, uri)
|
||||
if not uri:
|
||||
return False
|
||||
|
||||
scheme = uri_split(uri)[0]
|
||||
return scheme.startswith("test")
|
||||
|
||||
|
||||
def is_qemu(conn, uri=None):
|
||||
uri = _get_uri_to_split(conn, uri)
|
||||
if not uri:
|
||||
|
||||
@@ -432,18 +432,15 @@ def default_network(conn):
|
||||
|
||||
def default_connection():
|
||||
if os.path.exists('/var/lib/xend'):
|
||||
if os.path.exists('/dev/xen/evtchn'):
|
||||
return 'xen'
|
||||
if os.path.exists("/proc/xen"):
|
||||
if (os.path.exists('/dev/xen/evtchn') or
|
||||
os.path.exists("/proc/xen")):
|
||||
return 'xen'
|
||||
|
||||
from virtinst import User
|
||||
|
||||
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/bin/xenner"):
|
||||
if User.current().has_priv(User.PRIV_QEMU_SYSTEM):
|
||||
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/bin/xenner")):
|
||||
if os.geteuid() == 0:
|
||||
return "qemu:///system"
|
||||
else:
|
||||
return "qemu:///session"
|
||||
@@ -454,7 +451,6 @@ def is_blktap_capable():
|
||||
if platform.system() == 'SunOS':
|
||||
return False
|
||||
|
||||
# return os.path.exists("/dev/xen/blktapctrl")
|
||||
f = open("/proc/modules")
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
@@ -464,10 +460,6 @@ def is_blktap_capable():
|
||||
return False
|
||||
|
||||
|
||||
# this function is directly from xend/server/netif.py and is thus
|
||||
# available under the LGPL,
|
||||
# Copyright 2004, 2005 Mike Wray <mike.wray@hp.com>
|
||||
# Copyright 2005 XenSource Ltd
|
||||
def randomMAC(typ, conn=None):
|
||||
"""Generate a random MAC address.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user