Parse /etc/default/networking and return current configuration
513430
def _parse_current_network_settings():
    '''
    
    '''
    opts = salt.utils.odict.OrderedDict()
    opts['networking'] = ''

    if os.path.isfile(_DEB_NETWORKING_FILE):
        with salt.utils.files.fopen(_DEB_NETWORKING_FILE) as contents:
            for line in contents:
                salt.utils.stringutils.to_unicode(line)
                if line.startswith('#'):
                    continue
                elif line.startswith('CONFIGURE_INTERFACES'):
                    opts['networking'] = line.split('=', 1)[1].strip()

    hostname = _parse_hostname()
    domainname = _parse_domainname()
    searchdomain = _parse_searchdomain()

    opts['hostname'] = hostname
    opts['domainname'] = domainname
    opts['searchdomain'] = searchdomain
    return opts
1068631
def parse_config(self):
        
        tree = ElementTree.parse(self.file_xml)
        root = tree.getroot()
        for server in root.findall('server'):
            destination = server.text
            name = server.get("name")
            self.discover_remote(destination, name)
459317
def get_default_config(self):
        
        config = super(HAProxyCollector, self).get_default_config()
        config.update({
            'method':           'http',
            'path':             'haproxy',
            'url':              'http://localhost/haproxy?stats;csv',
            'user':             'admin',
            'pass':             'password',
            'sock':             '/var/run/haproxy.sock',
            'ignore_servers':   False,
        })
        return config
