def os_identifier_parser(self, xmlroot): """ Parser for identified os """ try: os_identified = [] host = xmlroot.find("host") if(host): os = host.find("os") if(host): osmatches = os.findall("osmatch") for match in osmatches: attrib = match.attrib for osclass in match.findall("osclass"): attrib["osclass"]=osclass.attrib for cpe in osclass.findall("cpe"): attrib["cpe"]=cpe.text os_identified.append(attrib) except Exception as e: raise(e) else: return os_identified
def parse_os(self, os_results): """ parses os results """ os = os_results.find("os") os_list = [] if os is not None: for match in os.findall("osmatch"): attrib = match.attrib for osclass in match.findall("osclass"): attrib["osclass"]=osclass.attrib for cpe in osclass.findall("cpe"): attrib["cpe"]=cpe.text os_list.append(attrib) return os_list else: return {}
def _set_boot_device(conn, domain, device): """Set the boot device. :param conn: active libvirt connection. :param domain: libvirt domain object. :raises: LibvirtError if failed update domain xml. """ parsed = ET.fromstring(domain.XMLDesc()) os = parsed.find('os') boot_list = os.findall('boot') # Clear boot list for boot_el in boot_list: os.remove(boot_el) boot_el = ET.SubElement(os, 'boot') boot_el.set('dev', device) try: conn.defineXML(ET.tostring(parsed)) except libvirt.libvirtError as e: raise f_exc.LibvirtError(err=e)