virtinst: Drop __init__ params from Guest and Installer

This commit is contained in:
Cole Robinson 2013-07-16 16:47:08 -04:00
parent aba9d82bac
commit f37d4d010a
7 changed files with 57 additions and 85 deletions

View File

@ -169,7 +169,8 @@ def diff_compare(actual_out, filename=None, expect_out=None):
def get_basic_paravirt_guest(installer=None):
g = virtinst.Guest(_conn, type="xen")
g = virtinst.Guest(_conn)
g.type = "xen"
g.name = "TestGuest"
g.memory = int(200 * 1024)
g.maxmemory = int(400 * 1024)
@ -195,7 +196,8 @@ def get_basic_paravirt_guest(installer=None):
def get_basic_fullyvirt_guest(typ="xen", installer=None):
g = virtinst.Guest(_conn, type=typ)
g = virtinst.Guest(_conn)
g.type = typ
g.name = "TestGuest"
g.memory = int(200 * 1024)
g.maxmemory = int(400 * 1024)
@ -220,24 +222,32 @@ def get_basic_fullyvirt_guest(typ="xen", installer=None):
def make_import_installer(os_type="hvm"):
inst = virtinst.ImportInstaller(type="xen", os_type=os_type, conn=_conn)
inst = virtinst.ImportInstaller(_conn)
inst.type = "xen"
inst.os_type = os_type
return inst
def make_distro_installer(location="/default-pool/default-vol", gtype="xen"):
inst = virtinst.DistroInstaller(type=gtype, os_type="hvm", conn=_conn,
location=location)
inst = virtinst.DistroInstaller(_conn)
inst.type = gtype
inst.os_type = "hvm"
inst.location = location
return inst
def make_live_installer(location="/dev/loop0", gtype="xen"):
inst = virtinst.LiveCDInstaller(type=gtype, os_type="hvm",
conn=_conn, location=location)
inst = virtinst.LiveCDInstaller(_conn)
inst.type = gtype
inst.os_type = "hvm"
inst.location = location
return inst
def make_pxe_installer(gtype="xen"):
inst = virtinst.PXEInstaller(type=gtype, os_type="hvm", conn=_conn)
inst = virtinst.PXEInstaller(_conn)
inst.type = gtype
inst.os_type = "hvm"
return inst

View File

@ -150,8 +150,8 @@ def main(conn=None):
# Build the Installer instance
installer = virtinst.ImageInstaller(conn, boot_index=options.boot,
image=image)
installer = virtinst.ImageInstaller(conn, image,
boot_index=options.boot)
# Get Guest instance from installer parameters.
guest = installer.guest_from_installer()

View File

@ -482,7 +482,9 @@ def build_installer(options, conn, virt_type, hv_name, arch, machine):
# Only set installer params here that impact the hw config, not
# anything to do with install media
installer = instclass(type=hv_name, os_type=virt_type, conn=conn)
installer = instclass(conn)
installer.type = hv_name
installer.os_type = virt_type
installer.arch = arch
installer.machine = machine

View File

@ -1762,9 +1762,9 @@ class vmmCreate(vmmGObjectUI):
# Interesting methods
def build_installer(self, instclass):
installer = instclass(self.conn.get_backend(),
type=self.capsdomain.hypervisor_type,
os_type=self.capsguest.os_type)
installer = instclass(self.conn.get_backend())
installer.type = self.capsdomain.hypervisor_type
installer.os_type = self.capsguest.os_type
installer.arch = self.capsguest.arch
return installer

View File

@ -155,27 +155,12 @@ def _upload_file(conn, meter, destpool, src):
class DistroInstaller(Installer.Installer):
def __init__(self, conn, type="xen", location=None,
extraargs=None, os_type=None):
# pylint: disable=W0622
# Redefining built-in 'type', but it matches the XML so keep it
def __init__(self, *args, **kwargs):
Installer.Installer.__init__(self, *args, **kwargs)
Installer.Installer.__init__(self, conn, type, location, extraargs,
os_type)
self._livecd = False
# True == location is a filesystem path
# False == location is a url
self.livecd = False
self._location_is_path = True
# DistroInstaller specific methods/overwrites
def _get_livecd(self):
return self._livecd
def _set_livecd(self, val):
self._livecd = bool(val)
livecd = property(_get_livecd, _set_livecd)
def get_location(self):
return self._location
@ -235,7 +220,6 @@ class DistroInstaller(Installer.Installer):
# Private helper methods
def _prepare_cdrom(self, guest, meter):
transient = not self.livecd
if not self._location_is_path:

View File