587311
def 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)

    # Get hostname and domain from opts
    sline = opts['hostname'].split('.', 1)
    opts['hostname'] = sline[0]
    current_domainname = current_network_settings['domainname']
    current_searchdomain = current_network_settings['searchdomain']

    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
        resolve = _parse_resolve()
        domain_prog = re.compile(r'domain\s+')
        search_prog = re.compile(r'search\s+')
        new_contents = []

        for item in _read_file(_DEB_RESOLV_FILE):
            if domain_prog.match(item):
                item = 'domain {0}'.format(domainname)
            elif search_prog.match(item):
                item = 'search {0}'.format(searchdomain)
            new_contents.append(item)

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

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

        new_resolv = '\n'.join(new_contents)

        # Write /etc/resolv.conf
        if not ('test' in settings 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
236735
def get_default_config_help(self):
        
        config = super(RiemannHandler, self).get_default_config_help()

        config.update({
            'host': '',
            'port': '',
            'transport': 'tcp or udp',
        })

        return config
133390
def get_default_gateway():
    '''
    
    '''
    try:
        return next(iter(
            x.split()[-1] for x in __salt__['cmd.run'](
                ['netsh', 'interface', 'ip', 'show', 'config'],
                python_shell=False
            ).splitlines()
            if 'Default Gateway:' in x
        ))
    except StopIteration:
        raise CommandExecutionError('Unable to find default gateway')
1012801
def _get_conn(opts, profile=None):
    '''
    
    '''
    if profile is None:
        profile = opts.get('etcd.returner')
    path = opts.get('etcd.returner_root', '/salt/return')
    return salt.utils.etcd_util.get_conn(opts, profile), path
905738
def parse_networking(
    text    = None
    ):
    
    try:
        address = _builtins.address
        port    = _builtins.port
    except:
        address = None
        port    = None
    triggers = []
    if address and port:
        triggers.extend([
            trigger_keyphrases(
                text                          = text,
                keyphrases                    = [
                                                "reverse SSH",
                                                "reverse ssh"
                                                ],
                function                      = engage_command,
                kwargs                        = {"command": "ssh -R " + str(port) + ":localhost:22 " + address},
                confirm                       = True,
                confirmation_prompt           = "Do you want to reverse SSH "
                                                "connect? (y/n)",
                confirmation_feedback_confirm = "confirm reverse SSH connect: "
                                                "ssh localhost -p " + str(port),
                confirmation_feedback_deny    = "deny reverse SSH connect"
            )
        ])
    if any(triggers):
        responses = [response for response in triggers if response]
        if len(responses) > 1:
            return responses
        else:
            return responses[0]
    else:
        return False
884218
def get_network_settings():
    '''
    
    '''
    skip_etc_default_networking = (
        __grains__['osfullname'] == 'Ubuntu' and
        int(__grains__['osrelease'].split('.')[0]) >= 12)

    if skip_etc_default_networking:
        settings = {}
        if __salt__['service.available']('networking'):
            if __salt__['service.status']('networking'):
                settings['networking'] = "yes"
            else:
                settings['networking'] = "no"
        else:
            settings['networking'] = "no"

        hostname = _parse_hostname()
        domainname = _parse_domainname()
        searchdomain = _parse_searchdomain()

        settings['hostname'] = hostname
        settings['domainname'] = domainname
        settings['searchdomain'] = searchdomain

    else:
        settings = _parse_current_network_settings()

    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(settings)
    return _read_temp(network)
546713
def _get_running_config(self, split=True):
        
        conn = self._get_connection()
        config = conn.get_config(source="running")
        if config:
            root = ET.fromstring(config._raw)
            running_config = root[0][0]
            if split is True:
                rgx = re.compile("\r*\n+")
                ioscfg = rgx.split(running_config.text)
            else:
                ioscfg = running_config.text
            return ioscfg
941086
def __parse(self, configuration):
        
        for entry in (
            "properties",
            "environment",
            "paths",
            "bundles",
            "components",
        ):
            # Check if current values must be reset
            reset_key = "reset_{0}".format(entry)

            # Compute the name of the method
            call_name = "add" if not configuration.get(reset_key) else "set"
            method = getattr(self.__state, "{0}_{1}".format(call_name, entry))

            # Update configuration
            method(configuration.get(entry))
234741
def config(env=DEFAULT_ENV, default='locmem://'):
    """"""
    config = {}

    s = os.environ.get(env, default)

    if s:
        config = parse(s)

    return config
703407
def _parse_conf(conf_file=default_conf):
    '''
    
    '''
    ret = {}
    with salt.utils.files.fopen(conf_file, 'r') as ifile:
        for line in ifile:
            line = salt.utils.stringutils.to_unicode(line).strip()
            if not line:
                continue
            if line.startswith('#'):
                continue
            splitline = line.split(' ', 1)
            ret[splitline[0]] = splitline[1]
    return ret
591999
def _parse_network_settings(opts, current):
    '''
    
    '''
    # Normalize keys
    opts = dict((k.lower(), v) for (k, v) in six.iteritems(opts))
    current = dict((k.lower(), v) for (k, v) in six.iteritems(current))

    # Check for supported parameters
    retain_settings = opts.get('retain_settings', False)
    result = current if retain_settings else {}

    # Default quote type is an empty string, which will not quote values
    quote_type = ''

    valid = _CONFIG_TRUE + _CONFIG_FALSE
    if 'enabled' not in opts:
        try:
            opts['networking'] = current['networking']
            # If networking option is quoted, use its quote type
            quote_type = salt.utils.stringutils.is_quoted(opts['networking'])
            _log_default_network('networking', current['networking'])
        except ValueError:
            _raise_error_network('networking', valid)
    else:
        opts['networking'] = opts['enabled']

    true_val = '{0}yes{0}'.format(quote_type)
    false_val = '{0}no{0}'.format(quote_type)

    networking = salt.utils.stringutils.dequote(opts['networking'])
    if networking in valid:
        if networking in _CONFIG_TRUE:
            result['networking'] = true_val
        elif networking in _CONFIG_FALSE:
            result['networking'] = false_val
    else:
        _raise_error_network('networking', valid)

    if 'hostname' not in opts:
        try:
            opts['hostname'] = current['hostname']
            _log_default_network('hostname', current['hostname'])
        except Exception:
            _raise_error_network('hostname', ['server1.example.com'])

    if opts['hostname']:
        result['hostname'] = '{1}{0}{1}'.format(
            salt.utils.stringutils.dequote(opts['hostname']), quote_type)
    else:
        _raise_error_network('hostname', ['server1.example.com'])

    if 'nozeroconf' in opts:
        nozeroconf = salt.utils.stringutils.dequote(opts['nozeroconf'])
        if nozeroconf in valid:
            if nozeroconf in _CONFIG_TRUE:
                result['nozeroconf'] = true_val
            elif nozeroconf in _CONFIG_FALSE:
                result['nozeroconf'] = false_val
        else:
            _raise_error_network('nozeroconf', valid)

    for opt in opts:
        if opt not in ['networking', 'hostname', 'nozeroconf']:
            result[opt] = '{1}{0}{1}'.format(
                salt.utils.stringutils.dequote(opts[opt]), quote_type)
    return result
513270
def _init_net_specs(conf):
        
        for net_name, net_spec in conf.get('nets', {}).items():
            net_spec['name'] = net_name
            net_spec['mapping'] = {}
            net_spec.setdefault('type', 'nat')

        return conf
339853
def get_conn(opts, profile=None, host=None, port=None):
    '''
    
    '''
    if not (host and port):
        opts_pillar = opts.get('pillar', {})
        opts_master = opts_pillar.get('master', {})

        opts_merged = {}
        opts_merged.update(opts_master)
        opts_merged.update(opts_pillar)
        opts_merged.update(opts)

        if profile:
            conf = opts_merged.get(profile, {})
        else:
            conf = opts_merged

        host = conf.get('memcached.host', DEFAULT_HOST)
        port = conf.get('memcached.port', DEFAULT_PORT)

    if not six.text_type(port).isdigit():
        raise SaltInvocationError('port must be an integer')

    if HAS_LIBS:
        return memcache.Client(['{0}:{1}'.format(host, port)])
    else:
        raise CommandExecutionError(
            '(unable to import memcache, '
            'module most likely not installed)'
        )
119116
def load_config():
    ''''''
    cfg_path = '/usr/local/etc/freelan'
    cfg_file = 'freelan.cfg'

    if not os.path.isdir(cfg_path):
        print("Can not find default freelan config directory.")
        return

    cfg_file_path = os.path.join(cfg_path,cfg_file)

    if not os.path.isfile( cfg_file_path ):
        print("Can not find default freelan config file.")
        return

    return _load_config(cfg_file_path)