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

« back to all changes in this revision

Viewing changes to virtinst/FullVirtGuest.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-01 15:40:11 UTC
  • mfrom: (1.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110201154011-op0nusgc240xajvb
Tags: 0.500.5-1ubuntu1
* Merge from debian experimental. Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Updated to add maverick and natty to OS list and enable virtio
       for them.
  - 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. (refreshed)
  - debian/control: added acl package to depends.
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin
* Removed patches:
  - debian/patches/9002-libvirt_disk_format.patch: Upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
20
# MA 02110-1301 USA.
21
21
 
22
 
import _util
23
 
import DistroInstaller
24
 
 
25
22
from Guest import Guest
26
 
from VirtualDevice import VirtualDevice
27
 
from VirtualDisk import VirtualDisk
28
 
from VirtualInputDevice import VirtualInputDevice
29
 
from VirtualCharDevice import VirtualCharDevice
30
23
 
31
24
class FullVirtGuest(Guest):
32
25
 
 
26
    _default_os_type = "hvm"
 
27
 
33
28
    def __init__(self, type=None, arch=None, connection=None,
34
 
                 hypervisorURI=None, emulator=None, installer=None):
35
 
        if not installer:
36
 
            installer = DistroInstaller.DistroInstaller(type = type,
37
 
                                                        os_type = "hvm",
38
 
                                                        conn=connection)
39
 
        Guest.__init__(self, type, connection, hypervisorURI, installer)
40
 
 
41
 
        self.disknode = "hd"
42
 
        self._diskbus = "ide"
43
 
 
44
 
        self.features = { "acpi": None, "pae":
45
 
            _util.is_pae_capable(self.conn), "apic": None }
 
29
                 hypervisorURI=None, emulator=None, installer=None,
 
30
                 caps=None):
 
31
        Guest.__init__(self, type, connection, hypervisorURI, installer,
 
32
                       caps=caps)
46
33
 
47
34
        self.emulator = emulator
48
35
        if arch:
49
36
            self.arch = arch
50
37
 
51
 
        self.loader = None
52
 
        guest = self._caps.guestForOSType(type=self.installer.os_type,
53
 
                                          arch=self.arch)
54
 
        if (not self.emulator) and guest:
55
 
            for dom in guest.domains:
56
 
                if dom.hypervisor_type == self.installer.type:
57
 
                    self.emulator = dom.emulator
58
 
                    self.loader = dom.loader
59
 
 
60
 
        # Fall back to default hardcoding
61
 
        if self.emulator is None:
62
 
            if self.type == "xen":
63
 
                if self._caps.host.arch in ("x86_64"):
64
 
                    self.emulator = "/usr/lib64/xen/bin/qemu-dm"
65
 
                else:
66
 
                    self.emulator = "/usr/lib/xen/bin/qemu-dm"
67
 
 
68
 
        if (not self.loader) and self.type == "xen":
69
 
            self.loader = "/usr/lib/xen-default/boot/hvmloader"
70
 
 
71
 
        # Add a default console device
72
 
        dev = VirtualCharDevice.get_dev_instance(self.conn,
73
 
                                                 VirtualCharDevice.DEV_CONSOLE,
74
 
                                                 VirtualCharDevice.CHAR_PTY)
75
 
        self.add_device(dev)
76
 
        self._default_console_assigned = True
77
 
 
78
 
        self._set_default_input_dev()
79
 
 
80
 
 
81
 
    def _get_input_device(self):
82
 
        inputtype = VirtualDevice.VIRTUAL_DEV_INPUT
83
 
 
84
 
        typ = self._lookup_device_param(inputtype, "type")
85
 
        bus = self._lookup_device_param(inputtype, "bus")
86
 
        dev = VirtualInputDevice(self.conn)
87
 
        dev.type = typ
88
 
        dev.bus = bus
89
 
        return dev
90
 
 
91
 
    def _get_device_xml(self, install=True):
92
 
        emu_xml = ""
93
 
        if self.emulator is not None:
94
 
            emu_xml = "    <emulator>%s</emulator>\n" % self.emulator
95
 
 
96
 
        return (emu_xml + Guest._get_device_xml(self, install))
97
 
 
98
 
    def _set_defaults(self, devlist_func):
99
 
        disktype = VirtualDevice.VIRTUAL_DEV_DISK
100
 
        nettype = VirtualDevice.VIRTUAL_DEV_NET
101
 
        disk_bus  = self._lookup_device_param(disktype, "bus")
102
 
        net_model = self._lookup_device_param(nettype, "model")
103
 
 
104
 
        # Only overwrite params if they weren't already specified
105
 
        for net in devlist_func(nettype):
106
 
            if net_model and not net.model:
107
 
                net.model = net_model
108
 
 
109
 
        for disk in devlist_func(disktype):
110
 
            if (disk_bus and not disk.bus and
111
 
                disk.device == VirtualDisk.DEVICE_DISK):
112
 
                disk.bus = disk_bus
113
 
 
114
 
        if self.clock.offset == None:
115
 
            self.clock.offset = self._lookup_osdict_key("clock")
116
 
 
117
 
        # Run this last, so we get first crack at disk attributes
118
 
        Guest._set_defaults(self, devlist_func)
 
38
    # Back compat
 
39
    def _get_loader(self):
 
40
        if not self.installer:
 
41
            return None
 
42
        return self.installer.loader
 
43
    def _set_loader(self, val):
 
44
        print val
 
45
        if not self.installer:
 
46
            return
 
47
        self.installer.loader = val
 
48
    loader = property(_get_loader, _set_loader)