2015-02-24 20:21:24 +08:00
|
|
|
# Copyright (C) 2006, 2013, 2014, 2015 Red Hat, Inc.
|
2006-06-29 03:50:17 +08:00
|
|
|
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2010-12-11 00:47:07 +08:00
|
|
|
import os
|
2015-04-02 07:10:16 +08:00
|
|
|
import threading
|
2011-04-29 05:11:04 +08:00
|
|
|
import time
|
2012-01-28 07:31:21 +08:00
|
|
|
import traceback
|
2010-01-07 02:09:33 +08:00
|
|
|
|
|
|
|
import libvirt
|
2016-06-07 23:33:21 +08:00
|
|
|
|
2008-02-23 00:48:29 +08:00
|
|
|
import virtinst
|
2019-06-17 09:12:39 +08:00
|
|
|
from virtinst import log
|
2013-07-08 01:53:37 +08:00
|
|
|
from virtinst import pollhelpers
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2019-06-17 10:19:17 +08:00
|
|
|
from .lib import connectauth
|
2020-09-03 01:38:48 +08:00
|
|
|
from .lib import testmock
|
2014-09-13 04:10:45 +08:00
|
|
|
from .baseclass import vmmGObject
|
2019-06-17 10:19:17 +08:00
|
|
|
from .lib.libvirtenummap import LibvirtEnumMap
|
2019-06-17 09:40:46 +08:00
|
|
|
from .object.domain import vmmDomain
|
|
|
|
from .object.network import vmmNetwork
|
|
|
|
from .object.nodedev import vmmNodeDevice
|
|
|
|
from .object.storagepool import vmmStoragePool
|
2019-06-17 10:19:17 +08:00
|
|
|
from .lib.statsmanager import vmmStatsManager
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2012-01-28 07:31:21 +08:00
|
|
|
|
2015-04-10 22:33:04 +08:00
|
|
|
class _ObjectList(vmmGObject):
|
|
|
|
"""
|
|
|
|
Class that wraps our internal list of libvirt objects
|
|
|
|
"""
|
2018-03-13 03:48:09 +08:00
|
|
|
# pylint: disable=not-context-manager
|
|
|
|
# pylint doesn't know that lock() has 'with' support
|
2017-09-08 15:36:58 +08:00
|
|
|
BLACKLIST_COUNT = 3
|
|
|
|
|
2015-04-10 22:33:04 +08:00
|
|
|
def __init__(self):
|
|
|
|
vmmGObject.__init__(self)
|
|
|
|
|
|
|
|
self._objects = []
|
2020-09-24 02:33:17 +08:00
|
|
|
self._denylist = {}
|
2015-04-10 22:33:04 +08:00
|
|
|
self._lock = threading.Lock()
|
|
|
|
|
|
|
|
def _cleanup(self):
|
2018-03-13 03:48:09 +08:00
|
|
|
self._objects = []
|
2015-04-10 22:33:04 +08:00
|
|
|
|
2020-09-24 02:33:17 +08:00
|
|
|
def _denylist_key(self, obj):
|
2020-09-02 00:35:26 +08:00
|
|
|
return str(obj.__class__) + obj.get_name()
|
2015-09-18 03:48:42 +08:00
|
|
|
|
2020-09-24 02:33:17 +08:00
|
|
|
def add_denylist(self, obj):
|
2015-09-18 03:48:42 +08:00
|
|
|
"""
|
2020-09-24 02:33:17 +08:00
|
|
|
Add an object to the denylist. Basically a list of objects we
|
2015-09-18 03:48:42 +08:00
|
|
|
choose not to poll, because they threw an error at init time
|
|
|
|
|
2020-09-24 02:33:17 +08:00
|
|
|
:param obj: vmmLibvirtObject to denylist
|
2017-09-08 15:36:58 +08:00
|
|
|
:returns: number of added object to list
|
2015-09-18 03:48:42 +08:00
|
|
|
"""
|
2020-09-24 02:33:17 +08:00
|
|
|
key = self._denylist_key(obj)
|
|
|
|
count = self._denylist.get(key, 0)
|
|
|
|
self._denylist[key] = count + 1
|
|
|
|
return self._denylist[key]
|
2017-09-08 15:36:58 +08:00
|
|
|
|
2020-09-24 02:33:17 +08:00
|
|
|
def remove_denylist(self, obj):
|
2017-09-08 15:36:58 +08:00
|
|
|
"""
|
2020-09-24 02:33:17 +08:00
|
|
|
:param obj: vmmLibvirtObject to remove from denylist
|
|
|
|
:returns: True if object was denylisted or False otherwise.
|
2017-09-08 15:36:58 +08:00
|
|
|
"""
|
2020-09-24 02:33:17 +08:00
|
|
|
key = self._denylist_key(obj)
|
|
|
|
return bool(self._denylist.pop(key, 0))
|
2015-09-18 03:48:42 +08:00
|
|
|
|
2020-09-24 02:33:17 +08:00
|
|
|
def in_denylist(self, obj):
|
2015-09-18 03:48:42 +08:00
|
|
|
"""
|
2020-09-24 02:33:17 +08:00
|
|
|
If an object is in list only once don't consider it denylisted,
|
2017-09-08 15:36:58 +08:00
|
|
|
give it one more chance.
|
|
|
|
|
2015-09-18 03:48:42 +08:00
|
|
|
:param obj: vmmLibvirtObject to check
|
2020-09-24 02:33:17 +08:00
|
|
|
:returns: True if object is denylisted
|
2015-09-18 03:48:42 +08:00
|
|
|
"""
|
2020-09-24 02:33:17 +08:00
|
|
|
key = self._denylist_key(obj)
|
|
|
|
return self._denylist.get(key, 0) >= _ObjectList.BLACKLIST_COUNT
|
2015-09-18 03:48:42 +08:00
|
|
|
|
2015-04-10 22:33:04 +08:00
|
|
|
def remove(self, obj):
|
|
|
|
"""
|
|
|
|
Remove an object from the list.
|
|
|
|
|
|
|
|
:param obj: vmmLibvirtObject to remove
|
|
|
|
:returns: True if object removed, False if object was not found
|
|
|
|
"""
|
2018-03-13 03:48:09 +08:00
|
|
|
with self._lock:
|
2015-04-10 22:33:04 +08:00
|
|
|
# Identity check is sufficient here, since we should never be
|
|
|
|
# asked to remove an object that wasn't at one point in the list.
|
|
|
|
if obj not in self._objects:
|
2020-09-24 02:33:17 +08:00
|
|
|
return self.remove_denylist(obj)
|
2015-04-10 22:33:04 +08:00
|
|
|
|
|
|
|
self._objects.remove(obj)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def add(self, obj):
|
|
|
|
"""
|
|
|
|
Add an object to the list.
|
|
|
|
|
|
|
|
:param obj: vmmLibvirtObject to add
|
|
|
|
:returns: True if object added, False if object already in the list
|
|
|
|
"""
|
2018-03-13 03:48:09 +08:00
|
|
|
with self._lock:
|
2015-04-10 22:33:04 +08:00
|
|
|
# We don't look up based on identity here, to prevent tick()
|
|
|
|
# races from adding the same domain twice
|
|
|
|
#
|
|
|
|
# We don't use lookup_object here since we need to hold the
|
|
|
|
# lock the whole time to prevent a 'time of check' issue
|
|
|
|
for checkobj in self._objects:
|
|
|
|
if (checkobj.__class__ == obj.__class__ and
|
2020-09-02 00:35:26 +08:00
|
|
|
checkobj.get_name() == obj.get_name()):
|
2015-04-10 22:33:04 +08:00
|
|
|
return False
|
|
|
|
|
|
|
|
self._objects.append(obj)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_objects_for_class(self, classobj):
|
|
|
|
"""
|
|
|
|
Return all objects over the passed vmmLibvirtObject class
|
|
|
|
"""
|
2018-03-13 03:48:09 +08:00
|
|
|
with self._lock:
|
2015-04-10 22:33:04 +08:00
|
|
|
return [o for o in self._objects if o.__class__ is classobj]
|
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
def lookup_object(self, classobj, name):
|
2015-04-10 22:33:04 +08:00
|
|
|
"""
|
2020-09-02 00:35:26 +08:00
|
|
|
Lookup an object with the passed classobj + name
|
2015-04-10 22:33:04 +08:00
|
|
|
"""
|
|
|
|
# Doesn't require locking, since get_objects_for_class covers us
|
|
|
|
for obj in self.get_objects_for_class(classobj):
|
2020-09-02 00:35:26 +08:00
|
|
|
if obj.get_name() == name:
|
2015-04-10 22:33:04 +08:00
|
|
|
return obj
|
|
|
|
return None
|
|
|
|
|
2018-03-13 03:48:09 +08:00
|
|
|
def all_objects(self):
|
|
|
|
with self._lock:
|
|
|
|
return self._objects[:]
|
|
|
|
|
2015-04-10 22:33:04 +08:00
|
|
|
|
2010-12-10 01:37:48 +08:00
|
|
|
class vmmConnection(vmmGObject):
|
2012-05-14 21:24:56 +08:00
|
|
|
__gsignals__ = {
|
2020-09-01 23:54:10 +08:00
|
|
|
"vm-added": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"vm-removed": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"net-added": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"net-removed": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"pool-added": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"pool-removed": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"nodedev-added": (vmmGObject.RUN_FIRST, None, [object]),
|
|
|
|
"nodedev-removed": (vmmGObject.RUN_FIRST, None, [object]),
|
2018-03-15 20:10:09 +08:00
|
|
|
"resources-sampled": (vmmGObject.RUN_FIRST, None, []),
|
|
|
|
"state-changed": (vmmGObject.RUN_FIRST, None, []),
|
2018-03-16 09:22:14 +08:00
|
|
|
"open-completed": (vmmGObject.RUN_FIRST, None, [object]),
|
2012-05-14 21:24:56 +08:00
|
|
|
}
|
2006-06-15 01:52:46 +08:00
|
|
|
|
2014-09-12 06:16:21 +08:00
|
|
|
(_STATE_DISCONNECTED,
|
|
|
|
_STATE_CONNECTING,
|
|
|
|
_STATE_ACTIVE) = range(1, 4)
|
2007-09-10 10:57:24 +08:00
|
|
|
|
2013-07-04 01:56:43 +08:00
|
|
|
def __init__(self, uri):
|
2011-05-04 01:11:33 +08:00
|
|
|
self._uri = uri
|
2018-03-15 19:43:56 +08:00
|
|
|
vmmGObject.__init__(self)
|
|
|
|
|
2014-09-12 06:16:21 +08:00
|
|
|
self._state = self._STATE_DISCONNECTED
|
2018-03-21 00:18:35 +08:00
|
|
|
self._backend = virtinst.VirtinstConnection(self._uri)
|
2014-04-16 22:32:52 +08:00
|
|
|
self._closing = False
|
2009-11-20 06:38:43 +08:00
|
|
|
|
2018-03-16 09:22:14 +08:00
|
|
|
# Error strings are stored here if open() fails
|
|
|
|
self.connect_error = None
|
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
self._init_object_count = None
|
|
|
|
self._init_object_event = None
|
|
|
|
|
2014-02-12 01:07:13 +08:00
|
|
|
self.using_domain_events = False
|
2014-04-01 00:43:49 +08:00
|
|
|
self._domain_cb_ids = []
|
2014-02-12 02:19:15 +08:00
|
|
|
self.using_network_events = False
|
2014-04-01 00:43:49 +08:00
|
|
|
self._network_cb_ids = []
|
2016-06-15 05:52:40 +08:00
|
|
|
self.using_storage_pool_events = False
|
|
|
|
self._storage_pool_cb_ids = []
|
2016-08-11 22:10:09 +08:00
|
|
|
self.using_node_device_events = False
|
|
|
|
self._node_device_cb_ids = []
|
2010-02-26 08:35:01 +08:00
|
|
|
|
|
|
|
self._xml_flags = {}
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2015-04-10 22:33:04 +08:00
|
|
|
self._objects = _ObjectList()
|
2018-10-05 22:54:25 +08:00
|
|
|
self.statsmanager = vmmStatsManager()
|
2015-04-10 22:33:04 +08:00
|
|
|
|
2015-05-05 06:16:09 +08:00
|
|
|
self._stats = []
|
|
|
|
self._hostinfo = None
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2015-04-12 01:39:25 +08:00
|
|
|
self.add_gsettings_handle(
|
|
|
|
self._on_config_pretty_name_changed(
|
|
|
|
self._config_pretty_name_changed_cb))
|
|
|
|
|
2013-07-08 06:54:08 +08:00
|
|
|
self._init_virtconn()
|
|
|
|
|
2013-07-05 20:59:58 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
@staticmethod
|
|
|
|
def pretty_hv(gtype, domtype):
|
|
|
|
"""
|
|
|
|
Convert XML <domain type='foo'> and <os><type>bar</type>
|
|
|
|
into a more human relevant string.
|
|
|
|
"""
|
|
|
|
|
|
|
|
gtype = gtype.lower()
|
|
|
|
domtype = domtype.lower()
|
|
|
|
|
|
|
|
label = domtype
|
2015-04-04 04:25:57 +08:00
|
|
|
if domtype == "xen":
|
2014-01-27 06:42:24 +08:00
|
|
|
if gtype == "xen":
|
|
|
|
label = "xen (paravirt)"
|
|
|
|
elif gtype == "hvm":
|
|
|
|
label = "xen (fullvirt)"
|
|
|
|
elif domtype == "test":
|
|
|
|
if gtype == "xen":
|
|
|
|
label = "test (xen)"
|
|
|
|
elif gtype == "hvm":
|
|
|
|
label = "test (hvm)"
|
2015-09-15 06:31:56 +08:00
|
|
|
elif domtype == "qemu":
|
|
|
|
label = "QEMU TCG"
|
|
|
|
elif domtype == "kvm":
|
|
|
|
label = "KVM"
|
2014-01-27 06:42:24 +08:00
|
|
|
|
|
|
|
return label
|
|
|
|
|
2018-03-15 19:43:56 +08:00
|
|
|
def __repr__(self):
|
2020-07-05 06:02:00 +08:00
|
|
|
# pylint: disable=arguments-differ
|
2018-03-15 19:43:56 +08:00
|
|
|
return "<%s uri=%s id=%s>" % (
|
|
|
|
self.__class__.__name__, self.get_uri(), hex(id(self)))
|
|
|
|
|
|
|
|
|
2009-11-26 06:07:12 +08:00
|
|
|
#################
|
|
|
|
# Init routines #
|
|
|
|
#################
|
|
|
|
|
2017-07-18 04:21:13 +08:00
|
|
|
def _wait_for_condition(self, compare_cb, timeout=3):
|
|
|
|
"""
|
|
|
|
Wait for this object to emit the specified signal. Will not
|
|
|
|
block the mainloop.
|
|
|
|
"""
|
|
|
|
from gi.repository import Gtk
|
|
|
|
is_main_thread = (threading.current_thread().name == "MainThread")
|
|
|
|
start_time = time.time()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
cur_time = time.time()
|
|
|
|
if compare_cb():
|
|
|
|
return
|
|
|
|
if (cur_time - start_time) >= timeout:
|
2020-09-03 03:28:12 +08:00
|
|
|
return # pragma: no cover
|
2017-07-18 04:21:13 +08:00
|
|
|
|
|
|
|
if is_main_thread:
|
|
|
|
if Gtk.events_pending():
|
|
|
|
Gtk.main_iteration_do(False)
|
|
|
|
continue
|
|
|
|
|
|
|
|
time.sleep(.1)
|
|
|
|
|
2013-07-08 06:54:08 +08:00
|
|
|
def _init_virtconn(self):
|
2018-09-01 03:20:50 +08:00
|
|
|
self._backend.cb_fetch_all_domains = (
|
2013-09-29 08:05:13 +08:00
|
|
|
lambda: [obj.get_xmlobj(refresh_if_nec=False)
|
2015-04-10 22:33:04 +08:00
|
|
|
for obj in self.list_vms()])
|
2013-09-29 08:05:13 +08:00
|
|
|
self._backend.cb_fetch_all_pools = (
|
|
|
|
lambda: [obj.get_xmlobj(refresh_if_nec=False)
|
2015-04-10 22:33:04 +08:00
|
|
|
for obj in self.list_pools()])
|
2014-09-20 23:30:24 +08:00
|
|
|
self._backend.cb_fetch_all_nodedevs = (
|
|
|
|
lambda: [obj.get_xmlobj(refresh_if_nec=False)
|
2015-04-10 22:33:04 +08:00
|
|
|
for obj in self.list_nodedevs()])
|
2014-02-28 02:16:21 +08:00
|
|
|
|
|
|
|
def fetch_all_vols():
|
|
|
|
ret = []
|
2015-04-10 22:33:04 +08:00
|
|
|
for pool in self.list_pools():
|
2015-04-11 00:52:42 +08:00
|
|
|
for vol in pool.get_volumes():
|
2014-02-28 02:16:21 +08:00
|
|
|
try:
|
|
|
|
ret.append(vol.get_xmlobj(refresh_if_nec=False))
|
2020-08-21 01:34:01 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Fetching volume XML failed: %s", e)
|
2014-02-28 02:16:21 +08:00
|
|
|
return ret
|
|
|
|
self._backend.cb_fetch_all_vols = fetch_all_vols
|
2013-09-29 08:05:13 +08:00
|
|
|
|
2017-07-20 04:11:17 +08:00
|
|
|
def cache_new_pool(obj):
|
2017-07-18 04:21:13 +08:00
|
|
|
if not self.is_active():
|
|
|
|
return
|
2017-07-20 04:11:17 +08:00
|
|
|
name = obj.name()
|
2017-07-18 04:21:13 +08:00
|
|
|
self.schedule_priority_tick(pollpool=True)
|
|
|
|
def compare_cb():
|
2020-09-02 00:35:26 +08:00
|
|
|
return bool(self.get_pool_by_name(name))
|
2017-07-18 04:21:13 +08:00
|
|
|
self._wait_for_condition(compare_cb)
|
2017-07-20 03:56:43 +08:00
|
|
|
self._backend.cb_cache_new_pool = cache_new_pool
|
2017-05-19 20:26:49 +08:00
|
|
|
|
2013-04-16 07:34:10 +08:00
|
|
|
|
2009-11-26 06:07:12 +08:00
|
|
|
########################
|
|
|
|
# General data getters #
|
|
|
|
########################
|
2009-11-26 05:12:03 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
def get_uri(self):
|
2011-05-04 01:11:33 +08:00
|
|
|
return self._uri
|
2013-07-05 20:59:58 +08:00
|
|
|
def get_backend(self):
|
|
|
|
return self._backend
|
2009-03-10 04:16:45 +08:00
|
|
|
|
2010-12-09 01:17:14 +08:00
|
|
|
def invalidate_caps(self):
|
2013-07-07 02:12:13 +08:00
|
|
|
return self._backend.invalidate_caps()
|
|
|
|
caps = property(lambda self: getattr(self, "_backend").caps)
|
2009-11-26 05:13:46 +08:00
|
|
|
|
|
|
|
def host_memory_size(self):
|
2018-09-26 17:00:57 +08:00
|
|
|
if not self._backend.is_open() or self._hostinfo is None:
|
2009-11-26 05:13:46 +08:00
|
|
|
return 0
|
2015-05-05 06:16:09 +08:00
|
|
|
return self._hostinfo[1] * 1024
|
2009-11-26 05:13:46 +08:00
|
|
|
|
|
|
|
def host_active_processor_count(self):
|
2018-09-26 17:00:57 +08:00
|
|
|
if not self._backend.is_open() or self._hostinfo is None:
|
2020-09-03 03:28:12 +08:00
|
|
|
return 0 # pragma: no cover
|
2015-05-05 06:16:09 +08:00
|
|
|
return self._hostinfo[2]
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2015-04-08 01:56:48 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
##########################
|
|
|
|
# URI + hostname helpers #
|
|
|
|
##########################
|
2009-11-16 04:17:03 +08:00
|
|
|
|
2015-04-16 23:21:34 +08:00
|
|
|
def libvirt_gethostname(self):
|
|
|
|
return self._backend.getHostname()
|
2006-11-06 23:34:54 +08:00
|
|
|
|
2013-07-06 08:36:28 +08:00
|
|
|
get_uri_hostname = property(lambda s:
|
2015-04-12 00:08:57 +08:00
|
|
|
getattr(s, "_backend").get_uri_hostname)
|
2015-04-12 00:57:32 +08:00
|
|
|
get_uri_username = property(lambda s:
|
|
|
|
getattr(s, "_backend").get_uri_username)
|
2015-04-12 00:08:57 +08:00
|
|
|
get_uri_transport = property(lambda s:
|
|
|
|
getattr(s, "_backend").get_uri_transport)
|
|
|
|
get_uri_port = property(lambda s: getattr(s, "_backend").get_uri_port)
|
2013-07-06 08:36:28 +08:00
|
|
|
get_driver = property(lambda s: getattr(s, "_backend").get_uri_driver)
|
2020-08-23 01:22:51 +08:00
|
|
|
is_container_only = property(
|
|
|
|
lambda s: getattr(s, "_backend").is_container_only)
|
2013-07-06 08:36:28 +08:00
|
|
|
is_lxc = property(lambda s: getattr(s, "_backend").is_lxc)
|
2017-03-13 20:01:51 +08:00
|
|
|
is_vz = property(lambda s: getattr(s, "_backend").is_vz)
|
2013-07-06 08:36:28 +08:00
|
|
|
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)
|
2020-02-03 08:43:06 +08:00
|
|
|
is_qemu_privileged = property(lambda s: getattr(s, "_backend").is_qemu_privileged)
|
|
|
|
is_qemu_unprivileged = property(lambda s:
|
|
|
|
getattr(s, "_backend").is_qemu_unprivileged)
|
2017-06-28 02:13:36 +08:00
|
|
|
is_test = property(lambda s: getattr(s, "_backend").is_test)
|
2020-02-03 08:43:06 +08:00
|
|
|
is_unprivileged = property(lambda s: getattr(s, "_backend").is_unprivileged)
|
2009-03-10 04:16:45 +08:00
|
|
|
|
2010-12-11 07:03:51 +08:00
|
|
|
|
2013-10-01 09:41:10 +08:00
|
|
|
def get_cache_dir(self):
|
|
|
|
uri = self.get_uri().replace("/", "_")
|
2019-06-08 05:50:58 +08:00
|
|
|
ret = os.path.join(self._backend.get_app_cache_dir(), uri)
|
2013-10-01 09:41:10 +08:00
|
|
|
if not os.path.exists(ret):
|
2020-09-03 03:28:12 +08:00
|
|
|
os.makedirs(ret, 0o755) # pragma: no cover
|
2013-10-01 09:41:10 +08:00
|
|
|
return ret
|
|
|
|
|
2013-10-03 03:17:15 +08:00
|
|
|
def get_default_storage_format(self):
|
|
|
|
raw = self.config.get_default_storage_format(raw=True)
|
|
|
|
if raw != "default":
|
2020-09-03 03:28:12 +08:00
|
|
|
return raw # pragma: no cover
|
2013-10-03 03:17:15 +08:00
|
|
|
|
|
|
|
fmt = self.config.get_default_storage_format()
|
|
|
|
if fmt != "qcow2":
|
2020-09-03 03:28:12 +08:00
|
|
|
return fmt # pragma: no cover
|
2013-10-03 03:17:15 +08:00
|
|
|
|
2019-06-08 04:06:52 +08:00
|
|
|
if self.support.conn_default_qcow2():
|
2013-10-03 03:17:15 +08:00
|
|
|
return fmt
|
2020-09-03 03:28:12 +08:00
|
|
|
return None # pragma: no cover
|
2010-02-11 09:26:40 +08:00
|
|
|
|
2014-02-11 07:47:58 +08:00
|
|
|
|
2013-07-07 02:12:13 +08:00
|
|
|
####################################
|
|
|
|
# Connection pretty print routines #
|
|
|
|
####################################
|
2010-02-11 09:26:40 +08:00
|
|
|
|
2015-04-12 00:57:32 +08:00
|
|
|
def get_pretty_desc(self):
|
2014-07-08 05:57:50 +08:00
|
|
|
"""
|
2015-04-12 00:57:32 +08:00
|
|
|
Return a pretty label for use in the manager view, and various
|
|
|
|
connection lists.
|
2014-07-08 05:57:50 +08:00
|
|
|
"""
|
2015-04-12 01:39:25 +08:00
|
|
|
if self._get_config_pretty_name():
|
|
|
|
return self._get_config_pretty_name()
|
2009-07-29 07:21:56 +08:00
|
|
|
|
2011-06-08 07:41:02 +08:00
|
|
|
pretty_map = {
|
2017-08-05 14:39:32 +08:00
|
|
|
"esx": "ESX",
|
|
|
|
"lxc": "LXC",
|
|
|
|
"openvz": "OpenVZ",
|
|
|
|
"qemu": "QEMU/KVM",
|
2020-08-29 23:53:19 +08:00
|
|
|
"vbox": "Virtualbox",
|
2017-08-05 14:39:32 +08:00
|
|
|
"vmware": "VMWare",
|
|
|
|
"xen": "Xen",
|
2011-06-08 07:41:02 +08:00
|
|
|
}
|
|
|
|
|
2015-04-12 00:57:32 +08:00
|
|
|
hv = pretty_map.get(self.get_driver(), self.get_driver())
|
|
|
|
hostname = self.get_uri_hostname()
|
|
|
|
path = self.get_backend().get_uri_path()
|
2014-07-08 05:57:50 +08:00
|
|
|
|
2015-04-12 00:57:32 +08:00
|
|
|
ret = hv
|
2010-12-12 12:51:20 +08:00
|
|
|
|
2020-02-03 08:43:06 +08:00
|
|
|
if path == "/session":
|
2016-02-05 23:18:16 +08:00
|
|
|
ret += " " + _("User session")
|
2015-09-16 07:30:09 +08:00
|
|
|
elif (path and path != "/system" and os.path.basename(path)):
|
2015-04-12 00:57:32 +08:00
|
|
|
# Used by test URIs to report what XML file they are using
|
|
|
|
ret += " %s" % os.path.basename(path)
|
2009-07-21 02:47:50 +08:00
|
|
|
|
2015-04-12 00:57:32 +08:00
|
|
|
if hostname:
|
2015-05-03 07:20:18 +08:00
|
|
|
ret += ": %s" % hostname
|
2013-07-17 05:15:51 +08:00
|
|
|
|
2015-04-12 00:57:32 +08:00
|
|
|
return ret
|
2009-07-21 02:47:50 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# API support helpers #
|
|
|
|
#######################
|
|
|
|
|
2019-06-08 04:06:52 +08:00
|
|
|
@property
|
|
|
|
def support(self):
|
|
|
|
return self._backend.support
|
2013-07-06 23:20:28 +08:00
|
|
|
|
2010-02-26 08:35:01 +08:00
|
|
|
def _get_flags_helper(self, obj, key, check_func):
|
2010-12-10 00:22:35 +08:00
|
|
|
ignore = obj
|
2010-02-26 08:35:01 +08:00
|
|
|
flags_dict = self._xml_flags.get(key)
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2012-11-08 21:15:02 +08:00
|
|
|
if flags_dict is None:
|
2010-02-26 08:35:01 +08:00
|
|
|
# Flags already set
|
|
|
|
inact, act = check_func()
|
|
|
|
flags_dict = {}
|
|
|
|
flags_dict["active"] = act
|
|
|
|
flags_dict["inactive"] = inact
|
|
|
|
|
|
|
|
self._xml_flags[key] = flags_dict
|
|
|
|
|
|
|
|
active_flags = flags_dict["active"]
|
|
|
|
inactive_flags = flags_dict["inactive"]
|
|
|
|
|
|
|
|
return (inactive_flags, active_flags)
|
|
|
|
|
|
|
|
def get_dom_flags(self, vm):
|
|
|
|
key = "domain"
|
|
|
|
|
|
|
|
def check_func():
|
|
|
|
act = 0
|
|
|
|
inact = 0
|
|
|
|
|
2019-06-08 04:06:52 +08:00
|
|
|
if self.support.domain_xml_inactive(vm):
|
2010-02-26 08:35:01 +08:00
|
|
|
inact = libvirt.VIR_DOMAIN_XML_INACTIVE
|
2020-08-21 01:34:01 +08:00
|
|
|
else: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Domain XML inactive flag not supported.")
|
2010-02-26 08:35:01 +08:00
|
|
|
|
2019-06-08 04:06:52 +08:00
|
|
|
if self.support.domain_xml_secure(vm):
|
2010-02-26 08:35:01 +08:00
|
|
|
inact |= libvirt.VIR_DOMAIN_XML_SECURE
|
|
|
|
act = libvirt.VIR_DOMAIN_XML_SECURE
|
2020-08-21 01:34:01 +08:00
|
|
|
else: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Domain XML secure flag not supported.")
|
2010-02-26 08:35:01 +08:00
|
|
|
|
|
|
|
return inact, act
|
|
|
|
|
|
|
|
return self._get_flags_helper(vm, key, check_func)
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def get_default_pool(self):
|
2019-07-03 07:44:10 +08:00
|
|
|
poolxml = virtinst.StoragePool.lookup_default_pool(self.get_backend())
|
2019-06-11 20:38:20 +08:00
|
|
|
if poolxml:
|
|
|
|
for p in self.list_pools():
|
|
|
|
if p.get_name() == poolxml.name:
|
|
|
|
return p
|
2014-06-03 05:17:47 +08:00
|
|
|
return None
|
|
|
|
|
|
|
|
def get_vol_by_path(self, path):
|
2015-04-10 22:33:04 +08:00
|
|
|
for pool in self.list_pools():
|
2015-04-11 00:52:42 +08:00
|
|
|
for vol in pool.get_volumes():
|
2014-12-05 09:38:55 +08:00
|
|
|
try:
|
|
|
|
if vol.get_target_path() == path:
|
|
|
|
return vol
|
2020-08-21 01:34:01 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2014-12-05 09:38:55 +08:00
|
|
|
# Errors can happen if the volume disappeared, bug 1092739
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error looking up volume from path=%s: %s",
|
2014-12-05 09:38:55 +08:00
|
|
|
path, e)
|
2014-06-03 05:17:47 +08:00
|
|
|
return None
|
|
|
|
|
2013-07-06 23:20:28 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
###################################
|
|
|
|
# Connection state getter/setters #
|
|
|
|
###################################
|
|
|
|
|
|
|
|
def _change_state(self, newstate):
|
2014-09-12 06:16:21 +08:00
|
|
|
if self._state != newstate:
|
|
|
|
self._state = newstate
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("conn=%s changed to state=%s",
|
2014-09-12 06:48:04 +08:00
|
|
|
self.get_uri(), self.get_state_text())
|
2009-11-26 05:13:46 +08:00
|
|
|
self.emit("state-changed")
|
|
|
|
|
2014-09-12 06:16:21 +08:00
|
|
|
def is_active(self):
|
|
|
|
return self._state == self._STATE_ACTIVE
|
|
|
|
def is_disconnected(self):
|
|
|
|
return self._state == self._STATE_DISCONNECTED
|
|
|
|
def is_connecting(self):
|
|
|
|
return self._state == self._STATE_CONNECTING
|
2009-11-26 05:13:46 +08:00
|
|
|
|
|
|
|
def get_state_text(self):
|
2014-09-12 06:16:21 +08:00
|
|
|
if self.is_disconnected():
|
2009-11-26 05:13:46 +08:00
|
|
|
return _("Disconnected")
|
2014-09-12 06:16:21 +08:00
|
|
|
elif self.is_connecting():
|
2009-11-26 05:13:46 +08:00
|
|
|
return _("Connecting")
|
2020-08-21 01:34:01 +08:00
|
|
|
return _("Active")
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
#################################
|
|
|
|
# Libvirt object lookup methods #
|
|
|
|
#################################
|
2006-06-15 02:36:26 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
def get_vm_by_name(self, name):
|
|
|
|
return self._objects.lookup_object(vmmDomain, name)
|
2014-06-03 05:17:47 +08:00
|
|
|
def list_vms(self):
|
2015-04-10 22:33:04 +08:00
|
|
|
return self._objects.get_objects_for_class(vmmDomain)
|
2014-06-03 05:17:47 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
def get_net_by_name(self, name):
|
|
|
|
return self._objects.lookup_object(vmmNetwork, name)
|
2014-06-03 05:17:47 +08:00
|
|
|
def list_nets(self):
|
2015-04-10 22:33:04 +08:00
|
|
|
return self._objects.get_objects_for_class(vmmNetwork)
|
2014-06-03 05:17:47 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
def get_pool_by_name(self, name):
|
|
|
|
return self._objects.lookup_object(vmmStoragePool, name)
|
2014-06-03 05:17:47 +08:00
|
|
|
def list_pools(self):
|
2015-04-10 22:33:04 +08:00
|
|
|
return self._objects.get_objects_for_class(vmmStoragePool)
|
2014-06-03 05:17:47 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
def get_nodedev_by_name(self, name):
|
|
|
|
return self._objects.lookup_object(vmmNodeDevice, name)
|
2015-04-10 22:33:04 +08:00
|
|
|
def list_nodedevs(self):
|
|
|
|
return self._objects.get_objects_for_class(vmmNodeDevice)
|
2015-04-10 21:37:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
############################
|
|
|
|
# nodedev helper functions #
|
|
|
|
############################
|
|
|
|
|
2019-06-06 02:45:48 +08:00
|
|
|
def filter_nodedevs(self, devtype):
|
2009-03-10 04:20:23 +08:00
|
|
|
retdevs = []
|
2015-04-10 22:33:04 +08:00
|
|
|
for dev in self.list_nodedevs():
|
2015-06-07 02:20:21 +08:00
|
|
|
try:
|
|
|
|
xmlobj = dev.get_xmlobj()
|
2020-08-21 01:34:01 +08:00
|
|
|
except libvirt.libvirtError as e: # pragma: no cover
|
2015-06-09 23:41:39 +08:00
|
|
|
# Libvirt nodedev XML fetching can be busted
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1225771
|
|
|
|
if e.get_error_code() != libvirt.VIR_ERR_NO_NODE_DEVICE:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error fetching nodedev XML", exc_info=True)
|
2015-06-09 23:41:39 +08:00
|
|
|
continue
|
2015-06-07 02:20:21 +08:00
|
|
|
|
2013-10-06 02:40:38 +08:00
|
|
|
if devtype and xmlobj.device_type != devtype:
|
2009-03-10 04:20:23 +08:00
|
|
|
continue
|
|
|
|
|
2015-04-08 02:12:00 +08:00
|
|
|
retdevs.append(dev)
|
2009-03-10 04:20:23 +08:00
|
|
|
return retdevs
|
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
|
|
|
|
###################################
|
|
|
|
# Libvirt object creation methods #
|
|
|
|
###################################
|
|
|
|
|
2013-09-30 00:14:00 +08:00
|
|
|
def define_domain(self, xml):
|
|
|
|
return self._backend.defineXML(xml)
|
|
|
|
def define_network(self, xml):
|
|
|
|
return self._backend.networkDefineXML(xml)
|
|
|
|
def define_pool(self, xml):
|
|
|
|
return self._backend.storagePoolDefineXML(xml, 0)
|
2009-12-12 02:45:53 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
def rename_object(self, obj, origxml, newxml):
|
2018-10-14 05:21:22 +08:00
|
|
|
if obj.is_domain():
|
2014-09-21 04:55:11 +08:00
|
|
|
define_cb = self.define_domain
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_pool():
|
2014-09-21 04:55:11 +08:00
|
|
|
define_cb = self.define_pool
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_network():
|
2014-09-21 04:55:11 +08:00
|
|
|
define_cb = self.define_network
|
|
|
|
else:
|
2020-07-18 06:58:00 +08:00
|
|
|
raise virtinst.xmlutil.DevError("rename_object "
|
2014-09-21 04:55:11 +08:00
|
|
|
"helper doesn't support object class %s" % obj.__class__)
|
|
|
|
|
2013-09-30 00:14:00 +08:00
|
|
|
# Undefine the original object
|
2013-10-01 03:23:14 +08:00
|
|
|
obj.delete(force=False)
|
2011-03-24 04:56:12 +08:00
|
|
|
|
|
|
|
newobj = None
|
|
|
|
try:
|
2014-09-21 04:55:11 +08:00
|
|
|
# Redefine new domain
|
|
|
|
newobj = define_cb(newxml)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as renameerr:
|
2011-03-24 04:56:12 +08:00
|
|
|
try:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error defining new name %s XML",
|
2015-04-10 21:15:44 +08:00
|
|
|
obj.class_name(), exc_info=True)
|
2014-09-21 04:55:11 +08:00
|
|
|
newobj = define_cb(origxml)
|
2020-09-03 03:28:12 +08:00
|
|
|
except Exception as fixerr: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Failed to redefine original %s!",
|
2015-04-10 21:15:44 +08:00
|
|
|
obj.class_name(), exc_info=True)
|
2020-07-14 15:41:49 +08:00
|
|
|
msg = _("%(object)s rename failed. Attempting to recover also "
|
|
|
|
"failed.\n"
|
|
|
|
"\n"
|
|
|
|
"Original error: %(origerror)s\n"
|
|
|
|
"\n"
|
2020-07-15 20:48:56 +08:00
|
|
|
"Recover error: %(recovererror)s") % {
|
2020-07-14 15:41:49 +08:00
|
|
|
"object": obj.class_name(),
|
|
|
|
"origerror": str(renameerr),
|
|
|
|
"recovererror": str(fixerr),
|
|
|
|
}
|
2020-09-16 00:33:31 +08:00
|
|
|
raise RuntimeError(msg) from None
|
2014-09-21 04:55:11 +08:00
|
|
|
raise
|
2011-03-24 04:56:12 +08:00
|
|
|
finally:
|
|
|
|
if newobj:
|
2013-09-30 00:14:00 +08:00
|
|
|
# Reinsert handle into new obj
|
|
|
|
obj.change_name_backend(newobj)
|
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2014-02-12 01:07:13 +08:00
|
|
|
#########################
|
|
|
|
# Domain event handling #
|
|
|
|
#########################
|
|
|
|
|
|
|
|
# Our strategy here isn't the most efficient: since we need to keep the
|
|
|
|
# poll helpers around for compat with old libvirt, switching to a fully
|
|
|
|
# event driven setup is hard, so we end up doing more polling than
|
|
|
|
# necessary on most events.
|
|
|
|
|
2014-04-01 00:43:49 +08:00
|
|
|
def _domain_xml_misc_event(self, conn, domain, *args):
|
|
|
|
# Just trigger a domain XML refresh for hotplug type events
|
|
|
|
ignore = conn
|
2018-02-28 00:56:18 +08:00
|
|
|
args = list(args)
|
|
|
|
eventstr = args.pop(-1)
|
2014-04-01 00:43:49 +08:00
|
|
|
|
2015-04-14 06:02:16 +08:00
|
|
|
name = domain.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("domain xmlmisc event: domain=%s event=%s args=%s",
|
2018-02-28 00:56:18 +08:00
|
|
|
name, eventstr, args)
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_vm_by_name(name)
|
2020-09-03 03:28:12 +08:00
|
|
|
if obj:
|
|
|
|
self.idle_add(obj.recache_from_event_loop)
|
2014-04-01 00:43:49 +08:00
|
|
|
|
2018-02-28 00:57:29 +08:00
|
|
|
def _domain_lifecycle_event(self, conn, domain, state, reason, userdata):
|
2014-02-12 01:07:13 +08:00
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
2015-04-14 06:02:16 +08:00
|
|
|
|
|
|
|
name = domain.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("domain lifecycle event: domain=%s %s", name,
|
2018-02-28 00:57:29 +08:00
|
|
|
LibvirtEnumMap.domain_lifecycle_str(state, reason))
|
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_vm_by_name(name)
|
2014-02-12 01:07:13 +08:00
|
|
|
|
2014-02-12 02:19:15 +08:00
|
|
|
if obj:
|
2016-06-24 02:48:04 +08:00
|
|
|
self.idle_add(obj.recache_from_event_loop)
|
2014-02-12 01:07:13 +08:00
|
|
|
else:
|
|
|
|
self.schedule_priority_tick(pollvm=True, force=True)
|
|
|
|
|
2018-07-04 16:10:37 +08:00
|
|
|
def _domain_agent_lifecycle_event(self, conn, domain, state, reason, userdata):
|
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
|
|
|
|
|
|
|
name = domain.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("domain agent lifecycle event: domain=%s %s", name,
|
2018-07-04 16:10:37 +08:00
|
|
|
LibvirtEnumMap.domain_agent_lifecycle_str(state, reason))
|
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_vm_by_name(name)
|
2018-07-04 16:10:38 +08:00
|
|
|
|
|
|
|
if obj:
|
|
|
|
self.idle_add(obj.recache_from_event_loop)
|
|
|
|
else:
|
2020-09-03 03:28:12 +08:00
|
|
|
self.schedule_priority_tick(pollvm=True, force=True) # pragma: no cover
|
2018-07-04 16:10:38 +08:00
|
|
|
|
2018-02-28 00:57:29 +08:00
|
|
|
def _network_lifecycle_event(self, conn, network, state, reason, userdata):
|
2014-02-12 02:19:15 +08:00
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
2015-04-14 06:02:16 +08:00
|
|
|
|
|
|
|
name = network.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("network lifecycle event: network=%s %s",
|
2018-02-28 00:57:29 +08:00
|
|
|
name, LibvirtEnumMap.network_lifecycle_str(state, reason))
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_net_by_name(name)
|
2014-02-12 02:19:15 +08:00
|
|
|
|
|
|
|
if obj:
|
2016-06-24 02:48:04 +08:00
|
|
|
self.idle_add(obj.recache_from_event_loop)
|
2014-02-12 02:19:15 +08:00
|
|
|
else:
|
|
|
|
self.schedule_priority_tick(pollnet=True, force=True)
|
2014-02-12 01:07:13 +08:00
|
|
|
|
2016-06-15 05:52:40 +08:00
|
|
|
def _storage_pool_lifecycle_event(self, conn, pool,
|
2018-02-28 00:57:29 +08:00
|
|
|
state, reason, userdata):
|
2016-06-15 05:52:40 +08:00
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
|
|
|
|
|
|
|
name = pool.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("storage pool lifecycle event: pool=%s %s",
|
2018-02-28 00:57:29 +08:00
|
|
|
name, LibvirtEnumMap.storage_lifecycle_str(state, reason))
|
2016-06-21 04:40:33 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_pool_by_name(name)
|
2016-06-15 05:52:40 +08:00
|
|
|
|
|
|
|
if obj:
|
2016-08-18 23:26:02 +08:00
|
|
|
self.idle_add(obj.recache_from_event_loop)
|
2016-06-15 05:52:40 +08:00
|
|
|
else:
|
|
|
|
self.schedule_priority_tick(pollpool=True, force=True)
|
|
|
|
|
2016-08-18 23:26:02 +08:00
|
|
|
def _storage_pool_refresh_event(self, conn, pool, userdata):
|
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
|
|
|
|
|
|
|
name = pool.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("storage pool refresh event: pool=%s", name)
|
2016-08-18 23:26:02 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_pool_by_name(name)
|
2016-08-18 23:26:02 +08:00
|
|
|
|
|
|
|
if not obj:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.idle_add(obj.refresh_pool_cache_from_event_loop)
|
|
|
|
|
2016-08-11 22:10:09 +08:00
|
|
|
def _node_device_lifecycle_event(self, conn, dev,
|
2018-02-28 00:57:29 +08:00
|
|
|
state, reason, userdata):
|
2016-08-11 22:10:09 +08:00
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
|
|
|
|
|
|
|
name = dev.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("node device lifecycle event: nodedev=%s %s",
|
2018-02-28 00:57:29 +08:00
|
|
|
name, LibvirtEnumMap.nodedev_lifecycle_str(state, reason))
|
2016-08-11 22:10:09 +08:00
|
|
|
|
|
|
|
self.schedule_priority_tick(pollnodedev=True, force=True)
|
|
|
|
|
2016-08-17 16:32:36 +08:00
|
|
|
def _node_device_update_event(self, conn, dev, userdata):
|
|
|
|
ignore = conn
|
|
|
|
ignore = userdata
|
|
|
|
|
|
|
|
name = dev.name()
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("node device update event: nodedev=%s", name)
|
2016-08-17 16:32:36 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
obj = self.get_nodedev_by_name(name)
|
2016-08-17 16:32:36 +08:00
|
|
|
|
|
|
|
if obj:
|
|
|
|
self.idle_add(obj.recache_from_event_loop)
|
|
|
|
|
2014-02-12 02:19:15 +08:00
|
|
|
def _add_conn_events(self):
|
2019-06-08 04:06:52 +08:00
|
|
|
if not self.support.conn_working_xen_events():
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2015-02-25 23:25:21 +08:00
|
|
|
|
2019-06-06 01:19:44 +08:00
|
|
|
def _check_events_disabled():
|
|
|
|
if self.config.CLITestOptions.no_events:
|
|
|
|
raise RuntimeError("events disabled via cli")
|
|
|
|
|
2014-02-12 01:07:13 +08:00
|
|
|
try:
|
2019-06-06 01:19:44 +08:00
|
|
|
_check_events_disabled()
|
2014-06-03 00:00:07 +08:00
|
|
|
|
2014-04-01 00:43:49 +08:00
|
|
|
self._domain_cb_ids.append(
|
|
|
|
self.get_backend().domainEventRegisterAny(
|
2014-02-12 02:27:59 +08:00
|
|
|
None, libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
|
2014-04-01 00:43:49 +08:00
|
|
|
self._domain_lifecycle_event, None))
|
2014-02-12 01:07:13 +08:00
|
|
|
self.using_domain_events = True
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Using domain events")
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-02-12 01:07:13 +08:00
|
|
|
self.using_domain_events = False
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error registering domain events: %s", e)
|
2014-02-12 01:07:13 +08:00
|
|
|
|
2018-07-04 16:10:35 +08:00
|
|
|
def _add_domain_xml_event(eventname, eventval, cb=None):
|
2014-04-01 00:43:49 +08:00
|
|
|
if not self.using_domain_events:
|
|
|
|
return
|
2018-07-04 16:10:35 +08:00
|
|
|
if not cb:
|
|
|
|
cb = self._domain_xml_misc_event
|
2014-04-01 00:43:49 +08:00
|
|
|
try:
|
2018-02-28 00:56:18 +08:00
|
|
|
eventid = getattr(libvirt, eventname, eventval)
|
2014-04-01 00:43:49 +08:00
|
|
|
self._domain_cb_ids.append(
|
|
|
|
self.get_backend().domainEventRegisterAny(
|
2018-07-04 16:10:35 +08:00
|
|
|
None, eventid, cb, eventname))
|
2020-09-03 01:38:48 +08:00
|
|
|
|
|
|
|
if (eventname == "VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE" and
|
|
|
|
self.config.CLITestOptions.fake_agent_event):
|
|
|
|
testmock.schedule_fake_agent_event(self, cb)
|
2020-08-21 01:34:01 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error registering %s event: %s",
|
2018-02-28 00:56:18 +08:00
|
|
|
eventname, e)
|
|
|
|
|
|
|
|
_add_domain_xml_event("VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE", 13)
|
|
|
|
_add_domain_xml_event("VIR_DOMAIN_EVENT_ID_TRAY_CHANGE", 10)
|
|
|
|
_add_domain_xml_event("VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED", 15)
|
|
|
|
_add_domain_xml_event("VIR_DOMAIN_EVENT_ID_DEVICE_ADDED", 19)
|
2018-07-04 16:10:37 +08:00
|
|
|
_add_domain_xml_event("VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE", 18,
|
|
|
|
self._domain_agent_lifecycle_event)
|
2022-02-08 22:12:38 +08:00
|
|
|
_add_domain_xml_event("VIR_DOMAIN_EVENT_ID_METADATA_CHANGE", 23)
|
2014-04-01 00:43:49 +08:00
|
|
|
|
2014-02-12 02:19:15 +08:00
|
|
|
try:
|
2019-06-06 01:19:44 +08:00
|
|
|
_check_events_disabled()
|
2014-06-03 00:00:07 +08:00
|
|
|
|
2014-03-22 23:21:19 +08:00
|
|
|
eventid = getattr(libvirt, "VIR_NETWORK_EVENT_ID_LIFECYCLE", 0)
|
2014-04-01 00:43:49 +08:00
|
|
|
self._network_cb_ids.append(
|
|
|
|
self.get_backend().networkEventRegisterAny(
|
|
|
|
None, eventid, self._network_lifecycle_event, None))
|
2014-02-12 02:19:15 +08:00
|
|
|
self.using_network_events = True
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Using network events")
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-02-12 02:19:15 +08:00
|
|
|
self.using_network_events = False
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error registering network events: %s", e)
|
2014-02-12 02:19:15 +08:00
|
|
|
|
2016-06-15 05:52:40 +08:00
|
|
|
try:
|
2019-06-06 01:19:44 +08:00
|
|
|
_check_events_disabled()
|
2016-06-15 05:52:40 +08:00
|
|
|
|
|
|
|
eventid = getattr(libvirt,
|
|
|
|
"VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE", 0)
|
2016-08-18 23:26:02 +08:00
|
|
|
refreshid = getattr(libvirt,
|
|
|
|
"VIR_STORAGE_POOL_EVENT_ID_REFRESH", 1)
|
2016-06-15 05:52:40 +08:00
|
|
|
self._storage_pool_cb_ids.append(
|
|
|
|
self.get_backend().storagePoolEventRegisterAny(
|
|
|
|
None, eventid, self._storage_pool_lifecycle_event, None))
|
2016-08-18 23:26:02 +08:00
|
|
|
self._storage_pool_cb_ids.append(
|
|
|
|
self.get_backend().storagePoolEventRegisterAny(
|
|
|
|
None, refreshid, self._storage_pool_refresh_event, None))
|
2016-06-15 05:52:40 +08:00
|
|
|
self.using_storage_pool_events = True
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Using storage pool events")
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2016-06-15 05:52:40 +08:00
|
|
|
self.using_storage_pool_events = False
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error registering storage pool events: %s", e)
|
2016-06-15 05:52:40 +08:00
|
|
|
|
2016-08-11 22:10:09 +08:00
|
|
|
try:
|
2019-06-06 01:19:44 +08:00
|
|
|
_check_events_disabled()
|
2016-08-11 22:10:09 +08:00
|
|
|
|
|
|
|
eventid = getattr(libvirt, "VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE", 0)
|
2016-08-17 16:32:36 +08:00
|
|
|
updateid = getattr(libvirt, "VIR_NODE_DEVICE_EVENT_ID_UPDATE", 1)
|
2020-09-03 01:38:48 +08:00
|
|
|
lifecycle_cb = self._node_device_lifecycle_event
|
|
|
|
update_cb = self._node_device_update_event
|
|
|
|
|
2016-08-11 22:10:09 +08:00
|
|
|
self._node_device_cb_ids.append(
|
|
|
|
self.get_backend().nodeDeviceEventRegisterAny(
|
2020-09-03 01:38:48 +08:00
|
|
|
None, eventid, lifecycle_cb, None))
|
2016-08-17 16:32:36 +08:00
|
|
|
self._node_device_cb_ids.append(
|
|
|
|
self.get_backend().nodeDeviceEventRegisterAny(
|
2020-09-03 01:38:48 +08:00
|
|
|
None, updateid, update_cb, None))
|
|
|
|
|
|
|
|
if self.config.CLITestOptions.fake_nodedev_event:
|
|
|
|
testmock.schedule_fake_nodedev_event(self,
|
|
|
|
lifecycle_cb, update_cb)
|
2016-08-17 16:32:36 +08:00
|
|
|
|
2016-08-11 22:10:09 +08:00
|
|
|
self.using_node_device_events = True
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Using node device events")
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2016-08-11 22:10:09 +08:00
|
|
|
self.using_network_events = False
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error registering node device events: %s", e)
|
2016-08-11 22:10:09 +08:00
|
|
|
|
2013-07-07 09:31:50 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
######################################
|
|
|
|
# Connection closing/opening methods #
|
|
|
|
######################################
|
|
|
|
|
2014-09-12 06:48:04 +08:00
|
|
|
def _schedule_close(self):
|
|
|
|
self._closing = True
|
|
|
|
self.idle_add(self.close)
|
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
def close(self):
|
2014-09-12 06:16:21 +08:00
|
|
|
if not self.is_disconnected():
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("conn.close() uri=%s", self.get_uri())
|
2014-04-16 22:32:52 +08:00
|
|
|
self._closing = True
|
|
|
|
|
2014-03-10 21:33:04 +08:00
|
|
|
try:
|
2020-01-29 00:42:33 +08:00
|
|
|
if self._backend.is_open():
|
2014-04-01 00:43:49 +08:00
|
|
|
for eid in self._domain_cb_ids:
|
|
|
|
self._backend.domainEventDeregisterAny(eid)
|
|
|
|
for eid in self._network_cb_ids:
|
|
|
|
self._backend.networkEventDeregisterAny(eid)
|
2016-06-15 05:52:40 +08:00
|
|
|
for eid in self._storage_pool_cb_ids:
|
|
|
|
self._backend.storagePoolEventDeregisterAny(eid)
|
2016-08-11 22:10:09 +08:00
|
|
|
for eid in self._node_device_cb_ids:
|
|
|
|
self._backend.nodeDeviceEventDeregisterAny(eid)
|
2020-08-21 01:34:01 +08:00
|
|
|
except Exception: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Failed to deregister events in conn cleanup",
|
2014-03-10 21:33:04 +08:00
|
|
|
exc_info=True)
|
2014-04-17 00:23:57 +08:00
|
|
|
finally:
|
|
|
|
self._domain_cb_ids = []
|
|
|
|
self._network_cb_ids = []
|
2016-06-15 05:52:40 +08:00
|
|
|
self._storage_pool_cb_ids = []
|
2016-08-11 22:10:09 +08:00
|
|
|
self._node_device_cb_ids = []
|
2014-02-12 02:27:59 +08:00
|
|
|
|
2015-05-05 06:16:09 +08:00
|
|
|
self._stats = []
|
2011-04-11 23:00:57 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
if self._init_object_event:
|
2020-09-03 03:28:12 +08:00
|
|
|
self._init_object_event.clear() # pragma: no cover
|
2015-04-11 02:08:25 +08:00
|
|
|
|
2018-03-13 03:48:09 +08:00
|
|
|
for obj in self._objects.all_objects():
|
|
|
|
self._objects.remove(obj)
|
|
|
|
try:
|
|
|
|
self._remove_object_signal(obj)
|
|
|
|
obj.cleanup()
|
2020-09-03 03:28:12 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Failed to cleanup %s: %s", obj, e)
|
2015-04-10 22:33:04 +08:00
|
|
|
self._objects.cleanup()
|
|
|
|
self._objects = _ObjectList()
|
2011-03-23 22:07:23 +08:00
|
|
|
|
2018-03-13 04:31:13 +08:00
|
|
|
closeret = self._backend.close()
|
2020-11-11 01:43:04 +08:00
|
|
|
if closeret == 1:
|
2020-08-21 01:34:01 +08:00
|
|
|
log.debug( # pragma: no cover
|
|
|
|
"LEAK: conn close() returned 1, "
|
2018-03-13 04:31:13 +08:00
|
|
|
"meaning refs may have leaked.")
|
|
|
|
|
2014-09-12 06:16:21 +08:00
|
|
|
self._change_state(self._STATE_DISCONNECTED)
|
2014-04-16 22:32:52 +08:00
|
|
|
self._closing = False
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
def _cleanup(self):
|
2011-04-13 21:27:02 +08:00
|
|
|
self.close()
|
|
|
|
|
2015-09-21 02:20:50 +08:00
|
|
|
self._objects = None
|
2018-09-01 03:20:50 +08:00
|
|
|
self._backend.cb_fetch_all_domains = None
|
2015-09-21 02:20:50 +08:00
|
|
|
self._backend.cb_fetch_all_pools = None
|
|
|
|
self._backend.cb_fetch_all_nodedevs = None
|
|
|
|
self._backend.cb_fetch_all_vols = None
|
2017-07-20 03:56:43 +08:00
|
|
|
self._backend.cb_cache_new_pool = None
|
2015-09-21 02:20:50 +08:00
|
|
|
|
2020-09-03 03:28:12 +08:00
|
|
|
self.statsmanager.cleanup()
|
|
|
|
self.statsmanager = None
|
|
|
|
|
2015-04-11 01:26:54 +08:00
|
|
|
def open(self):
|
2014-09-12 06:16:21 +08:00
|
|
|
if not self.is_disconnected():
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2007-09-10 10:57:24 +08:00
|
|
|
|
2014-09-12 06:16:21 +08:00
|
|
|
self._change_state(self._STATE_CONNECTING)
|
2007-09-11 08:56:01 +08:00
|
|
|
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Scheduling background open thread for %s",
|
2018-03-02 16:01:23 +08:00
|
|
|
self.get_uri())
|
2015-04-11 01:26:54 +08:00
|
|
|
self._start_thread(self._open_thread, "Connect %s" % self.get_uri())
|
2007-09-11 08:56:01 +08:00
|
|
|
|
2018-10-08 21:27:22 +08:00
|
|
|
def _do_open(self):
|
2014-09-12 06:48:04 +08:00
|
|
|
warnconsole = False
|
|
|
|
libvirt_error_code = None
|
|
|
|
libvirt_error_message = None
|
2017-12-21 03:15:56 +08:00
|
|
|
exc = None
|
2009-03-10 04:21:32 +08:00
|
|
|
|
2014-09-12 06:48:04 +08:00
|
|
|
try:
|
2020-09-03 02:17:54 +08:00
|
|
|
cb = connectauth.creds_dialog
|
|
|
|
data = self
|
|
|
|
if self.config.CLITestOptions.fake_openauth:
|
|
|
|
testmock.fake_openauth(self, cb, data)
|
2020-09-03 03:38:03 +08:00
|
|
|
if self.config.CLITestOptions.fake_session_error:
|
|
|
|
lerr = libvirt.libvirtError("fake session error")
|
|
|
|
lerr.err = [libvirt.VIR_ERR_AUTH_FAILED, None,
|
|
|
|
"fake session error not authorized"]
|
|
|
|
raise lerr
|
2020-09-03 02:17:54 +08:00
|
|
|
self._backend.open(cb, data)
|
2014-09-12 23:30:09 +08:00
|
|
|
return True, None
|
2017-12-21 03:15:56 +08:00
|
|
|
except Exception as e:
|
|
|
|
exc = e
|
2014-09-12 06:48:04 +08:00
|
|
|
tb = "".join(traceback.format_exc())
|
2016-04-19 04:42:12 +08:00
|
|
|
if isinstance(exc, libvirt.libvirtError):
|
|
|
|
# pylint: disable=no-member
|
2014-09-12 06:48:04 +08:00
|
|
|
libvirt_error_code = exc.get_error_code()
|
|
|
|
libvirt_error_message = exc.get_error_message()
|
|
|
|
|
|
|
|
if (libvirt_error_code ==
|
2020-09-03 03:28:12 +08:00
|
|
|
getattr(libvirt, "VIR_ERR_AUTH_CANCELLED", None)): # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("User cancelled auth, not raising any error.")
|
2014-09-12 23:30:09 +08:00
|
|
|
return False, None
|
2007-09-11 08:56:01 +08:00
|
|
|
|
2014-09-12 06:48:04 +08:00
|
|
|
if (libvirt_error_code == libvirt.VIR_ERR_AUTH_FAILED and
|
|
|
|
"not authorized" in libvirt_error_message.lower()):
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Looks like we might have failed policykit "
|
2014-09-12 06:48:04 +08:00
|
|
|
"auth. Checking to see if we have a valid "
|
|
|
|
"console session")
|
2020-09-03 03:38:03 +08:00
|
|
|
if not self.is_remote():
|
|
|
|
warnconsole = bool(not connectauth.do_we_have_session())
|
|
|
|
if self.config.CLITestOptions.fake_session_error:
|
2014-09-12 06:48:04 +08:00
|
|
|
warnconsole = True
|
|
|
|
|
2018-03-16 09:22:14 +08:00
|
|
|
ConnectError = connectauth.connect_error(
|
|
|
|
self, str(exc), tb, warnconsole)
|
|
|
|
return False, ConnectError
|
2014-09-12 06:48:04 +08:00
|
|
|
|
|
|
|
def _populate_initial_state(self):
|
2020-08-21 01:34:01 +08:00
|
|
|
if not self.support.conn_domain(): # pragma: no cover
|
2020-01-25 04:16:19 +08:00
|
|
|
raise RuntimeError("Connection does not support required "
|
|
|
|
"domain listing APIs")
|
|
|
|
|
2020-08-21 01:34:01 +08:00
|
|
|
if not self.support.conn_storage(): # pragma: no cover
|
2020-01-25 01:09:23 +08:00
|
|
|
log.debug("Connection doesn't seem to support storage APIs.")
|
2020-08-21 01:34:01 +08:00
|
|
|
if not self.support.conn_network(): # pragma: no cover
|
2020-01-25 01:09:23 +08:00
|
|
|
log.debug("Connection doesn't seem to support network APIs.")
|
2020-08-21 01:34:01 +08:00
|
|
|
if not self.support.conn_nodedev(): # pragma: no cover
|
2020-01-25 01:09:23 +08:00
|
|
|
log.debug("Connection doesn't seem to support nodedev APIs.")
|
2016-06-21 05:00:12 +08:00
|
|
|
|
2014-09-12 06:48:04 +08:00
|
|
|
self._add_conn_events()
|
2007-09-11 08:56:01 +08:00
|
|
|
|
2014-09-12 06:48:04 +08:00
|
|
|
try:
|
|
|
|
self._backend.setKeepAlive(20, 1)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2020-01-27 17:49:46 +08:00
|
|
|
log.debug("Failed to setKeepAlive: %s", str(e))
|
2009-07-12 09:23:16 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
# The initial tick will set up a threading event that will only
|
|
|
|
# trigger after all the polled libvirt objects are fully initialized.
|
|
|
|
# That way we only report the connection is open when everything is
|
|
|
|
# nicely setup for the rest of the app.
|
|
|
|
|
|
|
|
self._init_object_event = threading.Event()
|
|
|
|
self._init_object_count = 0
|
|
|
|
|
|
|
|
self.schedule_priority_tick(stats_update=True,
|
|
|
|
pollvm=True, pollnet=True,
|
2020-01-26 09:28:43 +08:00
|
|
|
pollpool=True, pollnodedev=True,
|
|
|
|
force=True, initial_poll=True)
|
2015-04-11 02:08:25 +08:00
|
|
|
|
|
|
|
self._init_object_event.wait()
|
|
|
|
self._init_object_event = None
|
|
|
|
self._init_object_count = None
|
|
|
|
|
2019-10-26 03:27:18 +08:00
|
|
|
# Try to create the default storage pool
|
|
|
|
# We need this after events setup so we can determine if the default
|
|
|
|
# pool already exists
|
|
|
|
try:
|
|
|
|
virtinst.StoragePool.build_default_pool(self.get_backend())
|
2020-08-21 01:34:01 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2019-10-26 03:27:18 +08:00
|
|
|
log.debug("Building default pool failed: %s", str(e))
|
|
|
|
|
2014-09-12 06:48:04 +08:00
|
|
|
def _open_thread(self):
|
2014-07-05 05:37:42 +08:00
|
|
|
try:
|
2018-03-16 09:22:14 +08:00
|
|
|
is_active, ConnectError = self._do_open()
|
2014-09-12 06:48:04 +08:00
|
|
|
if is_active:
|
|
|
|
self._populate_initial_state()
|
2020-09-03 03:28:12 +08:00
|
|
|
except Exception as e: # pragma: no cover
|
2014-09-12 06:48:04 +08:00
|
|
|
is_active = False
|
2018-03-16 09:22:14 +08:00
|
|
|
ConnectError = connectauth.connect_error(self, str(e),
|
|
|
|
"".join(traceback.format_exc()), False)
|
2010-11-25 03:01:51 +08:00
|
|
|
|
2020-09-03 03:28:12 +08:00
|
|
|
if is_active:
|
|
|
|
self.idle_add(self._change_state, self._STATE_ACTIVE)
|
|
|
|
else:
|
|
|
|
self._schedule_close()
|
|
|
|
|
2018-03-16 09:22:14 +08:00
|
|
|
self.idle_emit("open-completed", ConnectError)
|
2007-09-11 08:56:01 +08:00
|
|
|
|
2006-10-11 05:24:59 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
#######################
|
|
|
|
# Tick/Update methods #
|
|
|
|
#######################
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2018-03-13 03:48:09 +08:00
|
|
|
def _remove_object_signal(self, obj):
|
2018-10-14 05:21:22 +08:00
|
|
|
if obj.is_domain():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("vm-removed", obj)
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_network():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("net-removed", obj)
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_pool():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("pool-removed", obj)
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_nodedev():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("nodedev-removed", obj)
|
2018-03-13 03:48:09 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
def _gone_object_signals(self, gone_objects):
|
2015-04-10 22:33:04 +08:00
|
|
|
"""
|
|
|
|
Responsible for signaling the UI for any updates. All possible UI
|
|
|
|
updates need to go here to enable threading that doesn't block the
|
|
|
|
app with long tick operations.
|
|
|
|
"""
|
|
|
|
if not self._backend.is_open():
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2015-04-10 22:33:04 +08:00
|
|
|
|
2015-04-10 21:15:44 +08:00
|
|
|
for obj in gone_objects:
|
2015-04-11 02:08:25 +08:00
|
|
|
class_name = obj.class_name()
|
2020-09-03 03:28:12 +08:00
|
|
|
name = obj.get_name()
|
2015-04-11 02:08:25 +08:00
|
|
|
|
2015-04-10 22:33:04 +08:00
|
|
|
if not self._objects.remove(obj):
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Requested removal of %s=%s, but it's "
|
2015-05-08 00:30:28 +08:00
|
|
|
"not in our object list.", class_name, name)
|
2015-04-10 22:33:04 +08:00
|
|
|
continue
|
|
|
|
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("%s=%s removed", class_name, name)
|
2018-03-13 03:48:09 +08:00
|
|
|
self._remove_object_signal(obj)
|
2015-04-10 21:15:44 +08:00
|
|
|
obj.cleanup()
|
|
|
|
|
2018-03-13 03:57:36 +08:00
|
|
|
def _new_object_cb(self, obj, initialize_failed):
|
2015-04-11 02:08:25 +08:00
|
|
|
if not self._backend.is_open():
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2015-04-10 22:33:04 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
try:
|
2015-04-10 21:15:44 +08:00
|
|
|
class_name = obj.class_name()
|
2015-04-11 02:08:25 +08:00
|
|
|
|
2015-09-18 03:48:42 +08:00
|
|
|
if initialize_failed:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Blacklisting %s=%s", class_name, obj.get_name())
|
2020-09-24 02:33:17 +08:00
|
|
|
count = self._objects.add_denylist(obj)
|
|
|
|
log.debug("Object added in denylist, count=%d", count)
|
2015-09-18 03:48:42 +08:00
|
|
|
return
|
|
|
|
|
2020-09-24 02:33:17 +08:00
|
|
|
self._objects.remove_denylist(obj)
|
2015-04-11 02:08:25 +08:00
|
|
|
if not self._objects.add(obj):
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("New %s=%s requested, but it's already tracked.",
|
2015-04-11 02:08:25 +08:00
|
|
|
class_name, obj.get_name())
|
2020-09-09 00:27:38 +08:00
|
|
|
obj.cleanup()
|
2015-04-11 02:08:25 +08:00
|
|
|
return
|
|
|
|
|
2018-10-14 05:21:22 +08:00
|
|
|
if not obj.is_nodedev():
|
2015-04-10 21:15:44 +08:00
|
|
|
# Skip nodedev logging since it's noisy and not interesting
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("%s=%s status=%s added", class_name,
|
2015-04-10 21:15:44 +08:00
|
|
|
obj.get_name(), obj.run_status())
|
2018-10-14 05:21:22 +08:00
|
|
|
if obj.is_domain():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("vm-added", obj)
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_network():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("net-added", obj)
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_pool():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("pool-added", obj)
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_nodedev():
|
2020-09-01 23:54:10 +08:00
|
|
|
self.emit("nodedev-added", obj)
|
2015-04-11 02:08:25 +08:00
|
|
|
finally:
|
2018-03-13 03:57:36 +08:00
|
|
|
if self._init_object_event:
|
2015-04-11 02:08:25 +08:00
|
|
|
self._init_object_count -= 1
|
|
|
|
if self._init_object_count <= 0:
|
|
|
|
self._init_object_event.set()
|
2014-09-12 23:55:34 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
def _poll(self, initial_poll,
|
2020-01-26 09:28:43 +08:00
|
|
|
pollvm, pollnet, pollpool, pollnodedev):
|
2015-04-11 00:52:42 +08:00
|
|
|
"""
|
|
|
|
Helper called from tick() to do necessary polling and return
|
|
|
|
the relevant object lists
|
|
|
|
"""
|
|
|
|
gone_objects = []
|
|
|
|
preexisting_objects = []
|
|
|
|
|
2020-02-02 09:51:10 +08:00
|
|
|
def _process_objects(ptype):
|
|
|
|
if ptype == "nets":
|
|
|
|
dopoll = pollnet
|
|
|
|
objs = self.list_nets()
|
|
|
|
cls = vmmNetwork
|
|
|
|
pollcb = pollhelpers.fetch_nets
|
|
|
|
elif ptype == "pools":
|
|
|
|
dopoll = pollpool
|
|
|
|
objs = self.list_pools()
|
|
|
|
cls = vmmStoragePool
|
|
|
|
pollcb = pollhelpers.fetch_pools
|
|
|
|
elif ptype == "nodedevs":
|
|
|
|
dopoll = pollnodedev
|
|
|
|
objs = self.list_nodedevs()
|
|
|
|
cls = vmmNodeDevice
|
|
|
|
pollcb = pollhelpers.fetch_nodedevs
|
|
|
|
else:
|
|
|
|
dopoll = pollvm
|
|
|
|
objs = self.list_vms()
|
|
|
|
cls = vmmDomain
|
|
|
|
pollcb = pollhelpers.fetch_vms
|
|
|
|
|
2020-01-25 04:46:02 +08:00
|
|
|
|
2020-09-02 00:35:26 +08:00
|
|
|
keymap = dict((o.get_name(), o) for o in objs)
|
|
|
|
def cb(obj, name):
|
|
|
|
return cls(self, obj, name)
|
2020-02-02 09:51:10 +08:00
|
|
|
if dopoll:
|
|
|
|
gone, new, master = pollcb(self._backend, keymap, cb)
|
|
|
|
else:
|
|
|
|
gone, new, master = [], [], list(keymap.values())
|
2015-04-11 02:08:25 +08:00
|
|
|
|
|
|
|
if initial_poll:
|
|
|
|
self._init_object_count += len(new)
|
|
|
|
|
2015-04-11 00:52:42 +08:00
|
|
|
gone_objects.extend(gone)
|
|
|
|
preexisting_objects.extend([o for o in master if o not in new])
|
2020-09-24 02:33:17 +08:00
|
|
|
new = [n for n in new if not self._objects.in_denylist(n)]
|
2015-04-11 00:52:42 +08:00
|
|
|
return new
|
|
|
|
|
2020-02-02 09:51:10 +08:00
|
|
|
new_vms = _process_objects("vms")
|
|
|
|
new_nets = _process_objects("nets")
|
|
|
|
new_pools = _process_objects("pools")
|
|
|
|
new_nodedevs = _process_objects("nodedevs")
|
2015-04-11 02:08:25 +08:00
|
|
|
|
|
|
|
# Kick off one thread per object type to handle the initial
|
|
|
|
# XML fetching. Going any more fine grained then this probably
|
|
|
|
# won't be that useful due to libvirt's locking structure.
|
|
|
|
#
|
|
|
|
# Would prefer to start refreshing some objects before all polling
|
|
|
|
# is complete, but we need init_object_count to be fully accurate
|
|
|
|
# before we start initializing objects
|
2018-03-09 05:30:34 +08:00
|
|
|
|
|
|
|
if initial_poll and self._init_object_count == 0:
|
|
|
|
# If the connection doesn't have any objects, new_object_cb
|
|
|
|
# is never called and the event is never set, so let's do it here
|
|
|
|
self._init_object_event.set()
|
|
|
|
|
2020-01-26 09:28:43 +08:00
|
|
|
for newlist in [new_vms, new_nets, new_pools, new_nodedevs]:
|
2015-04-11 02:08:25 +08:00
|
|
|
if not newlist:
|
|
|
|
continue
|
|
|
|
|
|
|
|
def cb(lst):
|
|
|
|
for obj in lst:
|
|
|
|
obj.connect_once("initialized", self._new_object_cb)
|
|
|
|
obj.init_libvirt_state()
|
2015-04-11 00:52:42 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
self._start_thread(cb,
|
|
|
|
"refreshing xml for new %s" % newlist[0].class_name(),
|
|
|
|
args=(newlist,))
|
2015-04-11 00:52:42 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
return gone_objects, preexisting_objects
|
2015-04-11 00:52:42 +08:00
|
|
|
|
2015-04-14 04:56:46 +08:00
|
|
|
def _tick(self, stats_update=False,
|
2013-07-07 23:06:15 +08:00
|
|
|
pollvm=False, pollnet=False,
|
2020-01-26 09:28:43 +08:00
|
|
|
pollpool=False, pollnodedev=False,
|
2015-04-11 02:08:25 +08:00
|
|
|
force=False, initial_poll=False):
|
2014-02-12 01:07:13 +08:00
|
|
|
"""
|
|
|
|
main update function: polls for new objects, updates stats, ...
|
2015-04-11 00:52:42 +08:00
|
|
|
|
|
|
|
:param force: Perform the requested polling even if async events
|
2015-04-11 02:08:25 +08:00
|
|
|
are in use.
|
2014-02-12 01:07:13 +08:00
|
|
|
"""
|
2014-09-12 07:12:43 +08:00
|
|
|
if self._closing:
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2014-09-12 07:12:43 +08:00
|
|
|
if self.is_disconnected():
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2015-04-11 02:08:25 +08:00
|
|
|
if self.is_connecting() and not force:
|
2020-09-19 05:27:50 +08:00
|
|
|
return # pragma: no cover
|
2006-10-10 01:28:13 +08:00
|
|
|
|
2015-04-11 00:52:42 +08:00
|
|
|
# We need to set this before the event check, since stats polling
|
|
|
|
# is independent of events
|
2013-07-07 23:06:15 +08:00
|
|
|
if not pollvm:
|
|
|
|
stats_update = False
|
2014-02-12 02:19:15 +08:00
|
|
|
|
2014-02-12 01:07:13 +08:00
|
|
|
if self.using_domain_events and not force:
|
|
|
|
pollvm = False
|
2014-02-12 02:19:15 +08:00
|
|
|
if self.using_network_events and not force:
|
|
|
|
pollnet = False
|
2016-06-15 05:52:40 +08:00
|
|
|
if self.using_storage_pool_events and not force:
|
|
|
|
pollpool = False
|
2016-08-11 22:10:09 +08:00
|
|
|
if self.using_node_device_events and not force:
|
|
|
|
pollnodedev = False
|
2013-07-07 23:06:15 +08:00
|
|
|
|
2015-05-05 06:16:09 +08:00
|
|
|
self._hostinfo = self._backend.getInfo()
|
2018-10-11 04:59:55 +08:00
|
|
|
if stats_update:
|
|
|
|
self.statsmanager.cache_all_stats(self)
|
2008-10-07 01:21:06 +08:00
|
|
|
|
2015-04-11 02:08:25 +08:00
|
|
|
gone_objects, preexisting_objects = self._poll(
|
2020-01-26 09:28:43 +08:00
|
|
|
initial_poll, pollvm, pollnet, pollpool, pollnodedev)
|
2015-04-11 02:08:25 +08:00
|
|
|
self.idle_add(self._gone_object_signals, gone_objects)
|
2008-08-08 05:37:16 +08:00
|
|
|
|
2015-04-11 00:52:42 +08:00
|
|
|
# Only tick() pre-existing objects, since new objects will be
|
|
|
|
# initialized asynchronously and tick() would be redundant
|
|
|
|
for obj in preexisting_objects:
|
2009-09-17 04:02:19 +08:00
|
|
|
try:
|
2015-04-11 00:52:42 +08:00
|
|
|
if obj.reports_stats() and stats_update:
|
|
|
|
pass
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_domain() and not pollvm:
|
2015-04-11 00:52:42 +08:00
|
|
|
continue
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_network() and not pollnet:
|
2015-04-11 00:52:42 +08:00
|
|
|
continue
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_pool() and not pollpool:
|
2015-04-11 00:52:42 +08:00
|
|
|
continue
|
2018-10-14 05:21:22 +08:00
|
|
|
elif obj.is_nodedev() and not pollnodedev:
|
2015-04-11 00:52:42 +08:00
|
|
|
continue
|
|
|
|
|
2020-09-03 00:54:53 +08:00
|
|
|
if self.config.CLITestOptions.conn_crash:
|
|
|
|
self._backend.close()
|
|
|
|
e = libvirt.libvirtError("fake error")
|
|
|
|
e.err = [libvirt.VIR_ERR_SYSTEM_ERROR]
|
|
|
|
raise e
|
|
|
|
|
2015-04-10 21:15:44 +08:00
|
|
|
obj.tick(stats_update=stats_update)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.exception("Tick for %s failed", obj)
|
2012-01-30 00:26:24 +08:00
|
|
|
if (isinstance(e, libvirt.libvirtError) and
|
2012-02-01 08:07:32 +08:00
|
|
|
(getattr(e, "get_error_code")() ==
|
|
|
|
libvirt.VIR_ERR_SYSTEM_ERROR)):
|
2012-01-30 00:26:24 +08:00
|
|
|
# Try a simple getInfo call to see if conn was dropped
|
2013-07-05 20:59:58 +08:00
|
|
|
self._backend.getInfo()
|
2020-09-03 03:28:12 +08:00
|
|
|
log.debug( # pragma: no cover
|
|
|
|
"vm tick raised system error but "
|
|
|
|
"connection doesn't seem to have dropped. "
|
|
|
|
"Ignoring.")
|
2007-03-28 07:52:00 +08:00
|
|
|
|
2013-07-07 21:42:21 +08:00
|
|
|
if stats_update:
|
2015-04-11 00:52:42 +08:00
|
|
|
self._recalculate_stats(
|
|
|
|
[o for o in preexisting_objects if o.reports_stats()])
|
2011-04-18 23:12:36 +08:00
|
|
|
self.idle_emit("resources-sampled")
|
2009-07-12 09:23:16 +08:00
|
|
|
|
2013-07-07 20:12:15 +08:00
|
|
|
def _recalculate_stats(self, vms):
|
2013-07-05 20:59:58 +08:00
|
|
|
if not self._backend.is_open():
|
2020-08-21 01:34:01 +08:00
|
|
|
return # pragma: no cover
|
2010-02-12 04:25:41 +08:00
|
|
|
|
2013-07-07 20:12:15 +08:00
|
|
|
now = time.time()
|
2007-03-28 07:52:00 +08:00
|
|
|
expected = self.config.get_stats_history_length()
|
2015-05-05 06:16:09 +08:00
|
|
|
current = len(self._stats)
|
2007-03-28 07:52:00 +08:00
|
|
|
if current > expected:
|
2020-09-03 03:28:12 +08:00
|
|
|
del self._stats[expected:current] # pragma: no cover
|
2007-03-28 07:52:00 +08:00
|
|
|
|
|
|
|
mem = 0
|
|
|
|
cpuTime = 0
|
2008-10-19 03:21:33 +08:00
|
|
|
rdRate = 0
|
|
|
|
wrRate = 0
|
|
|
|
rxRate = 0
|
|
|
|
txRate = 0
|
2011-07-26 03:09:42 +08:00
|
|
|
diskMaxRate = self.disk_io_max_rate() or 10.0
|
|
|
|
netMaxRate = self.network_traffic_max_rate() or 10.0
|
2007-03-28 07:52:00 +08:00
|
|
|
|
2013-07-07 09:42:41 +08:00
|
|
|
for vm in vms:
|
2011-04-10 10:40:22 +08:00
|
|
|
if not vm.is_active():
|
|
|
|
continue
|
|
|
|
|
|
|
|
cpuTime += vm.cpu_time()
|
2011-04-10 12:02:39 +08:00
|
|
|
mem += vm.stats_memory()
|
2011-04-10 10:40:22 +08:00
|
|
|
rdRate += vm.disk_read_rate()
|
|
|
|
wrRate += vm.disk_write_rate()
|
|
|
|
rxRate += vm.network_rx_rate()
|
|
|
|
txRate += vm.network_tx_rate()
|
2007-03-28 07:52:00 +08:00
|
|
|
|
2011-07-26 03:09:42 +08:00
|
|
|
netMaxRate = max(netMaxRate, vm.network_traffic_max_rate())
|
|
|
|
diskMaxRate = max(diskMaxRate, vm.disk_io_max_rate())
|
|
|
|
|
2011-07-12 09:22:50 +08:00
|
|
|
pcentHostCpu = 0
|
|
|
|
pcentMem = mem * 100.0 / self.host_memory_size()
|
|
|
|
|
2015-05-05 06:16:09 +08:00
|
|
|
if len(self._stats) > 0:
|
|
|
|
prevTimestamp = self._stats[0]["timestamp"]
|
2010-12-11 00:47:07 +08:00
|
|
|
host_cpus = self.host_active_processor_count()
|
|
|
|
|
2011-07-12 09:22:50 +08:00
|
|
|
pcentHostCpu = ((cpuTime) * 100.0 /
|
2010-12-11 00:47:07 +08:00
|
|
|
((now - prevTimestamp) *
|
|
|
|
1000.0 * 1000.0 * 1000.0 * host_cpus))
|
2007-03-28 07:52:00 +08:00
|
|
|
|
2011-07-12 09:22:50 +08:00
|
|
|
pcentHostCpu = max(0.0, min(100.0, pcentHostCpu))
|
|
|
|
pcentMem = max(0.0, min(100.0, pcentMem))
|
2007-03-28 07:52:00 +08:00
|
|
|
|
|
|
|
newStats = {
|
|
|
|
"timestamp": now,
|
|
|
|
"memory": mem,
|
|
|
|
"memoryPercent": pcentMem,
|
|
|
|
"cpuTime": cpuTime,
|
2011-07-12 09:22:50 +08:00
|
|
|
"cpuHostPercent": pcentHostCpu,
|
2017-08-05 14:39:32 +08:00
|
|
|
"diskRdRate": rdRate,
|
|
|
|
"diskWrRate": wrRate,
|
|
|
|
"netRxRate": rxRate,
|
|
|
|
"netTxRate": txRate,
|
|
|
|
"diskMaxRate": diskMaxRate,
|
|
|
|
"netMaxRate": netMaxRate,
|
2007-03-28 07:52:00 +08:00
|
|
|
}
|
|
|
|
|
2015-05-05 06:16:09 +08:00
|
|
|
self._stats.insert(0, newStats)
|
2007-03-28 07:52:00 +08:00
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
|
2015-04-11 00:52:42 +08:00
|
|
|
def schedule_priority_tick(self, **kwargs):
|
2018-03-16 09:22:14 +08:00
|
|
|
from .engine import vmmEngine
|
|
|
|
vmmEngine.get_instance().schedule_priority_tick(self, kwargs)
|
2015-04-11 00:52:42 +08:00
|
|
|
|
2015-04-14 04:56:46 +08:00
|
|
|
def tick_from_engine(self, *args, **kwargs):
|
2015-04-11 00:52:42 +08:00
|
|
|
try:
|
|
|
|
self._tick(*args, **kwargs)
|
2020-09-03 00:53:25 +08:00
|
|
|
except Exception:
|
|
|
|
self._schedule_close()
|
|
|
|
raise
|
2015-04-11 00:52:42 +08:00
|
|
|
|
|
|
|
|
2009-11-26 05:13:46 +08:00
|
|
|
########################
|
|
|
|
# Stats getter methods #
|
|
|
|
########################
|
2012-05-14 21:24:56 +08:00
|
|
|
|
2015-05-05 04:33:56 +08:00
|
|
|
def _get_record_helper(self, record_name):
|
2015-05-05 06:16:09 +08:00
|
|
|
if len(self._stats) == 0:
|
2015-05-05 04:33:56 +08:00
|
|
|
return 0
|
2015-05-05 06:16:09 +08:00
|
|
|
return self._stats[0][record_name]
|
2015-05-05 04:33:56 +08:00
|
|
|
|
|
|
|
def _vector_helper(self, record_name, limit, ceil=100.0):
|
2007-03-28 07:52:00 +08:00
|
|
|
vector = []
|
2015-05-05 04:33:56 +08:00
|
|
|
statslen = self.config.get_stats_history_length() + 1
|
|
|
|
if limit is not None:
|
2020-09-03 03:28:12 +08:00
|
|
|
statslen = min(statslen, limit) # pragma: no cover
|
2015-05-05 04:33:56 +08:00
|
|
|
|
|
|
|
for i in range(statslen):
|
2015-05-05 06:16:09 +08:00
|
|
|
if i < len(self._stats):
|
|
|
|
vector.append(self._stats[i][record_name] / ceil)
|
2007-03-28 07:52:00 +08:00
|
|
|
else:
|
|
|
|
vector.append(0)
|
2013-04-12 20:26:21 +08:00
|
|
|
|
2015-05-05 04:33:56 +08:00
|
|
|
return vector
|
2011-04-15 00:20:02 +08:00
|
|
|
|
2015-05-05 04:33:56 +08:00
|
|
|
def stats_memory_vector(self, limit=None):
|
|
|
|
return self._vector_helper("memoryPercent", limit)
|
|
|
|
def host_cpu_time_vector(self, limit=None):
|
|
|
|
return self._vector_helper("cpuHostPercent", limit)
|
2011-04-15 00:20:02 +08:00
|
|
|
|
|
|
|
def stats_memory(self):
|
|
|
|
return self._get_record_helper("memory")
|
2011-07-12 09:22:50 +08:00
|
|
|
def host_cpu_time_percentage(self):
|
|
|
|
return self._get_record_helper("cpuHostPercent")
|
2015-05-05 04:33:56 +08:00
|
|
|
def guest_cpu_time_percentage(self):
|
|
|
|
return self.host_cpu_time_percentage()
|
2008-10-19 03:21:33 +08:00
|
|
|
def network_traffic_rate(self):
|
2015-05-05 04:33:56 +08:00
|
|
|
return (self._get_record_helper("netRxRate") +
|
|
|
|
self._get_record_helper("netTxRate"))
|
|
|
|
def disk_io_rate(self):
|
|
|
|
return (self._get_record_helper("diskRdRate") +
|
|
|
|
self._get_record_helper("diskWrRate"))
|
|
|
|
|
2011-07-26 03:09:42 +08:00
|
|
|
def network_traffic_max_rate(self):
|
|
|
|
return self._get_record_helper("netMaxRate")
|
|
|
|
def disk_io_max_rate(self):
|
|
|
|
return self._get_record_helper("diskMaxRate")
|
2015-04-12 01:39:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Per-conn config helpers #
|
|
|
|
###########################
|
|
|
|
|
|
|
|
def get_autoconnect(self):
|
|
|
|
return self.config.get_conn_autoconnect(self.get_uri())
|
|
|
|
def set_autoconnect(self, val):
|
|
|
|
self.config.set_conn_autoconnect(self.get_uri(), val)
|
|
|
|
|
|
|
|
def set_config_pretty_name(self, value):
|
2015-09-16 07:35:30 +08:00
|
|
|
cfgname = self._get_config_pretty_name()
|
|
|
|
if value == cfgname:
|
2020-09-03 03:28:12 +08:00
|
|
|
return # pragma: no cover
|
2015-09-16 07:35:30 +08:00
|
|
|
if not cfgname and value == self.get_pretty_desc():
|
|
|
|
# Don't encode the default connection value into gconf right
|
|
|
|
# away, require the user to edit it first
|
|
|
|
return
|
|
|
|
self.config.set_perconn(self.get_uri(), "/pretty-name", value)
|
2015-04-12 01:39:25 +08:00
|
|
|
def _get_config_pretty_name(self):
|
|
|
|
return self.config.get_perconn(self.get_uri(), "/pretty-name")
|
|
|
|
def _on_config_pretty_name_changed(self, *args, **kwargs):
|
|
|
|
return self.config.listen_perconn(self.get_uri(), "/pretty-name",
|
|
|
|
*args, **kwargs)
|
|
|
|
def _config_pretty_name_changed_cb(self):
|
|
|
|
self.emit("state-changed")
|
2019-04-14 02:52:17 +08:00
|
|
|
|
|
|
|
def set_details_window_size(self, w, h):
|
|
|
|
self.config.set_perconn(self.get_uri(), "/window-size", (w, h))
|
|
|
|
def get_details_window_size(self):
|
|
|
|
ret = self.config.get_perconn(self.get_uri(), "/window-size")
|
|
|
|
return ret
|