def check_domain_state(conn, guestname, logger):
    """ if a guest with the same name exists, remove it """
    running_guests = []
    ids = conn.listDomainsID()
    for id in ids:
        obj = conn.lookupByID(id)
        running_guests.append(obj.name())
    if guestname in running_guests:
        logger.info('A guest with the same name %s is running!' % guestname)
        logger.info('destroy it...')
        domobj = conn.lookupByName(guestname)
        domobj.destroy()
    defined_guests = conn.listDefinedDomains()
    if guestname in defined_guests:
        logger.info('undefine the guest with the same name %s' % guestname)
        domobj = conn.lookupByName(guestname)
        domobj.undefine()
