def _get_xml_config(self): xml = "" if self.kernel: xml = _util.xml_append( xml, " <kernel>%s</kernel>" % _util.xml_escape(self.kernel)) if self.initrd: xml = _util.xml_append( xml, " <initrd>%s</initrd>" % _util.xml_escape(self.initrd)) if self.kernel_args: xml = _util.xml_append( xml, " <cmdline>%s</cmdline>" % _util.xml_escape(self.kernel_args)) else: for dev in self.bootorder: xml = _util.xml_append(xml, " <boot dev='%s'/>" % dev) if self.enable_bootmenu in [True, False]: val = self.enable_bootmenu and "yes" or "no" xml = _util.xml_append(xml, " <bootmenu enable='%s'/>" % val) return xml
def _get_osblob_helper(self, guest, isinstall, bootconfig): conn = guest.conn arch = self.arch machine = self.machine hvtype = self.type loader = self.loader os_type = self.os_type init = self.init or self._get_default_init(guest) hvxen = (hvtype == "xen") if not loader and self.is_hvm() and hvxen: loader = "/usr/lib/xen/boot/hvmloader" # Use older libvirt 'linux' value for back compat if os_type == "xen" and hvxen: os_type = "linux" if (not isinstall and self.is_xenpv() and not self.bootconfig.kernel): return "<bootloader>%s</bootloader>" % _util.pygrub_path(conn) osblob = "<os>" typexml = " <type" if arch: typexml += " arch='%s'" % arch if machine: typexml += " machine='%s'" % machine typexml += ">%s</type>" % os_type osblob = _util.xml_append(osblob, typexml) if init: osblob = _util.xml_append(osblob, " <init>%s</init>" % _util.xml_escape(init)) if loader: osblob = _util.xml_append(osblob, " <loader>%s</loader>" % _util.xml_escape(loader)) if not self.is_container(): osblob = _util.xml_append(osblob, bootconfig.get_xml_config()) osblob = _util.xml_append(osblob, " </os>") return osblob
def _get_osblob_helper(self, guest, isinstall, bootconfig): def get_param(obj, paramname): if hasattr(obj, paramname): return getattr(obj, paramname) return None ishvm = bool(isinstance(guest, virtinst.FullVirtGuest)) conn = guest.conn arch = self.arch loader = get_param(guest, "loader") if not isinstall and not ishvm and not self.bootconfig.kernel: return "<bootloader>%s</bootloader>" % _util.pygrub_path(conn) osblob = "<os>\n" os_type = self.os_type # Hack for older libvirt: use old value 'linux' for best back compat, # new libvirt will adjust the value accordingly. if os_type == "xen" and self.type == "xen": os_type = "linux" osblob += " <type" if arch: osblob += " arch='%s'" % arch osblob += ">%s</type>\n" % os_type if loader: osblob += " <loader>%s</loader>\n" % loader osblob += bootconfig.get_xml_config() osblob = _util.xml_append(osblob, " </os>") return osblob
def _get_osblob(self, install): """ Return os, features, and clock xml (Implemented in subclass) """ xml = "" osxml = self.installer.get_install_xml(self, install) if not osxml: return None xml = _util.xml_append(xml, self.installer.get_install_xml(self, install)) return xml
def _get_xml_config(self): xml = "" if self.kernel: xml = _util.xml_append(xml, " <kernel>%s</kernel>" % _util.xml_escape(self.kernel)) if self.initrd: xml = _util.xml_append(xml, " <initrd>%s</initrd>" % _util.xml_escape(self.initrd)) if self.kernel_args: xml = _util.xml_append(xml, " <cmdline>%s</cmdline>" % _util.xml_escape(self.kernel_args)) else: for dev in self.bootorder: xml = _util.xml_append(xml, " <boot dev='%s'/>" % dev) if self.enable_bootmenu in [True, False]: val = self.enable_bootmenu and "yes" or "no" xml = _util.xml_append(xml, " <bootmenu enable='%s'/>" % val) return xml
def _get_device_xml(self, devs, install=True): def do_remove_media(d): # Keep cdrom around, but with no media attached, # But only if we are a distro that doesn't have a multi # stage install (aka not Windows) return (d.virtual_device_type == VirtualDevice.VIRTUAL_DEV_DISK and d.device == VirtualDisk.DEVICE_CDROM and d.transient and not install and not self.get_continue_inst()) def do_skip_disk(d): # Skip transient labeled non-media disks return (d.virtual_device_type == VirtualDevice.VIRTUAL_DEV_DISK and d.device == VirtualDisk.DEVICE_DISK and d.transient and not install) # Wrapper for building disk XML, handling transient CDROMs def get_dev_xml(dev): origpath = None try: if do_skip_disk(dev): return "" if do_remove_media(dev): origpath = dev.path dev.path = None return dev.get_xml_config() finally: if origpath: dev.path = origpath xml = self._get_emulator_xml() # Build XML for dev in devs: xml = _util.xml_append(xml, get_dev_xml(dev)) return xml
def get_config_xml(self, install = True, disk_boot = False): """ Return the full Guest xml configuration. @param install: Whether we want the 'OS install' configuration or the 'post-install' configuration. (Some Installers, like the LiveCDInstaller may not have an 'install' config.) @type install: C{bool} @param disk_boot: Whether we should boot off the harddisk, regardless of our position in the install process (this is used for 2 stage installs, where the second stage boots off the disk. You probably don't need to touch this.) @type disk_boot: C{bool} """ # We do a shallow copy of the device list here, and set the defaults. # This way, default changes aren't persistent, and we don't need # to worry about when to call set_defaults origdevs = self.get_all_devices() devs = [] for dev in origdevs: newdev = copy.copy(dev) devs.append(newdev) def get_transient_devices(devtype): return self._dev_build_list(devtype, devs) # Set device defaults so we can validly generate XML self._set_defaults(get_transient_devices) if install: action = "destroy" else: action = "restart" osblob_install = install if disk_boot: osblob_install = False osblob = self._get_osblob(osblob_install) if not osblob: # This means there is no 'install' phase, so just return return None cpuset = "" if self.cpuset is not None: cpuset = " cpuset='" + self.cpuset + "'" desc_xml = "" if self.description is not None: desc = str(self.description) desc_xml = (" <description>%s</description>" % _util.xml_escape(desc)) xml = "" add = lambda x: _util.xml_append(xml, x) xml = add("<domain type='%s'>" % self.type) xml = add(" <name>%s</name>" % self.name) xml = add(" <currentMemory>%s</currentMemory>" % (self.memory * 1024)) xml = add(" <memory>%s</memory>" % (self.maxmemory * 1024)) xml = add(" <uuid>%s</uuid>" % self.uuid) xml = add(desc_xml) xml = add(" %s" % osblob) xml = add(self._get_features_xml()) xml = add(self._get_cpu_xml()) xml = add(self._get_clock_xml()) xml = add(" <on_poweroff>destroy</on_poweroff>") xml = add(" <on_reboot>%s</on_reboot>" % action) xml = add(" <on_crash>%s</on_crash>" % action) xml = add(" <vcpu%s>%d</vcpu>" % (cpuset, self.vcpus)) xml = add(" <devices>") xml = add(self._get_device_xml(devs, install)) xml = add(" </devices>") xml = add(self._get_seclabel_xml()) xml = add("</domain>\n") return xml
def get_config_xml(self, install=True, disk_boot=False): """ Return the full Guest xml configuration. @param install: Whether we want the 'OS install' configuration or the 'post-install' configuration. (Some Installers, like the LiveCDInstaller may not have an 'install' config.) @type install: C{bool} @param disk_boot: Whether we should boot off the harddisk, regardless of our position in the install process (this is used for 2 stage installs, where the second stage boots off the disk. You probably don't need to touch this.) @type disk_boot: C{bool} """ # We do a shallow copy of the device list here, and set the defaults. # This way, default changes aren't persistent, and we don't need # to worry about when to call set_defaults origdevs = self.get_all_devices() devs = [] for dev in origdevs: newdev = copy.copy(dev) devs.append(newdev) def get_transient_devices(devtype): return self._dev_build_list(devtype, devs) # Set device defaults so we can validly generate XML self._set_defaults(get_transient_devices) if install: action = "destroy" else: action = "restart" osblob_install = install if disk_boot: osblob_install = False osblob = self._get_osblob(osblob_install) if not osblob: # This means there is no 'install' phase, so just return return None cpuset = "" if self.cpuset is not None: cpuset = " cpuset='" + self.cpuset + "'" desc_xml = "" if self.description is not None: desc = str(self.description) desc_xml = (" <description>%s</description>" % _util.xml_escape(desc)) xml = "" add = lambda x: _util.xml_append(xml, x) xml = add("<domain type='%s'>" % self.type) xml = add(" <name>%s</name>" % self.name) xml = add(" <currentMemory>%s</currentMemory>" % (self.memory * 1024)) xml = add(" <memory>%s</memory>" % (self.maxmemory * 1024)) xml = add(" <uuid>%s</uuid>" % self.uuid) xml = add(desc_xml) xml = add(" %s" % osblob) xml = add(self._get_features_xml()) xml = add(self._get_cpu_xml()) xml = add(self._get_clock_xml()) xml = add(" <on_poweroff>destroy</on_poweroff>") xml = add(" <on_reboot>%s</on_reboot>" % action) xml = add(" <on_crash>%s</on_crash>" % action) xml = add(" <vcpu%s>%d</vcpu>" % (cpuset, self.vcpus)) xml = add(" <devices>") xml = add(self._get_device_xml(devs, install)) xml = add(" </devices>") xml = add(self._get_seclabel_xml()) xml = add("</domain>\n") return xml