~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to virtinst/ParaVirtGuest.py

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2007-11-20 13:40:28 UTC
  • Revision ID: james.westby@ubuntu.com-20071120134028-rg0pjby0jc4mycks
Tags: upstream-0.300.1+hg20071120
ImportĀ upstreamĀ versionĀ 0.300.1+hg20071120

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -tt
 
2
#
 
3
# Paravirtualized guest support
 
4
#
 
5
# Copyright 2006-2007  Red Hat, Inc.
 
6
# Jeremy Katz <katzj@redhat.com>
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free  Software Foundation; either version 2 of the License, or
 
11
# (at your option)  any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program; if not, write to the Free Software
 
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
21
# MA 02110-1301 USA.
 
22
 
 
23
import os
 
24
import libvirt
 
25
import Guest
 
26
import DistroManager
 
27
from virtinst import _virtinst as _
 
28
 
 
29
class ParaVirtGuest(Guest.XenGuest):
 
30
    def __init__(self, type=None, connection=None, hypervisorURI=None, installer=None):
 
31
        if not installer:
 
32
            installer = DistroManager.DistroInstaller(type = type)
 
33
        Guest.Guest.__init__(self, type, connection, hypervisorURI, installer)
 
34
        self.disknode = "xvd"
 
35
 
 
36
    def _get_osblob(self, install):
 
37
        return self.installer._get_osblob(install, hvm = False)
 
38
 
 
39
    def _connectSerialConsole(self):
 
40
        cmd = ["/usr/bin/virsh", "console", "%s" %(self.domain.ID(),)]
 
41
        child = os.fork()
 
42
        if (not child):
 
43
            os.execvp(cmd[0], cmd)
 
44
            os._exit(1)
 
45
        return child
 
46
 
 
47
    def get_input_device(self):
 
48
        return ("mouse", "xen")
 
49
 
 
50
    def validate_parms(self):
 
51
        if not self.location and not self.boot:
 
52
            raise ValueError, _("A location must be specified to install from")
 
53
        Guest.Guest.validate_parms(self)
 
54
 
 
55
    def _prepare_install(self, meter):
 
56
        Guest.Guest._prepare_install(self, meter)
 
57
        self._installer.prepare(guest = self, meter = meter)
 
58
        if self._installer.install_disk is not None:
 
59
            self._install_disks.append(self._installer.install_disk)
 
60
 
 
61
 
 
62
    def _get_disk_xml(self, install = True):
 
63
        """Get the disk config in the libvirt XML format"""
 
64
        ret = ""
 
65
        nodes = {}
 
66
        for i in range(16):
 
67
            n = "%s%c" % (self.disknode, ord('a') + i)
 
68
            nodes[n] = None
 
69
        for d in self._install_disks:
 
70
            if d.transient and not install:
 
71
                continue
 
72
            target = d.target
 
73
            if target is None:
 
74
                for t in sorted(nodes.keys()):
 
75
                    if nodes[t] is None:
 
76
                        target = t
 
77
                        break
 
78
            if target is None or nodes[target] is not None:
 
79
                raise ValueError, _("Can't use more than 16 disks on a PV guest")
 
80
            nodes[target] = True
 
81
            ret += d.get_xml_config(target)
 
82
        return ret