mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-10 23:45:49 -06:00
Centralize connection duplication, and always use openAuth.
This commit is contained in:
parent
e8aa74000e
commit
09be6d1702
@ -22,7 +22,6 @@ import gobject
|
||||
import gtk
|
||||
import gtk.gdk
|
||||
import gtk.glade
|
||||
import libvirt
|
||||
import virtinst
|
||||
import os
|
||||
import logging
|
||||
@ -617,7 +616,7 @@ class vmmAddHardware(gobject.GObject):
|
||||
# If creating disk via storage API, we need to thread
|
||||
# off a new connection
|
||||
if disk.vol_install:
|
||||
newconn = libvirt.open(disk.conn.getURI())
|
||||
newconn = vmmutil.dup_conn(self.config, None, disk.conn)
|
||||
disk.conn = newconn
|
||||
logging.debug("Starting background file allocate process")
|
||||
disk.setup(meter)
|
||||
|
@ -24,8 +24,6 @@ import gtk.glade
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.error import vmmErrorDialog
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
@ -302,12 +300,7 @@ class vmmCreatePool(gobject.GObject):
|
||||
newconn = None
|
||||
try:
|
||||
# Open a seperate connection to install on since this is async
|
||||
logging.debug("Threading off connection to create pool.")
|
||||
#newconn = vmmConnection(self.config, self.conn.get_uri(),
|
||||
# self.conn.is_read_only())
|
||||
#newconn.open()
|
||||
#newconn.connectThreadEvent.wait()
|
||||
newconn = libvirt.open(self._pool.conn.getURI())
|
||||
newconn = util.dup_conn(self.config, None, self._pool.conn)
|
||||
meter = vmmCreateMeter(asyncjob)
|
||||
self._pool.conn = newconn
|
||||
|
||||
|
@ -24,8 +24,7 @@ import gtk.glade
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.error import vmmErrorDialog
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager.createmeter import vmmCreateMeter
|
||||
@ -177,13 +176,7 @@ class vmmCreateVolume(gobject.GObject):
|
||||
def _async_vol_create(self, asyncjob):
|
||||
newconn = None
|
||||
try:
|
||||
# Open a seperate connection to install on since this is async
|
||||
logging.debug("Threading off connection to create vol.")
|
||||
#newconn = vmmConnection(self.config, self.conn.get_uri(),
|
||||
# self.conn.is_read_only())
|
||||
#newconn.open()
|
||||
#newconn.connectThreadEvent.wait()
|
||||
newconn = libvirt.open(self.conn.get_uri())
|
||||
newconn = util.dup_conn(self.config, self.conn)
|
||||
|
||||
# Lookup different pool obj
|
||||
newpool = newconn.storagePoolLookupByName(self.parent_pool.get_name())
|
||||
|
@ -23,7 +23,9 @@ import libvirt
|
||||
import libxml2
|
||||
import os
|
||||
import logging
|
||||
import virtinst.util as util
|
||||
|
||||
from virtManager import util
|
||||
import virtinst.util as vutil
|
||||
|
||||
class vmmDomain(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
@ -151,7 +153,7 @@ class vmmDomain(gobject.GObject):
|
||||
return False
|
||||
|
||||
def is_hvm(self):
|
||||
os_type = util.get_xml_path(self.get_xml(), "/domain/os/type")
|
||||
os_type = vutil.get_xml_path(self.get_xml(), "/domain/os/type")
|
||||
# FIXME: This should be static, not parse xml everytime
|
||||
# XXX libvirt bug - doesn't work for inactive guests
|
||||
#os_type = self.vm.OSType()
|
||||
@ -162,7 +164,7 @@ class vmmDomain(gobject.GObject):
|
||||
|
||||
def get_type(self):
|
||||
# FIXME: This should be static, not parse xml everytime
|
||||
return util.get_xml_path(self.get_xml(), "/domain/@type")
|
||||
return vutil.get_xml_path(self.get_xml(), "/domain/@type")
|
||||
|
||||
def is_vcpu_hotplug_capable(self):
|
||||
# Read only connections aren't allowed to change it
|
||||
@ -241,7 +243,7 @@ class vmmDomain(gobject.GObject):
|
||||
self.connection.host_active_processor_count()))
|
||||
# Due to timing diffs between getting wall time & getting
|
||||
# the domain's time, its possible to go a tiny bit over
|
||||
# 100% utilization. This freaks out users of the data, so
|
||||
# 100% vutilization. This freaks out users of the data, so
|
||||
# we hard limit it.
|
||||
if pcentCpuTime > 100.0:
|
||||
pcentCpuTime = 100.0
|
||||
@ -467,7 +469,7 @@ class vmmDomain(gobject.GObject):
|
||||
return self.record[0]["vcpuCount"]
|
||||
|
||||
def vcpu_max_count(self):
|
||||
cpus = util.get_xml_path(self.get_xml(), "/domain/vcpu")
|
||||
cpus = vutil.get_xml_path(self.get_xml(), "/domain/vcpu")
|
||||
return int(cpus)
|
||||
|
||||
def cpu_time_vector(self):
|
||||
@ -569,7 +571,7 @@ class vmmDomain(gobject.GObject):
|
||||
|
||||
def save(self, filename, ignore1=None, background=True):
|
||||
if background:
|
||||
conn = libvirt.open(self.connection.uri)
|
||||
conn = util.dup_conn(self.config, self.connection)
|
||||
vm = conn.lookupByID(self.get_id())
|
||||
else:
|
||||
vm = self.vm
|
||||
@ -635,11 +637,11 @@ class vmmDomain(gobject.GObject):
|
||||
def get_graphics_console(self):
|
||||
self.update_xml()
|
||||
|
||||
typ = util.get_xml_path(self.get_xml(),
|
||||
typ = vutil.get_xml_path(self.get_xml(),
|
||||
"/domain/devices/graphics/@type")
|
||||
port = None
|
||||
if typ == "vnc":
|
||||
port = util.get_xml_path(self.get_xml(),
|
||||
port = vutil.get_xml_path(self.get_xml(),
|
||||
"/domain/devices/graphics[@type='vnc']/@port")
|
||||
if port is not None:
|
||||
port = int(port)
|
||||
|
@ -23,6 +23,7 @@ import gtk
|
||||
|
||||
import libvirt
|
||||
|
||||
import virtManager
|
||||
import virtinst
|
||||
|
||||
DEFAULT_POOL_NAME = "default"
|
||||
@ -112,3 +113,28 @@ def browse_local(parent, dialog_name, start_folder=None, _type=None,
|
||||
fcdialog.destroy()
|
||||
return None
|
||||
|
||||
def dup_conn(config, conn, libconn=None):
|
||||
|
||||
is_readonly = False
|
||||
|
||||
if libconn:
|
||||
uri = libconn.getURI()
|
||||
is_test = uri.startswith("test")
|
||||
vmm = libconn
|
||||
else:
|
||||
is_test = conn.is_test_conn()
|
||||
is_readonly = conn.is_read_only()
|
||||
uri = conn.get_uri()
|
||||
vmm = conn.vmm
|
||||
|
||||
if is_test:
|
||||
# Skip duplicating a test conn, since it doesn't maintain state
|
||||
# between instances
|
||||
return vmm
|
||||
|
||||
logging.debug("Duplicating connection for async operation.")
|
||||
newconn = virtManager.connection.vmmConnection(config, uri, is_readonly)
|
||||
newconn.open()
|
||||
newconn.connectThreadEvent.wait()
|
||||
|
||||
return newconn.vmm
|
||||
|
Loading…
Reference in New Issue
Block a user