util: Move local_libvirt_version to VirtinstConnection

Make it private because we want people to use
conn.local_libvirt_version, and adjust the one other user
This commit is contained in:
Cole Robinson 2019-06-07 17:15:10 -04:00
parent 7d17d5d03b
commit b34800decd
3 changed files with 19 additions and 16 deletions

View File

@ -17,7 +17,7 @@ import gi
gi.require_version('LibvirtGLib', '1.0')
from gi.repository import LibvirtGLib
from virtinst import util
from virtinst import VirtinstConnection
from virtinst import cli
from virtcli import CLIConfig
@ -258,7 +258,7 @@ def main():
Gtk.get_minor_version(),
Gtk.get_micro_version())
if not util.local_libvirt_version() >= 6000:
if not VirtinstConnection.libvirt_new_enough_for_virtmanager(6000):
# We need this version for threaded virConnect access
_show_startup_error(
_("virt-manager requires libvirt 0.6.0 or later."), "")

View File

@ -11,7 +11,6 @@ import libvirt
from . import pollhelpers
from . import support
from . import util
from . import Capabilities
from .guest import Guest
from .nodedev import NodeDevice
@ -19,6 +18,17 @@ from .storage import StoragePool, StorageVolume
from .uri import URI, MagicURI
def _real_local_libvirt_version():
"""
Lookup the local libvirt library version, but cache the value since
it never changes.
"""
key = "__virtinst_cached_getVersion"
if not hasattr(libvirt, key):
setattr(libvirt, key, libvirt.getVersion())
return getattr(libvirt, key)
class VirtinstConnection(object):
"""
Wrapper for libvirt connection that provides various bits like
@ -26,6 +36,10 @@ class VirtinstConnection(object):
- lookup for API feature support
- simplified API wrappers that handle new and old ways of doing things
"""
@staticmethod
def libvirt_new_enough_for_virtmanager(version):
return _real_local_libvirt_version() >= version
def __init__(self, uri):
_initial_uri = uri or ""
@ -294,13 +308,13 @@ class VirtinstConnection(object):
if self._fake_libvirt_version is not None:
return self._fake_libvirt_version
# This handles caching for us
return util.local_libvirt_version()
return _real_local_libvirt_version()
def daemon_version(self):
if self._fake_libvirt_version is not None:
return self._fake_libvirt_version
if not self.is_remote():
return self.local_libvirt_version()
return _real_local_libvirt_version()
if self._daemon_version is None:
self._daemon_version = 0

View File

@ -119,17 +119,6 @@ def xml_escape(xml):
return xml
def local_libvirt_version():
"""
Lookup the local libvirt library version, but cache the value since
it never changes.
"""
key = "__virtinst_cached_getVersion"
if not hasattr(libvirt, key):
setattr(libvirt, key, libvirt.getVersion())
return getattr(libvirt, key)
def pretty_mem(val):
val = int(val)
if val > (10 * 1024 * 1024):