Ensure that only the given hostnames are associated with the
    given IP address.

    .. versionadded:: 2016.3.0

    name
        The IP address to associate with the given hostnames.

    hostnames
        Either a single hostname or a list of hostnames to associate
        with the given IP address in the given order.  Any other
        hostname associated with the IP address is removed.  If no
        hostnames are specified, all hostnames associated with the
        given IP address are removed.

def only(name, hostnames):
    '''
    Ensure that only the given hostnames are associated with the
    given IP address.

    .. versionadded:: 2016.3.0

    name
        The IP address to associate with the given hostnames.

    hostnames
        Either a single hostname or a list of hostnames to associate
        with the given IP address in the given order.  Any other
        hostname associated with the IP address is removed.  If no
        hostnames are specified, all hostnames associated with the
        given IP address are removed.
    '''
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': ''}

    if isinstance(hostnames, six.string_types):
        hostnames = [hostnames]

    old = ' '.join(__salt__['hosts.get_alias'](name))
    new = ' '.join((x.strip() for x in hostnames))

    if old == new:
        ret['comment'] = 'IP address {0} already set to "{1}"'.format(
            name, new)
        ret['result'] = True
        return ret

    if __opts__['test']:
        ret['comment'] = 'Would change {0} from "{1}" to "{2}"'.format(
            name, old, new)
        return ret

    ret['result'] = __salt__['hosts.set_host'](name, new)
    if not ret['result']:
        ret['comment'] = ('hosts.set_host failed to change {0}'
            + ' from "{1}" to "{2}"').format(name, old, new)
        return ret

    ret['comment'] = 'successfully changed {0} from "{1}" to "{2}"'.format(
        name, old, new)
    ret['changes'] = {name: {'old': old, 'new': new}}
    return ret