virt-manager/virtManager/storagepool.py

169 lines
5.0 KiB
Python
Raw Normal View History

#
# Copyright (C) 2008 Red Hat, Inc.
# Copyright (C) 2008 Cole Robinson <crobinso@redhat.com>
#
# 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 virtinst
# pylint: disable=E0611
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 17:24:56 +04:00
from gi.repository import GObject
# pylint: enable=E0611
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 17:24:56 +04:00
2011-04-11 01:08:23 +04:00
from virtManager import util
from virtManager.libvirtobject import vmmLibvirtObject
from virtManager.storagevol import vmmStorageVolume
class vmmStoragePool(vmmLibvirtObject):
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 17:24:56 +04:00
__gsignals__ = {
"refreshed": (GObject.SignalFlags.RUN_FIRST, None, [])
}
def __init__(self, conn, pool, uuid):
vmmLibvirtObject.__init__(self, conn)
self.pool = pool # Libvirt pool object
self.uuid = uuid # String UUID
self.active = True # bool indicating if it is running
self._volumes = {} # UUID->vmmStorageVolume mapping of the
# pools associated volumes
self._support_isactive = None
self.tick()
self.refresh()
# Required class methods
def get_name(self):
return self.pool.name()
def _XMLDesc(self, flags):
return self.pool.XMLDesc(flags)
def _define(self, xml):
return self.conn.get_backend().storagePoolDefineXML(xml, 0)
def set_active(self, state):
if state == self.active:
return
self.idle_emit(state and "started" or "stopped")
self.active = state
2010-12-10 17:57:42 +03:00
self.refresh_xml()
def is_active(self):
return self.active
def can_change_alloc(self):
typ = self.get_type()
return (typ in [virtinst.Storage.StoragePool.TYPE_LOGICAL])
def get_uuid(self):
return self.uuid
def start(self):
self.pool.create(0)
self.idle_add(self.refresh_xml)
def stop(self):
self.pool.destroy()
self.idle_add(self.refresh_xml)
def delete(self, nodelete=True):
if nodelete:
self.pool.undefine()
else:
self.pool.delete(0)
del(self.pool)
def set_autostart(self, value):
self.pool.setAutostart(value)
def get_autostart(self):
return self.pool.autostart()
def get_target_path(self):
return util.xpath(self.get_xml(), "/pool/target/path") or ""
def get_allocation(self):
2011-04-11 01:08:23 +04:00
return long(util.xpath(self.get_xml(), "/pool/allocation"))
def get_available(self):
2011-04-11 01:08:23 +04:00
return long(util.xpath(self.get_xml(), "/pool/available"))
def get_capacity(self):
2011-04-11 01:08:23 +04:00
return long(util.xpath(self.get_xml(), "/pool/capacity"))
def get_pretty_allocation(self):
2011-04-11 01:08:23 +04:00
return util.pretty_bytes(self.get_allocation())
def get_pretty_available(self):
2011-04-11 01:08:23 +04:00
return util.pretty_bytes(self.get_available())
def get_pretty_capacity(self):
2011-04-11 01:08:23 +04:00
return util.pretty_bytes(self.get_capacity())
def get_type(self):
2011-04-11 01:08:23 +04:00
return util.xpath(self.get_xml(), "/pool/@type")
def get_volumes(self):
self.update_volumes()
return self._volumes
def get_volume(self, uuid):
return self._volumes[uuid]
def _backend_get_active(self):
if self._support_isactive is None:
self._support_isactive = self.conn.check_pool_support(
self.pool,
self.conn.SUPPORT_STORAGE_ISACTIVE)
if not self._support_isactive:
return True
return bool(self.pool.isActive())
def tick(self):
self.set_active(self._backend_get_active())
def refresh(self):
2010-04-21 18:56:06 +04:00
if not self.active:
return
def cb():
self.refresh_xml()
self.update_volumes(refresh=True)
self.emit("refreshed")
2010-04-21 18:56:06 +04:00
self.pool.refresh(0)
self.idle_add(cb)
def update_volumes(self, refresh=False):
if not self.is_active():
self._volumes = {}
return
vols = self.pool.listVolumes()
new_vol_list = {}
for volname in vols:
if volname in self._volumes:
new_vol_list[volname] = self._volumes[volname]
if refresh:
new_vol_list[volname].refresh_xml()
else:
new_vol_list[volname] = vmmStorageVolume(self.conn,
self.pool.storageVolLookupByName(volname),
volname)
self._volumes = new_vol_list