Add class wrapper for nodedev objects

This commit is contained in:
Cole Robinson 2011-04-09 19:32:30 -04:00
parent 2d5fc88cda
commit 6ba13a641d
3 changed files with 62 additions and 8 deletions

View File

@ -42,6 +42,7 @@ from virtManager.interface import vmmInterface
from virtManager.netdev import vmmNetDevice
from virtManager.mediadev import vmmMediaDevice
from virtManager.baseclass import vmmGObject
from virtManager.nodedev import vmmNodeDevice
class vmmConnection(vmmGObject):
__gsignals__ = {
@ -690,7 +691,8 @@ class vmmConnection(vmmGObject):
return self.nodedevs[name]
def get_nodedevs(self, devtype=None, devcap=None):
retdevs = []
for vdev in self.nodedevs.values():
for dev in self.nodedevs.values():
vdev = dev.get_virtinst_obj()
if devtype and vdev.device_type != devtype:
continue
@ -1355,12 +1357,11 @@ class vmmConnection(vmmGObject):
if key not in orig:
obj = self.vmm.nodeDeviceLookupByName(name)
vdev = virtinst.NodeDeviceParser.parse(obj.XMLDesc(0))
dev = vmmNodeDevice(self, obj, name)
# Object is brand new this tick period
current[key] = vdev
current[key] = dev
new.append(key)
else:
# Previously known object, remove it from the orig list
current[key] = orig[key]

View File

@ -40,7 +40,9 @@ class vmmMediaDevice(vmmGObject):
}
@staticmethod
def mediadev_from_nodedev(conn, nodedev):
def mediadev_from_nodedev(conn, dev):
nodedev = dev.get_virtinst_obj()
if nodedev.device_type != "storage":
return None
@ -54,9 +56,8 @@ class vmmMediaDevice(vmmGObject):
media_label = nodedev.media_label
media_key = None
nodedev_obj = conn.vmm.nodeDeviceLookupByName(key)
obj = vmmMediaDevice(path, key, has_media, media_label, media_key,
nodedev_obj, drvtype)
dev, drvtype)
obj.enable_poll_for_media()
return obj
@ -153,7 +154,8 @@ class vmmMediaDevice(vmmGObject):
return False
try:
xml = self.nodedev_obj.XMLDesc(0)
self.nodedev_obj.refresh_xml()
xml = self.nodedev_obj.get_xml()
except:
# Assume the device was removed
return False

View File

@ -0,0 +1,51 @@
#
# Copyright (C) 2011 Red Hat, Inc.
# Copyright (C) 2011 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 gobject
import logging
import virtinst
from virtManager.libvirtobject import vmmLibvirtObject
class vmmNodeDevice(vmmLibvirtObject):
__gsignals__ = {
}
def __init__(self, connection, backend, name):
vmmLibvirtObject.__init__(self, connection)
self.name = name
self._backend = backend
self._virtinst_obj = None
self.get_virtinst_obj()
def _XMLDesc(self, flags):
return self._backend.XMLDesc(flags)
def get_virtinst_obj(self):
if not self._virtinst_obj:
self._virtinst_obj = virtinst.NodeDeviceParser.parse(
self._backend.XMLDesc(0))
return self._virtinst_obj
vmmLibvirtObject.type_register(vmmNodeDevice)