@ -162,10 +162,7 @@ class Guest(XMLBuilder):
return cpustr
def __init__(self, conn, type=None, installer=None, parsexml=None):
# pylint: disable=W0622
# Redefining built-in 'type', but it matches the XML so keep it
def __init__(self, conn, parsexml=None, parsexmlnode=None):
self._name = None
self._uuid = None
self._memory = None
@ -181,12 +178,13 @@ class Guest(XMLBuilder):
self._features = None
self._replace = None
self._emulator = None
self._installer = installer
self._os_type = None
self._os_variant = None
self._os_autodetect = False
self.installer = None
# General device list. Only access through API calls (even internally)
self._devices = []
@ -202,8 +200,7 @@ class Guest(XMLBuilder):
if self._is_parse():
return
if not self.installer:
self.installer = virtinst.DistroInstaller(conn, type)
self.installer = virtinst.DistroInstaller(conn)
# Need to do this after all parameter init
self._features = DomainFeatures(self.conn)
@ -217,12 +214,6 @@ class Guest(XMLBuilder):
# Property accessors #
######################
def get_installer(self):
return self._installer
def set_installer(self, val):
self._installer = val
installer = property(get_installer, set_installer)
def get_clock(self):
return self._clock
clock = property(get_clock)
@ -445,9 +436,9 @@ class Guest(XMLBuilder):
# Hypervisor name (qemu, xen, kvm, etc.)
# Deprecated: should be pulled directly from the installer
def get_type(self):
return self._installer.type
return self.installer.type
def set_type(self, val):
self._installer.type = val
self.installer.type = val
type = property(get_type, set_type)
# Deprecated: should be pulled directly from the installer
@ -459,29 +450,29 @@ class Guest(XMLBuilder):
# Deprecated: Should be called from the installer directly
def get_location(self):
return self._installer.location
return self.installer.location
def set_location(self, val):
self._installer.location = val
self.installer.location = val
location = property(get_location, set_location)
# Deprecated: Should be called from the installer directly
def get_scratchdir(self):
return self._installer.scratchdir
return self.installer.scratchdir
scratchdir = property(get_scratchdir)
# Deprecated: Should be called from the installer directly
def get_extraargs(self):
return self._installer.extraargs
return self.installer.extraargs
def set_extraargs(self, val):
self._installer.extraargs = val
self.installer.extraargs = val
extraargs = property(get_extraargs, set_extraargs)
# Deprecated: Should set the installer values directly
def get_cdrom(self):
return self._installer.location
return self.installer.location
def set_cdrom(self, val):
self._installer.location = val
self._installer.cdrom = True
self.installer.location = val
self.installer.cdrom = True
cdrom = property(get_cdrom, set_cdrom)
@ -618,8 +609,8 @@ class Guest(XMLBuilder):
self._track_device(dev)
self._xml_node.virtinst_root_doc = self._xml_root_doc
self._installer = virtinst.Installer.Installer(self.conn,
parsexmlnode=self._xml_node)
self.installer = virtinst.Installer.Installer(self.conn,
parsexmlnode=self._xml_node)
self._features = DomainFeatures(self.conn,
parsexmlnode=self._xml_node)
self._clock = Clock(self.conn, parsexmlnode=self._xml_node)
@ -781,15 +772,15 @@ class Guest(XMLBuilder):
ignore = dry
# Fetch install media, prepare installer devices
self._installer.prepare(guest=self,
self.installer.prepare(guest=self,
meter=meter)
# Initialize install device list
for dev in self._installer.install_devices:
for dev in self.installer.install_devices:
self._install_devices.append(dev)
def _cleanup_install(self):
self._installer.cleanup()
self.installer.cleanup()
def _create_devices(self, progresscb):
"""

View File

@ -61,14 +61,8 @@ class Installer(XMLBuilder):
_dumpxml_xpath = "/domain/os"
_has_install_phase = True
def __init__(self, conn, type="xen", location=None,
extraargs=None, os_type=None,
parsexml=None, parsexmlnode=None):
# pylint: disable=W0622
# Redefining built-in 'type', but it matches the XML so keep it
XMLBuilder.__init__(self, conn, parsexml,
parsexmlnode)
def __init__(self, conn, parsexml=None, parsexmlnode=None):
XMLBuilder.__init__(self, conn, parsexml, parsexmlnode)
self._type = None
self._location = None
@ -86,26 +80,16 @@ class Installer(XMLBuilder):
# Devices created/added during the prepare() stage
self.install_devices = []
self._tmpfiles = []
self._tmpvols = []
if self._is_parse():
return
self._type = "xen"
self._arch = self.conn.caps.host.arch
self._os_type = "xen"
if type is None:
type = "xen"
self.type = type
if not os_type is None:
self.os_type = os_type
else:
self.os_type = "xen"
if not location is None:
self.location = location
self.extraargs = extraargs
self._tmpfiles = []
self._tmpvols = []
def _get_bootconfig(self):
return self._bootconfig
@ -422,7 +406,8 @@ class Installer(XMLBuilder):
arch=self.arch,
machine=self.machine)
gobj = virtinst.Guest(self.conn, installer=self)
gobj = virtinst.Guest(self.conn)
gobj.installer = self
gobj.arch = guest.arch
gobj.emulator = domain.emulator
self.loader = domain.loader