'Returns an iterator over serial port(s) configured on guest.
:param mode: Should be a value in (None, bind, connect)'

def _get_serial_ports_from_guest(self, guest, mode=None):

    xml = guest.get_xml_desc()
    tree = etree.fromstring(xml)
    xpath_mode = (("[@mode='%s']" % mode) if mode else '')
    serial_tcp = ("./devices/serial[@type='tcp']/source" + xpath_mode)
    console_tcp = ("./devices/console[@type='tcp']/source" + xpath_mode)
    tcp_devices = tree.findall(serial_tcp)
    if (len(tcp_devices) == 0):
        tcp_devices = tree.findall(console_tcp)
    for source in tcp_devices:
        (yield (source.get('host'), int(source.get('service'))))
