import re
import logging


def sanitize(name):
    """Clean a proposed hostname so it it is LocalHostName compliant.

    :param name: Name to sanitize.

    :return: Sanitized name.

    CLI Example::

        salt '*' hostname.sanitize 2L33T_4_u_
    """
    new_name = re.sub(r'[^0-9A-Z-]', '-', name, flags=re.IGNORECASE)
    if new_name != name:
        logging.warning("Hostname was sanitized from '%s' to '%s'.", name, new_name)
    return new_name