ia64/xen-unstable

changeset 12083:ea65d8be211f

[XEND] Refactoring device controllers to its own module so it can be used by both XendConfig and XendDomainInfo.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Thu Oct 05 17:29:19 2006 +0100 (2006-10-05)
parents 59f3891b94b8
children ec29b6262a8b
files tools/python/xen/xend/XendDevices.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/python/xen/xend/XendDevices.py	Thu Oct 05 17:29:19 2006 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +#===========================================================================
     1.5 +# This library is free software; you can redistribute it and/or
     1.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     1.7 +# License as published by the Free Software Foundation.
     1.8 +#
     1.9 +# This library is distributed in the hope that it will be useful,
    1.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.12 +# Lesser General Public License for more details.
    1.13 +#
    1.14 +# You should have received a copy of the GNU Lesser General Public
    1.15 +# License along with this library; if not, write to the Free Software
    1.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.17 +#============================================================================
    1.18 +# Copyright (C) 2006 XenSource Ltd
    1.19 +#============================================================================
    1.20 +
    1.21 +#
    1.22 +# A collection of DevControllers 
    1.23 +#
    1.24 +
    1.25 +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif
    1.26 +from xen.xend.server.BlktapController import BlktapController
    1.27 +
    1.28 +class XendDevices:
    1.29 +    """ An ugly halfway point between the module local device name
    1.30 +    to class map we used to have in XendDomainInfo and something
    1.31 +    slightly more managable.
    1.32 +
    1.33 +    This class should contain all the functions that have to do
    1.34 +    with managing devices in Xend. Right now it is only a factory
    1.35 +    function.
    1.36 +    """
    1.37 +
    1.38 +    controllers = {
    1.39 +        'vbd': blkif.BlkifController,
    1.40 +        'vif': netif.NetifController,
    1.41 +        'vtpm': tpmif.TPMifController,
    1.42 +        'pci': pciif.PciController,
    1.43 +        'ioports': iopif.IOPortsController,
    1.44 +        'irq': irqif.IRQController,
    1.45 +        'usb': usbif.UsbifController,
    1.46 +        'tap': BlktapController,
    1.47 +    }
    1.48 +
    1.49 +    #@classmethod
    1.50 +    def valid_devices(cls):
    1.51 +        return cls.controllers.keys()
    1.52 +    valid_devices = classmethod(valid_devices)
    1.53 +
    1.54 +    #@classmethod
    1.55 +    def make_controller(cls, name, domain):
    1.56 +        """Factory function to make device controllers per domain.
    1.57 +
    1.58 +        @param name: device class name in L{VALID_DEVICES}
    1.59 +        @type name: String
    1.60 +        @param domain: domain this controller is handling devices for.
    1.61 +        @type domain: XendDomainInfo
    1.62 +        @return: DevController of class 'name' or None
    1.63 +        @rtype: subclass of DevController
    1.64 +        """
    1.65 +        if name in cls.controllers.keys():
    1.66 +            cls.controllers[name].deviceClass = name
    1.67 +            return cls.controllers[name](domain)
    1.68 +        return None
    1.69 +
    1.70 +    make_controller = classmethod(make_controller)
    1.71 +