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 _char_file_xml(self): """ Provide source xml for devs that require only a path (dev, pipe) """ file_xml = "" mode_xml = "" if self.source_path: file_xml = " path='%s'" % xml_escape(self.source_path) else: raise ValueError(_("A source path is required for character " "device type '%s'" % self.char_type)) if self.supports_property("source_mode") and self.source_mode: mode_xml = " mode='%s'" % xml_escape(self.source_mode) xml = " <source%s%s/>\n" % (mode_xml, file_xml) return xml
def _char_file_xml(self): """ Provide source xml for devs that require only a patch (dev, pipe) """ file_xml = "" mode_xml = "" if self.source_path: file_xml = " path='%s'" % xml_escape(self.source_path) else: raise ValueError( _("A source path is required for character " "device type '%s'" % self.char_type)) if hasattr(self, "source_mode") and self.source_mode: mode_xml = " mode='%s'" % xml_escape(self.source_mode) xml = " <source%s%s/>\n" % (mode_xml, file_xml) 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 new_setter(self, val, *args, **kwargs): # Do this regardless, for validation purposes fset(self, val, *args, **kwargs) if not self._xml_node: return # Convert from API value to XML value val = fget(self) if set_converter: val = set_converter(self, val) elif default_converter and val == "default": val = default_converter(self) nodexpath = xpath if xml_set_xpath: nodexpath = xml_set_xpath(self) if nodexpath is None: return nodes = _util.listify(_get_xpath_node(self._xml_ctx, nodexpath, is_multi)) xpath_list = nodexpath if xml_set_list: xpath_list = xml_set_list(self) node_map = map(lambda x, y, z: (x, y, z), _util.listify(nodes), _util.listify(val), _util.listify(xpath_list)) for node, val, usexpath in node_map: if node: usexpath = node.nodePath() if val not in [None, False]: if not node: node = _build_xpath_node(self._xml_node, usexpath) if val is True: # Boolean property, creating the node is enough pass else: node.setContent(_util.xml_escape(str(val))) else: _remove_xpath_node(self._xml_node, usexpath)
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