def build_network_settings(**settings):
    '''
    Build the global network script.

    CLI Example:

    .. code-block:: bash

        salt '*' ip.build_network_settings <settings>
    '''
    changes = []

    # Read current configuration and store default values
    current_network_settings = _parse_current_network_settings()

    # Build settings
    opts = _parse_network_settings(settings, current_network_settings)

    # Ubuntu has moved away from /etc/default/networking
    # beginning with the 12.04 release so we disable or enable
    # the networking related services on boot
    skip_etc_default_networking = (
        __grains__['osfullname'] == 'Ubuntu' and
        int(__grains__['osrelease'].split('.')[0]) >= 12)
    if skip_etc_default_networking:
        if opts['networking'] == 'yes':
            service_cmd = 'service.enable'
        else:
            service_cmd = 'service.disable'

        if __salt__['service.available']('NetworkManager'):
            __salt__[service_cmd]('NetworkManager')

        if __salt__['service.available']('networking'):
            __salt__[service_cmd]('networking')
    else:
        try:
            template = JINJA.get_template('network.jinja')
        except jinja2.exceptions.TemplateNotFound:
            log.error('Could not load template network.jinja')
            return ''
        network = template.render(opts)

        if 'test' in settings and settings['test']:
            return _read_temp(network)
        # Write settings
        _write_file_network(network, _DEB_NETWORKING_FILE, True)

    # Write hostname to /etc/hostname
    sline = opts['hostname'].split('.', 1)
    opts['hostname'] = sline[0]
    hostname = '{0}\n' . format(opts['hostname'])
    current_domainname = current_network_settings['domainname']
    current_searchdomain = current_network_settings['searchdomain']

    # Only write the hostname if it has changed
    if not opts['hostname'] == current_network_settings['hostname']:
        if not ('test' in settings and settings['test']):
            # TODO  replace wiht a call to network.mod_hostname instead
            _write_file_network(hostname, _DEB_HOSTNAME_FILE)

    new_domain = False
    if len(sline) > 1:
        new_domainname = sline[1]
        if new_domainname != current_domainname:
            domainname = new_domainname
            opts['domainname'] = new_domainname
            new_domain = True
        else:
            domainname = current_domainname
            opts['domainname'] = domainname
    else:
        domainname = current_domainname
        opts['domainname'] = domainname

    new_search = False
    if 'search' in opts:
        new_searchdomain = opts['search']
        if new_searchdomain != current_searchdomain:
            searchdomain = new_searchdomain
            opts['searchdomain'] = new_searchdomain
            new_search = True
        else:
            searchdomain = current_searchdomain
            opts['searchdomain'] = searchdomain
    else:
        searchdomain = current_searchdomain
        opts['searchdomain'] = searchdomain

    # If the domain changes, then we should write the resolv.conf file.
    if new_domain or new_search:
        # Look for existing domain line and update if necessary
        contents = _parse_resolve()
        domain_prog = re.compile(r'domain\s+(?P<domain_name>\S+)')
        search_prog = re.compile(r'search\s+(?P<search_domain>\S+)')
        new_contents = []
        found_domain = False
        found_search = False
        for item in contents:
            domain_match = domain_prog.match(item)
            search_match = search_prog.match(item)
            if domain_match:
                new_contents.append('domain {0}\n' . format(domainname))
                found_domain = True
            elif search_match:
                new_contents.append('search {0}\n' . format(searchdomain))
                found_search = True
            else:
                new_contents.append(item)

        # A domain line didn't exist so we'll add one in
        # with the new domainname
        if not found_domain:
            new_contents.insert(0, 'domain {0}\n' . format(domainname))

        # A search line didn't exist so we'll add one in
        # with the new search domain
        if not found_search:
            if new_contents[0].startswith('domain'):
                new_contents.insert(1, 'search {0}\n' . format(searchdomain))
            else:
                new_contents.insert(0, 'search {0}\n' . format(searchdomain))

        new_resolv = ''.join(new_contents)

        # Write /etc/resolv.conf
        if not (settings in 'test' and settings['test']):
            _write_file_network(new_resolv, _DEB_RESOLV_FILE)

    #  used for returning the results back
    try:
        template = JINJA.get_template('display-network.jinja')
    except jinja2.exceptions.TemplateNotFound:
        log.error('Could not load template display-network.jinja')
        return ''
    network = template.render(opts)
    changes.extend(_read_temp(network))

    return changes
dataset/ETHPy150Open saltstack/salt/salt/modules/debian_ip.py/build_network_settings/swapped operands of `in`