<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import functools <EOL> import logging <EOL> import os . path <EOL> import os <EOL> import re <EOL> import time <EOL> import jinja2 <EOL> import jinja2 . exceptions <EOL> import salt . ext . six as six <EOL> from salt . ext . six . moves import StringIO <EOL> import salt . utils <EOL> import salt . utils . templates <EOL> import salt . utils . validate . net <EOL> import salt . utils . odict <EOL> log = logging . getLogger ( __name__ ) <EOL> JINJA = jinja2 . Environment ( <EOL> loader = jinja2 . FileSystemLoader ( <EOL> os . path . join ( salt . utils . templates . TEMPLATE_DIRNAME , '<STR_LIT>' ) <EOL> ) <EOL> ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> return __virtualname__ <EOL> return ( False , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> _ETHTOOL_CONFIG_OPTS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _REV_ETHTOOL_CONFIG_OPTS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _DEB_CONFIG_PPPOE_OPTS = { <EOL> '<STR_LIT:user>' : '<STR_LIT:user>' , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _DEB_ROUTES_FILE = '<STR_LIT>' <EOL> _DEB_NETWORK_FILE = '<STR_LIT>' <EOL> _DEB_NETWORK_DIR = '<STR_LIT>' <EOL> _DEB_NETWORK_UP_DIR = '<STR_LIT>' <EOL> _DEB_NETWORK_DOWN_DIR = '<STR_LIT>' <EOL> _DEB_NETWORK_CONF_FILES = '<STR_LIT>' <EOL> _DEB_NETWORKING_FILE = '<STR_LIT>' <EOL> _DEB_HOSTNAME_FILE = '<STR_LIT>' <EOL> _DEB_RESOLV_FILE = '<STR_LIT>' <EOL> _DEB_PPP_DIR = '<STR_LIT>' <EOL> _CONFIG_TRUE = [ '<STR_LIT:yes>' , '<STR_LIT>' , '<STR_LIT:true>' , '<STR_LIT:1>' , True ] <EOL> _CONFIG_FALSE = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:false>' , '<STR_LIT:0>' , False ] <EOL> _IFACE_TYPES = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' , <EOL> ] <EOL> def _error_msg_iface ( iface , option , expected ) : <EOL> '''<STR_LIT>''' <EOL> msg = '<STR_LIT>' <EOL> return msg . format ( iface , option , '<STR_LIT:|>' . join ( expected ) ) <EOL> def _error_msg_routes ( iface , option , expected ) : <EOL> '''<STR_LIT>''' <EOL> msg = '<STR_LIT>' <EOL> return msg . format ( iface , option , expected ) <EOL> def _log_default_iface ( iface , opt , value ) : <EOL> msg = '<STR_LIT>' <EOL> log . info ( msg . format ( iface , opt , value ) ) <EOL> def _error_msg_network ( option , expected ) : <EOL> '''<STR_LIT>''' <EOL> msg = '<STR_LIT>' <EOL> return msg . format ( option , '<STR_LIT:|>' . join ( expected ) ) <EOL> def _log_default_network ( opt , value ) : <EOL> msg = '<STR_LIT>' <EOL> log . info ( msg . format ( opt , value ) ) <EOL> def _raise_error_iface ( iface , option , expected ) : <EOL> '''<STR_LIT>''' <EOL> msg = _error_msg_iface ( iface , option , expected ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> def _raise_error_network ( option , expected ) : <EOL> '''<STR_LIT>''' <EOL> msg = _error_msg_network ( option , expected ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> def _raise_error_routes ( iface , option , expected ) : <EOL> '''<STR_LIT>''' <EOL> msg = _error_msg_routes ( iface , option , expected ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> def _read_file ( path ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> with salt . utils . flopen ( path , '<STR_LIT:rb>' ) as contents : <EOL> return [ salt . utils . to_str ( line ) for line in contents . readlines ( ) ] <EOL> except ( OSError , IOError ) : <EOL> return '<STR_LIT>' <EOL> def _parse_resolve ( ) : <EOL> '''<STR_LIT>''' <EOL> contents = _read_file ( _DEB_RESOLV_FILE ) <EOL> return contents <EOL> def _parse_domainname ( ) : <EOL> '''<STR_LIT>''' <EOL> contents = _read_file ( _DEB_RESOLV_FILE ) <EOL> pattern = r'<STR_LIT>' <EOL> prog = re . compile ( pattern ) <EOL> for item in contents : <EOL> match = prog . match ( item ) <EOL> if match : <EOL> return match . group ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> def _parse_searchdomain ( ) : <EOL> '''<STR_LIT>''' <EOL> contents = _read_file ( _DEB_RESOLV_FILE ) <EOL> pattern = r'<STR_LIT>' <EOL> prog = re . compile ( pattern ) <EOL> for item in contents : <EOL> match = prog . match ( item ) <EOL> if match : <EOL> return match . group ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> def _parse_hostname ( ) : <EOL> '''<STR_LIT>''' <EOL> contents = _read_file ( _DEB_HOSTNAME_FILE ) <EOL> if contents : <EOL> return contents [ <NUM_LIT:0> ] . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] <EOL> else : <EOL> return '<STR_LIT>' <EOL> def _parse_current_network_settings ( ) : <EOL> '''<STR_LIT>''' <EOL> opts = salt . utils . odict . OrderedDict ( ) <EOL> opts [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if os . path . isfile ( _DEB_NETWORKING_FILE ) : <EOL> with salt . utils . fopen ( _DEB_NETWORKING_FILE ) as contents : <EOL> for line in contents : <EOL> if line . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> opts [ '<STR_LIT>' ] = line . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> hostname = _parse_hostname ( ) <EOL> domainname = _parse_domainname ( ) <EOL> searchdomain = _parse_searchdomain ( ) <EOL> opts [ '<STR_LIT>' ] = hostname <EOL> opts [ '<STR_LIT>' ] = domainname <EOL> opts [ '<STR_LIT>' ] = searchdomain <EOL> return opts <EOL> def __ipv4_quad ( value ) : <EOL> '''<STR_LIT>''' <EOL> return ( salt . utils . validate . net . ipv4_addr ( value ) , value , <EOL> '<STR_LIT>' ) <EOL> def __ipv6 ( value ) : <EOL> '''<STR_LIT>''' <EOL> return ( salt . utils . validate . net . ipv6_addr ( value ) , value , <EOL> '<STR_LIT>' ) <EOL> def __mac ( value ) : <EOL> '''<STR_LIT>''' <EOL> return ( salt . utils . validate . net . mac ( value ) , value , <EOL> '<STR_LIT>' ) <EOL> def __anything ( value ) : <EOL> return ( True , value , None ) <EOL> def __int ( value ) : <EOL> '''<STR_LIT>''' <EOL> valid , _value = False , value <EOL> try : <EOL> _value = int ( value ) <EOL> valid = True <EOL> except ValueError : <EOL> pass <EOL> return ( valid , _value , '<STR_LIT>' ) <EOL> def __float ( value ) : <EOL> '''<STR_LIT>''' <EOL> valid , _value = False , value <EOL> try : <EOL> _value = float ( value ) <EOL> valid = True <EOL> except ValueError : <EOL> pass <EOL> return ( valid , _value , '<STR_LIT:float>' ) <EOL> def __ipv4_netmask ( value ) : <EOL> '''<STR_LIT>''' <EOL> valid , errmsg = False , '<STR_LIT>' <EOL> valid , value , _ = __int ( value ) <EOL> if not ( valid and <NUM_LIT:0> <= value <= <NUM_LIT:32> ) : <EOL> valid = salt . utils . validate . net . netmask ( value ) <EOL> return ( valid , value , errmsg ) <EOL> def __ipv6_netmask ( value ) : <EOL> '''<STR_LIT>''' <EOL> valid , errmsg = False , '<STR_LIT>' <EOL> valid , value , _ = __int ( value ) <EOL> valid = ( valid and <NUM_LIT:0> <= value <= <NUM_LIT> ) <EOL> return ( valid , value , errmsg ) <EOL> def __within2 ( value , within = None , errmsg = None , dtype = None ) : <EOL> '''<STR_LIT>''' <EOL> valid , _value = False , value <EOL> if dtype : <EOL> try : <EOL> _value = dtype ( value ) <EOL> valid = _value in within <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> valid = _value in within <EOL> if errmsg is None : <EOL> if dtype : <EOL> typename = getattr ( dtype , '<STR_LIT>' , <EOL> hasattr ( dtype , '<STR_LIT>' ) <EOL> and getattr ( dtype . __class__ , '<STR_LIT:name>' , dtype ) ) <EOL> errmsg = '<STR_LIT>' . format ( typename , within ) <EOL> else : <EOL> errmsg = '<STR_LIT>' . format ( within ) <EOL> return ( valid , _value , errmsg ) <EOL> def __within ( within = None , errmsg = None , dtype = None ) : <EOL> return functools . partial ( __within2 , within = within , <EOL> errmsg = errmsg , dtype = dtype ) <EOL> def __space_delimited_list ( value ) : <EOL> '''<STR_LIT>''' <EOL> valid , _value , errmsg = False , value , '<STR_LIT>' <EOL> try : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> valid = True <EOL> else : <EOL> _value = value . split ( ) <EOL> if _value == [ ] : <EOL> raise ValueError <EOL> valid = True <EOL> except AttributeError : <EOL> pass <EOL> except ValueError : <EOL> pass <EOL> return ( valid , _value , errmsg ) <EOL> SALT_ATTR_TO_DEBIAN_ATTR_MAP = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:address>' , <EOL> } <EOL> DEBIAN_ATTR_TO_SALT_ATTR_MAP = dict ( <EOL> ( v , k ) for ( k , v ) in six . iteritems ( SALT_ATTR_TO_DEBIAN_ATTR_MAP ) ) <EOL> DEBIAN_ATTR_TO_SALT_ATTR_MAP [ '<STR_LIT:address>' ] = '<STR_LIT:address>' <EOL> DEBIAN_ATTR_TO_SALT_ATTR_MAP [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> IPV4_VALID_PROTO = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> IPV4_ATTR_MAP = { <EOL> '<STR_LIT>' : __within ( IPV4_VALID_PROTO , dtype = str ) , <EOL> '<STR_LIT:address>' : __ipv4_quad , <EOL> '<STR_LIT>' : __ipv4_netmask , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __mac , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __within ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:host>' ] , dtype = str ) , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __mac , <EOL> '<STR_LIT>' : __within ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , dtype = str ) , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __ipv4_quad , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __space_delimited_list , <EOL> '<STR_LIT>' : __space_delimited_list , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT:test>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> } <EOL> IPV6_VALID_PROTO = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> IPV6_ATTR_MAP = { <EOL> '<STR_LIT:address>' : __ipv6 , <EOL> '<STR_LIT>' : __ipv6_netmask , <EOL> '<STR_LIT>' : __ipv6 , <EOL> '<STR_LIT>' : __ipv6 , <EOL> '<STR_LIT>' : __within ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:host>' ] , dtype = str ) , <EOL> '<STR_LIT>' : __within ( IPV6_VALID_PROTO ) , <EOL> '<STR_LIT>' : __within ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , dtype = int ) , <EOL> '<STR_LIT>' : __within ( [ <NUM_LIT:0> , <NUM_LIT:1> ] , dtype = int ) , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __within ( [ <NUM_LIT:0> , <NUM_LIT:1> ] , dtype = int ) , <EOL> '<STR_LIT>' : __within ( [ <NUM_LIT:0> , <NUM_LIT:1> ] , dtype = int ) , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __int , <EOL> '<STR_LIT>' : __float , <EOL> } <EOL> WIRELESS_ATTR_MAP = { <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __within ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , dtype = int ) , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> '<STR_LIT>' : __anything , <EOL> } <EOL> ATTRMAPS = { <EOL> '<STR_LIT>' : [ IPV4_ATTR_MAP , WIRELESS_ATTR_MAP ] , <EOL> '<STR_LIT>' : [ IPV6_ATTR_MAP , IPV4_ATTR_MAP , WIRELESS_ATTR_MAP ] <EOL> } <EOL> def _validate_interface_option ( attr , value , addrfam = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> valid , _value , errmsg = False , value , '<STR_LIT>' <EOL> attrmaps = ATTRMAPS . get ( addrfam , [ ] ) <EOL> for attrmap in attrmaps : <EOL> if attr in attrmap : <EOL> validate_func = attrmap [ attr ] <EOL> ( valid , _value , errmsg ) = validate_func ( value ) <EOL> break <EOL> return ( valid , _value , errmsg ) <EOL> def _attrmaps_contain_attr ( attr ) : <EOL> return ( <EOL> attr in WIRELESS_ATTR_MAP or <EOL> attr in IPV4_ATTR_MAP or <EOL> attr in IPV6_ATTR_MAP ) <EOL> def _parse_interfaces ( interface_files = None ) : <EOL> '''<STR_LIT>''' <EOL> if interface_files is None : <EOL> interface_files = [ ] <EOL> if os . path . exists ( _DEB_NETWORK_DIR ) : <EOL> interface_files += [ '<STR_LIT>' . format ( _DEB_NETWORK_DIR , dir ) for dir in os . listdir ( _DEB_NETWORK_DIR ) ] <EOL> if os . path . isfile ( _DEB_NETWORK_FILE ) : <EOL> interface_files . insert ( <NUM_LIT:0> , _DEB_NETWORK_FILE ) <EOL> adapters = salt . utils . odict . OrderedDict ( ) <EOL> method = - <NUM_LIT:1> <EOL> for interface_file in interface_files : <EOL> with salt . utils . fopen ( interface_file ) as interfaces : <EOL> for line in interfaces : <EOL> if line . lstrip ( ) . startswith ( '<STR_LIT:#>' ) or line . isspace ( ) : <EOL> continue <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> sline = line . split ( ) <EOL> if len ( sline ) != <NUM_LIT:4> : <EOL> msg = '<STR_LIT>' <EOL> msg = msg . format ( sline ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> iface_name = sline [ <NUM_LIT:1> ] <EOL> addrfam = sline [ <NUM_LIT:2> ] <EOL> method = sline [ <NUM_LIT:3> ] <EOL> if iface_name not in adapters : <EOL> adapters [ iface_name ] = salt . utils . odict . OrderedDict ( ) <EOL> if '<STR_LIT:data>' not in adapters [ iface_name ] : <EOL> adapters [ iface_name ] [ '<STR_LIT:data>' ] = salt . utils . odict . OrderedDict ( ) <EOL> if addrfam not in adapters [ iface_name ] [ '<STR_LIT:data>' ] : <EOL> adapters [ iface_name ] [ '<STR_LIT:data>' ] [ addrfam ] = salt . utils . odict . OrderedDict ( ) <EOL> iface_dict = adapters [ iface_name ] [ '<STR_LIT:data>' ] [ addrfam ] <EOL> iface_dict [ '<STR_LIT>' ] = addrfam <EOL> iface_dict [ '<STR_LIT>' ] = method <EOL> iface_dict [ '<STR_LIT:filename>' ] = interface_file <EOL> elif line [ <NUM_LIT:0> ] . isspace ( ) : <EOL> sline = line . split ( ) <EOL> attr , valuestr = line . rstrip ( ) . split ( None , <NUM_LIT:1> ) <EOL> if _attrmaps_contain_attr ( attr ) : <EOL> if '<STR_LIT:->' in attr : <EOL> attrname = attr . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> else : <EOL> attrname = attr <EOL> ( valid , value , errmsg ) = _validate_interface_option ( <EOL> attr , valuestr , addrfam ) <EOL> iface_dict [ attrname ] = value <EOL> elif attr in _REV_ETHTOOL_CONFIG_OPTS : <EOL> if '<STR_LIT>' not in iface_dict : <EOL> iface_dict [ '<STR_LIT>' ] = salt . utils . odict . OrderedDict ( ) <EOL> iface_dict [ '<STR_LIT>' ] [ attr ] = valuestr <EOL> elif attr . startswith ( '<STR_LIT>' ) : <EOL> opt = re . split ( r'<STR_LIT>' , attr , maxsplit = <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> if '<STR_LIT>' not in iface_dict : <EOL> iface_dict [ '<STR_LIT>' ] = salt . utils . odict . OrderedDict ( ) <EOL> iface_dict [ '<STR_LIT>' ] [ opt ] = valuestr <EOL> elif attr . startswith ( '<STR_LIT>' ) : <EOL> opt = re . split ( r'<STR_LIT>' , attr , maxsplit = <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> if '<STR_LIT>' not in iface_dict : <EOL> iface_dict [ '<STR_LIT>' ] = salt . utils . odict . OrderedDict ( ) <EOL> iface_dict [ '<STR_LIT>' ] [ opt ] = valuestr <EOL> elif attr in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> cmd = valuestr <EOL> cmd_key = '<STR_LIT>' . format ( re . sub ( '<STR_LIT:->' , '<STR_LIT:_>' , attr ) ) <EOL> if cmd_key not in iface_dict : <EOL> iface_dict [ cmd_key ] = [ ] <EOL> iface_dict [ cmd_key ] . append ( cmd ) <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> for word in line . split ( ) [ <NUM_LIT:1> : ] : <EOL> if word not in adapters : <EOL> adapters [ word ] = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ word ] [ '<STR_LIT>' ] = True <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> for word in line . split ( ) [ <NUM_LIT:1> : ] : <EOL> if word not in adapters : <EOL> adapters [ word ] = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ word ] [ '<STR_LIT>' ] = True <EOL> elif line . startswith ( '<STR_LIT:source>' ) : <EOL> if '<STR_LIT:source>' not in adapters : <EOL> adapters [ '<STR_LIT:source>' ] = salt . utils . odict . OrderedDict ( ) <EOL> if '<STR_LIT:data>' not in adapters [ '<STR_LIT:source>' ] : <EOL> adapters [ '<STR_LIT:source>' ] [ '<STR_LIT:data>' ] = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ '<STR_LIT:source>' ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] = [ ] <EOL> adapters [ '<STR_LIT:source>' ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] . append ( line . split ( ) [ <NUM_LIT:1> ] ) <EOL> for iface_name in adapters : <EOL> if iface_name == '<STR_LIT:source>' : <EOL> continue <EOL> if '<STR_LIT:data>' not in adapters [ iface_name ] : <EOL> msg = '<STR_LIT>' . format ( iface_name ) <EOL> log . error ( msg ) <EOL> adapters . pop ( iface_name ) <EOL> continue <EOL> for opt in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in adapters [ iface_name ] [ '<STR_LIT:data>' ] : <EOL> if opt in adapters [ iface_name ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] : <EOL> opt_keys = sorted ( adapters [ iface_name ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ opt ] . keys ( ) ) <EOL> adapters [ iface_name ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ opt + '<STR_LIT>' ] = opt_keys <EOL> return adapters <EOL> def _parse_ethtool_opts ( opts , iface ) : <EOL> '''<STR_LIT>''' <EOL> config = { } <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> config . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> config . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , _CONFIG_TRUE + _CONFIG_FALSE ) <EOL> if '<STR_LIT>' in opts : <EOL> valid = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if opts [ '<STR_LIT>' ] in valid : <EOL> config . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> if '<STR_LIT>' in opts : <EOL> valid = [ '<STR_LIT>' , '<STR_LIT:100>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if str ( opts [ '<STR_LIT>' ] ) in valid : <EOL> config . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> else : <EOL> _raise_error_iface ( iface , opts [ '<STR_LIT>' ] , valid ) <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> for option in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if option in opts : <EOL> if opts [ option ] in _CONFIG_TRUE : <EOL> config . update ( { option : '<STR_LIT>' } ) <EOL> elif opts [ option ] in _CONFIG_FALSE : <EOL> config . update ( { option : '<STR_LIT>' } ) <EOL> else : <EOL> _raise_error_iface ( iface , option , valid ) <EOL> return config <EOL> def _parse_ethtool_pppoe_opts ( opts , iface ) : <EOL> '''<STR_LIT>''' <EOL> config = { } <EOL> for opt in _DEB_CONFIG_PPPOE_OPTS : <EOL> if opt in opts : <EOL> config [ opt ] = opts [ opt ] <EOL> if '<STR_LIT>' in opts and not opts [ '<STR_LIT>' ] : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , _CONFIG_TRUE + _CONFIG_FALSE ) <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> for option in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if option in opts : <EOL> if opts [ option ] in _CONFIG_TRUE : <EOL> config . update ( { option : '<STR_LIT:True>' } ) <EOL> elif opts [ option ] in _CONFIG_FALSE : <EOL> config . update ( { option : '<STR_LIT:False>' } ) <EOL> else : <EOL> _raise_error_iface ( iface , option , valid ) <EOL> return config <EOL> def _parse_settings_bond ( opts , iface ) : <EOL> '''<STR_LIT>''' <EOL> bond_def = { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:100>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT:0>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' . format ( <EOL> iface <EOL> ) <EOL> ) <EOL> return _parse_settings_bond_0 ( opts , iface , bond_def ) <EOL> elif opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT:1>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' . format ( <EOL> iface <EOL> ) <EOL> ) <EOL> return _parse_settings_bond_1 ( opts , iface , bond_def ) <EOL> elif opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT:2>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' . format ( iface ) <EOL> ) <EOL> return _parse_settings_bond_2 ( opts , iface , bond_def ) <EOL> elif opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT:3>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' . format ( <EOL> iface <EOL> ) <EOL> ) <EOL> return _parse_settings_bond_3 ( opts , iface , bond_def ) <EOL> elif opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT:4>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( iface ) <EOL> ) <EOL> return _parse_settings_bond_4 ( opts , iface , bond_def ) <EOL> elif opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT:5>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' . format ( iface ) <EOL> ) <EOL> return _parse_settings_bond_5 ( opts , iface , bond_def ) <EOL> elif opts [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> log . info ( <EOL> '<STR_LIT>' . format ( iface ) <EOL> ) <EOL> return _parse_settings_bond_6 ( opts , iface , bond_def ) <EOL> else : <EOL> valid = [ <EOL> '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' , '<STR_LIT:4>' , '<STR_LIT:5>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> def _parse_settings_bond_0 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT:0>' } <EOL> valid = [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in opts : <EOL> if isinstance ( opts [ '<STR_LIT>' ] , list ) : <EOL> if <NUM_LIT:1> <= len ( opts [ '<STR_LIT>' ] ) <= <NUM_LIT:16> : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> for ip in opts [ '<STR_LIT>' ] : <EOL> if len ( bond [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> bond [ '<STR_LIT>' ] = bond [ '<STR_LIT>' ] + '<STR_LIT:U+002C>' + ip <EOL> else : <EOL> bond [ '<STR_LIT>' ] = ip <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> if '<STR_LIT>' in opts : <EOL> try : <EOL> int ( opts [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> return bond <EOL> def _parse_settings_bond_1 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT:1>' } <EOL> for binding in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if binding in opts : <EOL> try : <EOL> int ( opts [ binding ] ) <EOL> bond . update ( { binding : opts [ binding ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , binding , [ '<STR_LIT>' ] ) <EOL> else : <EOL> _log_default_iface ( iface , binding , bond_def [ binding ] ) <EOL> bond . update ( { binding : bond_def [ binding ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> else : <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> return bond <EOL> def _parse_settings_bond_2 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT:2>' } <EOL> valid = [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in opts : <EOL> if isinstance ( opts [ '<STR_LIT>' ] , list ) : <EOL> if <NUM_LIT:1> <= len ( opts [ '<STR_LIT>' ] ) <= <NUM_LIT:16> : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> for ip in opts [ '<STR_LIT>' ] : <EOL> if len ( bond [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> bond [ '<STR_LIT>' ] = bond [ '<STR_LIT>' ] + '<STR_LIT:U+002C>' + ip <EOL> else : <EOL> bond [ '<STR_LIT>' ] = ip <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> if '<STR_LIT>' in opts : <EOL> try : <EOL> int ( opts [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> bond . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> valid = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if opts [ '<STR_LIT>' ] in valid : <EOL> bond . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> return bond <EOL> def _parse_settings_bond_3 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT:3>' } <EOL> for binding in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if binding in opts : <EOL> try : <EOL> int ( opts [ binding ] ) <EOL> bond . update ( { binding : opts [ binding ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , binding , [ '<STR_LIT>' ] ) <EOL> else : <EOL> _log_default_iface ( iface , binding , bond_def [ binding ] ) <EOL> bond . update ( { binding : bond_def [ binding ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> else : <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> return bond <EOL> def _parse_settings_bond_4 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT:4>' } <EOL> for binding in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if binding in opts : <EOL> if binding == '<STR_LIT>' : <EOL> if opts [ binding ] == '<STR_LIT>' : <EOL> opts . update ( { binding : '<STR_LIT:1>' } ) <EOL> if opts [ binding ] == '<STR_LIT>' : <EOL> opts . update ( { binding : '<STR_LIT:0>' } ) <EOL> valid = [ '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT:0>' ] <EOL> else : <EOL> valid = [ '<STR_LIT>' ] <EOL> try : <EOL> int ( opts [ binding ] ) <EOL> bond . update ( { binding : opts [ binding ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , binding , valid ) <EOL> else : <EOL> _log_default_iface ( iface , binding , bond_def [ binding ] ) <EOL> bond . update ( { binding : bond_def [ binding ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> else : <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> valid = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if opts [ '<STR_LIT>' ] in valid : <EOL> bond . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> return bond <EOL> def _parse_settings_bond_5 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT:5>' } <EOL> for binding in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if binding in opts : <EOL> try : <EOL> int ( opts [ binding ] ) <EOL> bond . update ( { binding : opts [ binding ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , binding , [ '<STR_LIT>' ] ) <EOL> else : <EOL> _log_default_iface ( iface , binding , bond_def [ binding ] ) <EOL> bond . update ( { binding : bond_def [ binding ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> else : <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> return bond <EOL> def _parse_settings_bond_6 ( opts , iface , bond_def ) : <EOL> '''<STR_LIT>''' <EOL> bond = { '<STR_LIT>' : '<STR_LIT>' } <EOL> for binding in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if binding in opts : <EOL> try : <EOL> int ( opts [ binding ] ) <EOL> bond . update ( { binding : opts [ binding ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , binding , [ '<STR_LIT>' ] ) <EOL> else : <EOL> _log_default_iface ( iface , binding , bond_def [ binding ] ) <EOL> bond . update ( { binding : bond_def [ binding ] } ) <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:1>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> bond . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> else : <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> _raise_error_iface ( iface , '<STR_LIT>' , valid ) <EOL> else : <EOL> _log_default_iface ( iface , '<STR_LIT>' , bond_def [ '<STR_LIT>' ] ) <EOL> bond . update ( { '<STR_LIT>' : bond_def [ '<STR_LIT>' ] } ) <EOL> return bond <EOL> def _parse_bridge_opts ( opts , iface ) : <EOL> '''<STR_LIT>''' <EOL> config = { } <EOL> if '<STR_LIT>' in opts : <EOL> if isinstance ( opts [ '<STR_LIT>' ] , list ) : <EOL> opts [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( opts [ '<STR_LIT>' ] ) <EOL> config . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> for opt in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:hello>' , '<STR_LIT>' ] : <EOL> if opt in opts : <EOL> try : <EOL> float ( opts [ opt ] ) <EOL> config . update ( { opt : opts [ opt ] } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , opt , [ '<STR_LIT:float>' ] ) <EOL> for opt in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if opt in opts : <EOL> if isinstance ( opts [ opt ] , int ) : <EOL> config . update ( { opt : opts [ opt ] } ) <EOL> else : <EOL> _raise_error_iface ( iface , opt , [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in opts : <EOL> if re . match ( '<STR_LIT>' , <EOL> opts [ '<STR_LIT>' ] . lower ( ) ) : <EOL> config . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> for opt in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if opt in opts : <EOL> try : <EOL> port , cost_or_prio = opts [ opt ] . split ( ) <EOL> int ( cost_or_prio ) <EOL> config . update ( { opt : '<STR_LIT>' . format ( port , cost_or_prio ) } ) <EOL> except ValueError : <EOL> _raise_error_iface ( iface , opt , [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in opts : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> config . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> config . update ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> else : <EOL> _raise_error_iface ( iface , '<STR_LIT>' , _CONFIG_TRUE + _CONFIG_FALSE ) <EOL> if '<STR_LIT>' in opts : <EOL> if isinstance ( opts [ '<STR_LIT>' ] , int ) : <EOL> config . update ( { '<STR_LIT>' : opts [ '<STR_LIT>' ] } ) <EOL> else : <EOL> values = opts [ '<STR_LIT>' ] . split ( ) <EOL> waitport_time = values . pop ( <NUM_LIT:0> ) <EOL> if waitport_time . isdigit ( ) and values : <EOL> config . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( <EOL> waitport_time , '<STR_LIT:U+0020>' . join ( values ) <EOL> ) <EOL> } ) <EOL> else : <EOL> _raise_error_iface ( iface , opt , [ '<STR_LIT>' ] ) <EOL> return config <EOL> def _parse_settings_eth ( opts , iface_type , enabled , iface ) : <EOL> '''<STR_LIT>''' <EOL> adapters = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ iface ] = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ iface ] [ '<STR_LIT:type>' ] = iface_type <EOL> adapters [ iface ] [ '<STR_LIT:data>' ] = salt . utils . odict . OrderedDict ( ) <EOL> iface_data = adapters [ iface ] [ '<STR_LIT:data>' ] <EOL> iface_data [ '<STR_LIT>' ] = salt . utils . odict . OrderedDict ( ) <EOL> if enabled : <EOL> adapters [ iface ] [ '<STR_LIT>' ] = True <EOL> if opts . get ( '<STR_LIT>' , False ) : <EOL> adapters [ iface ] [ '<STR_LIT>' ] = True <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if iface_type not in [ '<STR_LIT>' ] : <EOL> tmp_ethtool = _parse_ethtool_opts ( opts , iface ) <EOL> if tmp_ethtool : <EOL> ethtool = { } <EOL> for item in tmp_ethtool : <EOL> ethtool [ _ETHTOOL_CONFIG_OPTS [ item ] ] = tmp_ethtool [ item ] <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = ethtool <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = sorted ( ethtool ) <EOL> if iface_type == '<STR_LIT>' : <EOL> bridging = _parse_bridge_opts ( opts , iface ) <EOL> if bridging : <EOL> opts . pop ( '<STR_LIT>' , None ) <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = bridging <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = sorted ( bridging ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> bonding = _parse_settings_bond ( opts , iface ) <EOL> if bonding : <EOL> opts . pop ( '<STR_LIT>' , None ) <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = bonding <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = sorted ( bonding ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> adapters [ iface ] [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> elif iface_type == '<STR_LIT>' : <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , iface ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> tmp_ethtool = _parse_ethtool_pppoe_opts ( opts , iface ) <EOL> if tmp_ethtool : <EOL> for item in tmp_ethtool : <EOL> adapters [ iface ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ _DEB_CONFIG_PPPOE_OPTS [ item ] ] = tmp_ethtool [ item ] <EOL> if '<STR_LIT>' in opts and opts [ '<STR_LIT>' ] : <EOL> iface_data [ '<STR_LIT>' ] = { } <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' in opts and opts [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> iface_data [ '<STR_LIT>' ] [ '<STR_LIT>' ] = ( <EOL> re . sub ( r'<STR_LIT>' , '<STR_LIT>' , iface ) ) <EOL> for opt in opts : <EOL> if opt . startswith ( '<STR_LIT>' ) : <EOL> optname = opt [ <NUM_LIT:4> : ] <EOL> addrfam = '<STR_LIT>' <EOL> else : <EOL> optname = opt <EOL> addrfam = '<STR_LIT>' <EOL> _optname = SALT_ATTR_TO_DEBIAN_ATTR_MAP . get ( optname , optname ) <EOL> if _attrmaps_contain_attr ( _optname ) : <EOL> valuestr = opts [ opt ] <EOL> if optname == '<STR_LIT>' and valuestr == '<STR_LIT:none>' : <EOL> valuestr = '<STR_LIT>' <EOL> ( valid , value , errmsg ) = _validate_interface_option ( <EOL> _optname , valuestr , addrfam = addrfam ) <EOL> if not valid : <EOL> _raise_error_iface ( <EOL> iface , <EOL> '<STR_LIT>' . format ( opt , valuestr ) , <EOL> [ errmsg ] <EOL> ) <EOL> _optname = _optname . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> iface_data [ addrfam ] [ _optname ] = value <EOL> for opt in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if opt in opts : <EOL> iface_data [ '<STR_LIT>' ] [ opt ] = opts [ opt ] <EOL> return adapters <EOL> def _parse_settings_source ( opts , iface_type , enabled , iface ) : <EOL> '''<STR_LIT>''' <EOL> adapters = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ iface ] = salt . utils . odict . OrderedDict ( ) <EOL> adapters [ iface ] [ '<STR_LIT:type>' ] = iface_type <EOL> adapters [ iface ] [ '<STR_LIT:data>' ] = salt . utils . odict . OrderedDict ( ) <EOL> iface_data = adapters [ iface ] [ '<STR_LIT:data>' ] <EOL> iface_data [ '<STR_LIT>' ] = [ opts [ '<STR_LIT:source>' ] ] <EOL> return adapters <EOL> def _parse_network_settings ( opts , current ) : <EOL> '''<STR_LIT>''' <EOL> opts = dict ( ( k . lower ( ) , v ) for ( k , v ) in six . iteritems ( opts ) ) <EOL> current = dict ( ( k . lower ( ) , v ) for ( k , v ) in six . iteritems ( current ) ) <EOL> result = { } <EOL> valid = _CONFIG_TRUE + _CONFIG_FALSE <EOL> if '<STR_LIT>' not in opts : <EOL> try : <EOL> opts [ '<STR_LIT>' ] = current [ '<STR_LIT>' ] <EOL> _log_default_network ( '<STR_LIT>' , current [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> _raise_error_network ( '<STR_LIT>' , valid ) <EOL> else : <EOL> opts [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> if opts [ '<STR_LIT>' ] in valid : <EOL> if opts [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> result [ '<STR_LIT>' ] = '<STR_LIT:yes>' <EOL> elif opts [ '<STR_LIT>' ] in _CONFIG_FALSE : <EOL> result [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> _raise_error_network ( '<STR_LIT>' , valid ) <EOL> if '<STR_LIT>' not in opts : <EOL> try : <EOL> opts [ '<STR_LIT>' ] = current [ '<STR_LIT>' ] <EOL> _log_default_network ( '<STR_LIT>' , current [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> _raise_error_network ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> if opts [ '<STR_LIT>' ] : <EOL> result [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> else : <EOL> _raise_error_network ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in opts : <EOL> result [ '<STR_LIT>' ] = opts [ '<STR_LIT>' ] <EOL> return result <EOL> def _parse_routes ( iface , opts ) : <EOL> '''<STR_LIT>''' <EOL> opts = dict ( ( k . lower ( ) , v ) for ( k , v ) in six . iteritems ( opts ) ) <EOL> result = { } <EOL> if '<STR_LIT>' not in opts : <EOL> _raise_error_routes ( iface , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for opt in opts : <EOL> result [ opt ] = opts [ opt ] <EOL> return result <EOL> def _write_file ( iface , data , folder , pattern ) : <EOL> '''<STR_LIT>''' <EOL> filename = os . path . join ( folder , pattern . format ( iface ) ) <EOL> if not os . path . exists ( folder ) : <EOL> msg = '<STR_LIT>' <EOL> msg = msg . format ( filename , folder ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> with salt . utils . flopen ( filename , '<STR_LIT:w>' ) as fout : <EOL> fout . write ( data ) <EOL> return filename <EOL> def _write_file_routes ( iface , data , folder , pattern ) : <EOL> '''<STR_LIT>''' <EOL> filename = os . path . join ( folder , pattern . format ( iface ) ) <EOL> if not os . path . exists ( folder ) : <EOL> msg = '<STR_LIT>' <EOL> msg = msg . format ( filename , folder ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> with salt . utils . flopen ( filename , '<STR_LIT:w>' ) as fout : <EOL> fout . write ( data ) <EOL> __salt__ [ '<STR_LIT>' ] ( filename , '<STR_LIT>' ) <EOL> return filename <EOL> def _write_file_network ( data , filename , create = False ) : <EOL> '''<STR_LIT>''' <EOL> if not os . path . exists ( filename ) and not create : <EOL> msg = '<STR_LIT>' <EOL> msg = msg . format ( filename ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> with salt . utils . flopen ( filename , '<STR_LIT:w>' ) as fout : <EOL> fout . write ( data ) <EOL> def _read_temp ( data ) : <EOL> '''<STR_LIT>''' <EOL> tout = StringIO ( ) <EOL> tout . write ( data ) <EOL> tout . seek ( <NUM_LIT:0> ) <EOL> output = tout . readlines ( ) <EOL> tout . close ( ) <EOL> return output <EOL> def _read_temp_ifaces ( iface , data ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> ifcfg = template . render ( { '<STR_LIT:name>' : iface , '<STR_LIT:data>' : data } ) <EOL> return [ item + '<STR_LIT:\n>' for item in ifcfg . split ( '<STR_LIT:\n>' ) ] <EOL> def _write_file_ifaces ( iface , data , ** settings ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> eth_template = JINJA . get_template ( '<STR_LIT>' ) <EOL> source_template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> adapters = _parse_interfaces ( ) <EOL> adapters [ iface ] = data <EOL> ifcfg = '<STR_LIT>' <EOL> for adapter in adapters : <EOL> if '<STR_LIT:type>' in adapters [ adapter ] and adapters [ adapter ] [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> adapters [ adapter ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> adapters [ adapter ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> adapters [ adapter ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = adapters [ adapter ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT:type>' in adapters [ adapter ] and adapters [ adapter ] [ '<STR_LIT:type>' ] == '<STR_LIT:source>' : <EOL> tmp = source_template . render ( { '<STR_LIT:name>' : adapter , '<STR_LIT:data>' : adapters [ adapter ] } ) <EOL> else : <EOL> tmp = eth_template . render ( { '<STR_LIT:name>' : adapter , '<STR_LIT:data>' : adapters [ adapter ] } ) <EOL> ifcfg = ifcfg + tmp <EOL> if adapter == iface : <EOL> saved_ifcfg = tmp <EOL> _SEPERATE_FILE = False <EOL> if '<STR_LIT:filename>' in settings : <EOL> if not settings [ '<STR_LIT:filename>' ] . startswith ( '<STR_LIT:/>' ) : <EOL> filename = '<STR_LIT>' . format ( _DEB_NETWORK_DIR , settings [ '<STR_LIT:filename>' ] ) <EOL> else : <EOL> filename = settings [ '<STR_LIT:filename>' ] <EOL> _SEPERATE_FILE = True <EOL> else : <EOL> if '<STR_LIT:filename>' in adapters [ adapter ] [ '<STR_LIT:data>' ] : <EOL> filename = adapters [ adapter ] [ '<STR_LIT:data>' ] <EOL> else : <EOL> filename = _DEB_NETWORK_FILE <EOL> if not os . path . exists ( os . path . dirname ( filename ) ) : <EOL> msg = '<STR_LIT>' <EOL> msg = msg . format ( os . path . dirname ( filename ) ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> with salt . utils . flopen ( filename , '<STR_LIT:w>' ) as fout : <EOL> if _SEPERATE_FILE : <EOL> fout . write ( saved_ifcfg ) <EOL> else : <EOL> fout . write ( ifcfg ) <EOL> return saved_ifcfg . split ( '<STR_LIT:\n>' ) <EOL> def _write_file_ppp_ifaces ( iface , data ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> adapters = _parse_interfaces ( ) <EOL> adapters [ iface ] = data <EOL> ifcfg = '<STR_LIT>' <EOL> tmp = template . render ( { '<STR_LIT:data>' : adapters [ iface ] } ) <EOL> ifcfg = tmp + ifcfg <EOL> filename = _DEB_PPP_DIR + '<STR_LIT:/>' + adapters [ iface ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if not os . path . exists ( os . path . dirname ( filename ) ) : <EOL> msg = '<STR_LIT>' <EOL> msg = msg . format ( os . path . dirname ( filename ) ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> with salt . utils . fopen ( filename , '<STR_LIT:w>' ) as fout : <EOL> fout . write ( ifcfg ) <EOL> return filename <EOL> def build_bond ( iface , ** settings ) : <EOL> '''<STR_LIT>''' <EOL> deb_major = __grains__ [ '<STR_LIT>' ] [ : <NUM_LIT:1> ] <EOL> opts = _parse_settings_bond ( settings , iface ) <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> data = template . render ( { '<STR_LIT:name>' : iface , '<STR_LIT>' : opts } ) <EOL> if '<STR_LIT:test>' in settings and settings [ '<STR_LIT:test>' ] : <EOL> return _read_temp ( data ) <EOL> _write_file ( iface , data , _DEB_NETWORK_CONF_FILES , '<STR_LIT>' . format ( iface ) ) <EOL> path = os . path . join ( _DEB_NETWORK_CONF_FILES , '<STR_LIT>' . format ( iface ) ) <EOL> if deb_major == '<STR_LIT:5>' : <EOL> for line_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , r'<STR_LIT>' . format ( line_type , iface ) , <EOL> '<STR_LIT>' ] <EOL> __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , path ) <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> return _read_file ( path ) <EOL> def build_interface ( iface , iface_type , enabled , ** settings ) : <EOL> '''<STR_LIT>''' <EOL> iface = iface . lower ( ) <EOL> iface_type = iface_type . lower ( ) <EOL> if iface_type not in _IFACE_TYPES : <EOL> _raise_error_iface ( iface , iface_type , _IFACE_TYPES ) <EOL> if '<STR_LIT>' not in settings : <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if iface_type == '<STR_LIT>' : <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT:yes>' <EOL> if '<STR_LIT>' not in settings : <EOL> msg = '<STR_LIT>' <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT:yes>' <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT:yes>' <EOL> if not __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) : <EOL> inst = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> if '<STR_LIT>' not in settings : <EOL> msg = '<STR_LIT>' <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> elif iface_type == '<STR_LIT>' : <EOL> if '<STR_LIT>' not in settings : <EOL> msg = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> log . error ( msg ) <EOL> raise AttributeError ( msg ) <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> if iface_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> opts = _parse_settings_eth ( settings , iface_type , enabled , iface ) <EOL> if iface_type in [ '<STR_LIT:source>' ] : <EOL> opts = _parse_settings_source ( settings , iface_type , enabled , iface ) <EOL> if '<STR_LIT:test>' in settings and settings [ '<STR_LIT:test>' ] : <EOL> return _read_temp_ifaces ( iface , opts [ iface ] ) <EOL> ifcfg = _write_file_ifaces ( iface , opts [ iface ] , ** settings ) <EOL> if iface_type == '<STR_LIT>' : <EOL> _write_file_ppp_ifaces ( iface , opts [ iface ] ) <EOL> return [ item + '<STR_LIT:\n>' for item in ifcfg ] <EOL> def build_routes ( iface , ** settings ) : <EOL> '''<STR_LIT>''' <EOL> iface = iface . lower ( ) <EOL> opts = _parse_routes ( iface , settings ) <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> add_routecfg = template . render ( route_type = '<STR_LIT>' , <EOL> routes = opts [ '<STR_LIT>' ] , <EOL> iface = iface ) <EOL> del_routecfg = template . render ( route_type = '<STR_LIT>' , <EOL> routes = opts [ '<STR_LIT>' ] , <EOL> iface = iface ) <EOL> if '<STR_LIT:test>' in settings and settings [ '<STR_LIT:test>' ] : <EOL> return _read_temp ( add_routecfg + del_routecfg ) <EOL> filename = _write_file_routes ( iface , <EOL> add_routecfg , <EOL> _DEB_NETWORK_UP_DIR , <EOL> '<STR_LIT>' ) <EOL> results = _read_file ( filename ) <EOL> filename = _write_file_routes ( iface , <EOL> del_routecfg , <EOL> _DEB_NETWORK_DOWN_DIR , <EOL> '<STR_LIT>' ) <EOL> results += _read_file ( filename ) <EOL> return results <EOL> def down ( iface , iface_type ) : <EOL> '''<STR_LIT>''' <EOL> if iface_type not in [ '<STR_LIT>' , '<STR_LIT:source>' ] : <EOL> return __salt__ [ '<STR_LIT>' ] ( [ '<STR_LIT>' , iface ] ) <EOL> return None <EOL> def get_bond ( iface ) : <EOL> '''<STR_LIT>''' <EOL> path = os . path . join ( _DEB_NETWORK_CONF_FILES , '<STR_LIT>' . format ( iface ) ) <EOL> return _read_file ( path ) <EOL> def get_interface ( iface ) : <EOL> '''<STR_LIT>''' <EOL> adapters = _parse_interfaces ( ) <EOL> if iface in adapters : <EOL> try : <EOL> if iface == '<STR_LIT:source>' : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> else : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> ifcfg = template . render ( { '<STR_LIT:name>' : iface , '<STR_LIT:data>' : adapters [ iface ] } ) <EOL> return [ item + '<STR_LIT:\n>' for item in ifcfg . split ( '<STR_LIT:\n>' ) ] <EOL> else : <EOL> return [ ] <EOL> def up ( iface , iface_type ) : <EOL> '''<STR_LIT>''' <EOL> if iface_type not in ( '<STR_LIT>' , '<STR_LIT:source>' ) : <EOL> return __salt__ [ '<STR_LIT>' ] ( [ '<STR_LIT>' , iface ] ) <EOL> return None <EOL> def get_network_settings ( ) : <EOL> '''<STR_LIT>''' <EOL> skip_etc_default_networking = ( <EOL> __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' and <EOL> int ( __grains__ [ '<STR_LIT>' ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) >= <NUM_LIT:12> ) <EOL> if skip_etc_default_networking : <EOL> settings = { } <EOL> if __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) : <EOL> if __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) : <EOL> settings [ '<STR_LIT>' ] = "<STR_LIT:yes>" <EOL> else : <EOL> settings [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> else : <EOL> settings [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> hostname = _parse_hostname ( ) <EOL> domainname = _parse_domainname ( ) <EOL> settings [ '<STR_LIT>' ] = hostname <EOL> settings [ '<STR_LIT>' ] = domainname <EOL> else : <EOL> settings = _parse_current_network_settings ( ) <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> network = template . render ( settings ) <EOL> return _read_temp ( network ) <EOL> def get_routes ( iface ) : <EOL> '''<STR_LIT>''' <EOL> filename = os . path . join ( _DEB_NETWORK_UP_DIR , '<STR_LIT>' . format ( iface ) ) <EOL> results = _read_file ( filename ) <EOL> filename = os . path . join ( _DEB_NETWORK_DOWN_DIR , '<STR_LIT>' . format ( iface ) ) <EOL> results += _read_file ( filename ) <EOL> return results <EOL> def apply_network_settings ( ** settings ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' not in settings : <EOL> settings [ '<STR_LIT>' ] = False <EOL> if '<STR_LIT>' not in settings : <EOL> settings [ '<STR_LIT>' ] = False <EOL> hostname_res = True <EOL> if settings [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> if '<STR_LIT>' in settings : <EOL> hostname_res = __salt__ [ '<STR_LIT>' ] ( settings [ '<STR_LIT>' ] ) <EOL> else : <EOL> log . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> hostname_res = False <EOL> res = True <EOL> if settings [ '<STR_LIT>' ] in _CONFIG_TRUE : <EOL> log . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> res = True <EOL> else : <EOL> stop = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> res = stop and __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> return hostname_res and res <EOL> def build_network_settings ( ** settings ) : <EOL> '''<STR_LIT>''' <EOL> changes = [ ] <EOL> current_network_settings = _parse_current_network_settings ( ) <EOL> opts = _parse_network_settings ( settings , current_network_settings ) <EOL> skip_etc_default_networking = ( <EOL> __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' and <EOL> int ( __grains__ [ '<STR_LIT>' ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) >= <NUM_LIT:12> ) <EOL> if skip_etc_default_networking : <EOL> if opts [ '<STR_LIT>' ] == '<STR_LIT:yes>' : <EOL> service_cmd = '<STR_LIT>' <EOL> else : <EOL> service_cmd = '<STR_LIT>' <EOL> if __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) : <EOL> __salt__ [ service_cmd ] ( '<STR_LIT>' ) <EOL> if __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) : <EOL> __salt__ [ service_cmd ] ( '<STR_LIT>' ) <EOL> else : <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> network = template . render ( opts ) <EOL> if '<STR_LIT:test>' in settings and settings [ '<STR_LIT:test>' ] : <EOL> return _read_temp ( network ) <EOL> _write_file_network ( network , _DEB_NETWORKING_FILE , True ) <EOL> sline = opts [ '<STR_LIT>' ] . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> opts [ '<STR_LIT>' ] = sline [ <NUM_LIT:0> ] <EOL> hostname = '<STR_LIT>' . format ( opts [ '<STR_LIT>' ] ) <EOL> current_domainname = current_network_settings [ '<STR_LIT>' ] <EOL> current_searchdomain = current_network_settings [ '<STR_LIT>' ] <EOL> if not opts [ '<STR_LIT>' ] == current_network_settings [ '<STR_LIT>' ] : <EOL> if not ( '<STR_LIT:test>' in settings and settings [ '<STR_LIT:test>' ] ) : <EOL> _write_file_network ( hostname , _DEB_HOSTNAME_FILE ) <EOL> new_domain = False <EOL> if len ( sline ) > <NUM_LIT:1> : <EOL> new_domainname = sline [ <NUM_LIT:1> ] <EOL> if new_domainname != current_domainname : <EOL> domainname = new_domainname <EOL> opts [ '<STR_LIT>' ] = new_domainname <EOL> new_domain = True <EOL> else : <EOL> domainname = current_domainname <EOL> opts [ '<STR_LIT>' ] = domainname <EOL> else : <EOL> domainname = current_domainname <EOL> opts [ '<STR_LIT>' ] = domainname <EOL> new_search = False <EOL> if '<STR_LIT>' in opts : <EOL> new_searchdomain = opts [ '<STR_LIT>' ] <EOL> if new_searchdomain != current_searchdomain : <EOL> searchdomain = new_searchdomain <EOL> opts [ '<STR_LIT>' ] = new_searchdomain <EOL> new_search = True <EOL> else : <EOL> searchdomain = current_searchdomain <EOL> opts [ '<STR_LIT>' ] = searchdomain <EOL> else : <EOL> searchdomain = current_searchdomain <EOL> opts [ '<STR_LIT>' ] = searchdomain <EOL> if new_domain or new_search : <EOL> contents = _parse_resolve ( ) <EOL> domain_prog = re . compile ( r'<STR_LIT>' ) <EOL> search_prog = re . compile ( r'<STR_LIT>' ) <EOL> new_contents = [ ] <EOL> found_domain = False <EOL> found_search = False <EOL> for item in contents : <EOL> domain_match = domain_prog . match ( item ) <EOL> search_match = search_prog . match ( item ) <EOL> if domain_match : <EOL> new_contents . append ( '<STR_LIT>' . format ( domainname ) ) <EOL> found_domain = True <EOL> elif search_match : <EOL> new_contents . append ( '<STR_LIT>' . format ( searchdomain ) ) <EOL> found_search = True <EOL> else : <EOL> new_contents . append ( item ) <EOL> if not found_domain : <EOL> new_contents . insert ( <NUM_LIT:0> , '<STR_LIT>' . format ( domainname ) ) <EOL> if not found_search : <EOL> if new_contents [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) : <EOL> new_contents . insert ( <NUM_LIT:1> , '<STR_LIT>' . format ( searchdomain ) ) <EOL> else : <EOL> new_contents . insert ( <NUM_LIT:0> , '<STR_LIT>' . format ( searchdomain ) ) <EOL> new_resolv = '<STR_LIT>' . join ( new_contents ) <EOL> if not ( '<STR_LIT:test>' in settings and settings [ '<STR_LIT:test>' ] ) : <EOL> _write_file_network ( new_resolv , _DEB_RESOLV_FILE ) <EOL> try : <EOL> template = JINJA . get_template ( '<STR_LIT>' ) <EOL> except jinja2 . exceptions . TemplateNotFound : <EOL> log . error ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' <EOL> network = template . render ( opts ) <EOL> changes . extend ( _read_temp ( network ) ) <EOL> return changes </s>
