~ubuntu-branches/ubuntu/precise/virtinst/precise-updates

« back to all changes in this revision

Viewing changes to virtinst/VirtualDevice.py

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-11 11:47:53 UTC
  • mfrom: (1.6.6 sid)
  • Revision ID: package-import@ubuntu.com-20120211114753-sq9f3xayrma8px2h
Tags: 0.600.1-1ubuntu1
* Merge from debian unstable. Remaining changes:
  - debian/patches/9003-fix-path-to-hvmloader-in-testsuite.patch: adjust
    testsuite for 0001-fix-path-to-hvmloader.patch and
    0002-Fix-path-to-pygrub.patch.
  - debian/patches/9004_ubuntu_fix_tree_support.patch: Fix tree detection
    for all ISO/HTTP source, to not longer fail with cobbler/koan.
  - debian/patches/9005_ubuntu_precise.patch: Add Ubuntu precise as a
    supported distro.
  - debian/{control,rules,pyversions}: Build using dh_python2, use
    debhelper v8 instead of cdbs; for some reason the package build an
    empty binary package when using dh_python2.
  - debian/control: added acl package to depends.
  - debian/control: added libvirt-bin to recommends

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from XMLBuilderDomain import XMLBuilderDomain, _xml_property
23
23
from virtinst import _gettext as _
 
24
import logging
24
25
 
25
26
class VirtualDevice(XMLBuilderDomain):
26
27
    """
42
43
    VIRTUAL_DEV_WATCHDOG        = "watchdog"
43
44
    VIRTUAL_DEV_FILESYSTEM      = "filesystem"
44
45
    VIRTUAL_DEV_SMARTCARD       = "smartcard"
 
46
    VIRTUAL_DEV_REDIRDEV        = "redirdev"
45
47
 
46
48
    # Ordering in this list is important: it will be the order the
47
49
    # Guest class outputs XML. So changing this may upset the test suite
59
61
                            VIRTUAL_DEV_VIDEO,
60
62
                            VIRTUAL_DEV_HOSTDEV,
61
63
                            VIRTUAL_DEV_WATCHDOG,
62
 
                            VIRTUAL_DEV_SMARTCARD]
 
64
                            VIRTUAL_DEV_SMARTCARD,
 
65
                            VIRTUAL_DEV_REDIRDEV]
63
66
 
64
67
    # General device type (disk, interface, etc.)
65
68
    _virtual_device_type = None
113
116
        ignore = meter
114
117
        return
115
118
 
 
119
    def set_address(self, addrstr):
 
120
        self.address = VirtualDeviceAddress(self.conn, addrstr=addrstr)
 
121
 
 
122
 
116
123
class VirtualDeviceAlias(XMLBuilderDomain):
117
124
    def __init__(self, conn, parsexml=None, parsexmlnode=None, caps=None):
118
125
        XMLBuilderDomain.__init__(self, conn, parsexml, parsexmlnode,
132
139
 
133
140
class VirtualDeviceAddress(XMLBuilderDomain):
134
141
 
135
 
    TYPES = ["pci", "drive", "virtio-serial", "ccid"]
136
 
 
137
 
    def __init__(self, conn, parsexml=None, parsexmlnode=None, caps=None):
 
142
    ADDRESS_TYPE_PCI           = "pci"
 
143
    ADDRESS_TYPE_DRIVE         = "drive"
 
144
    ADDRESS_TYPE_VIRTIO_SERIAL = "virtio-serial"
 
145
    ADDRESS_TYPE_CCID          = "ccid"
 
146
 
 
147
    TYPES = [ADDRESS_TYPE_PCI, ADDRESS_TYPE_DRIVE,
 
148
             ADDRESS_TYPE_VIRTIO_SERIAL, ADDRESS_TYPE_CCID]
 
149
 
 
150
    def __init__(self, conn, parsexml=None, parsexmlnode=None, caps=None, addrstr=None):
138
151
        XMLBuilderDomain.__init__(self, conn, parsexml, parsexmlnode,
139
152
                                  caps=caps)
140
153
 
160
173
        # CCID address:
161
174
        # <address type='ccid' controller='0' slot='0'/>
162
175
 
 
176
        if addrstr:
 
177
            self.parse_friendly_address(addrstr)
 
178
 
 
179
    def parse_friendly_address(self, addrstr):
 
180
        try:
 
181
            if addrstr.count(":") in [1, 2] and addrstr.count("."):
 
182
                self.type = self.ADDRESS_TYPE_PCI
 
183
                addrstr, self.function = addrstr.split(".", 1)
 
184
                addrstr, self.slot = addrstr.rsplit(":", 1)
 
185
                self.domain = "0"
 
186
                if addrstr.count(":"):
 
187
                    self.domain, self.bus = addrstr.split(":", 1)
 
188
            else:
 
189
                raise ValueError(_("Could not determine or unsupported format of '%s'") % addrstr)
 
190
        except:
 
191
            logging.exception("Error parsing address.")
 
192
            return None
 
193
 
 
194
 
163
195
    def clear(self):
164
196
        self._type = None
165
197
        self._bus = None
170
202
        self._unit = None
171
203
        self._port = None
172
204
 
173
 
        self._remove_child_xpath("./address")
 
205
        if self._is_parse():
 
206
            self._remove_child_xpath("./address")
174
207
 
175
208
    def _get_type(self):
176
209
        return self._type
223
256
    port = _xml_property(_get_port, _set_port, xpath="./address/@port")
224
257
 
225
258
    def _get_xml_config(self):
226
 
        return ""
 
259
        if not self.type:
 
260
            return
 
261
 
 
262
        xml = "<address type='%s'" % self.type
 
263
        if self.type == self.ADDRESS_TYPE_PCI:
 
264
            xml += " domain='%s' bus='%s' slot='%s' function='%s'" % (self.domain, self.bus, self.slot, self.function)
 
265
        elif self.type == self.ADDRESS_TYPE_DRIVE:
 
266
            xml += " controller='%s' bus='%s' unit='%s'" % (self.controller, self.bus, self.unit)
 
267
        elif self.type == self.ADDRESS_TYPE_VIRTIO_SERIAL:
 
268
            xml += " controller='%s' bus='%s' port='%s'" % (self.controller, self.bus, self.port)
 
269
        elif self.type == self.ADDRESS_TYPE_CCID:
 
270
            xml += " controller='%s' slot='%s'" % (self.controller, self.slot)
 
271
        xml += "/>"
 
272
        return xml