<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import salt . utils <EOL> from salt . exceptions import SaltInvocationError <EOL> log = logging . getLogger ( __name__ ) <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if salt . utils . which ( '<STR_LIT>' ) : <EOL> return True <EOL> return ( False , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def scan ( iface , style = None ) : <EOL> '''<STR_LIT>''' <EOL> if not _valid_iface ( iface ) : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( iface ) ) <EOL> if '<STR_LIT>' in out : <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( iface ) ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( iface ) ) <EOL> ret = { } <EOL> tmp = { } <EOL> for line in out . splitlines ( ) : <EOL> if not line . strip ( ) : <EOL> continue <EOL> if '<STR_LIT>' in line : <EOL> continue <EOL> if line . strip ( ) . startswith ( '<STR_LIT>' ) : <EOL> comps = line . split ( '<STR_LIT>' ) <EOL> line = comps [ <NUM_LIT:1> ] <EOL> if tmp : <EOL> ret [ tmp [ '<STR_LIT>' ] ] = tmp <EOL> tmp = { } <EOL> comps = line . split ( '<STR_LIT::>' ) <EOL> if comps [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' : <EOL> comps [ <NUM_LIT:1> ] = comps [ <NUM_LIT:1> ] . lstrip ( '<STR_LIT:">' ) . rstrip ( '<STR_LIT:">' ) <EOL> if comps [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' : <EOL> if '<STR_LIT>' not in tmp : <EOL> tmp [ '<STR_LIT>' ] = [ ] <EOL> tmp [ '<STR_LIT>' ] . append ( '<STR_LIT::>' . join ( comps [ <NUM_LIT:1> : ] ) . strip ( ) ) <EOL> else : <EOL> tmp [ comps [ <NUM_LIT:0> ] . strip ( ) ] = '<STR_LIT::>' . join ( comps [ <NUM_LIT:1> : ] ) . strip ( ) <EOL> ret [ tmp [ '<STR_LIT>' ] ] = tmp <EOL> if style == '<STR_LIT:list>' : <EOL> return ret . keys ( ) <EOL> return ret <EOL> def set_mode ( iface , mode ) : <EOL> '''<STR_LIT>''' <EOL> if not _valid_iface ( iface ) : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> valid_modes = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if mode not in valid_modes : <EOL> raise SaltInvocationError ( <EOL> '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( valid_modes ) ) <EOL> ) <EOL> __salt__ [ '<STR_LIT>' ] ( iface ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( iface , mode ) ) <EOL> __salt__ [ '<STR_LIT>' ] ( iface ) <EOL> return mode <EOL> def _valid_iface ( iface ) : <EOL> '''<STR_LIT>''' <EOL> ifaces = list_interfaces ( ) <EOL> if iface in ifaces . keys ( ) : <EOL> return True <EOL> return False <EOL> def list_interfaces ( style = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> tmp = None <EOL> iface = None <EOL> out = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> for line in out . splitlines ( ) : <EOL> if not line : <EOL> continue <EOL> if '<STR_LIT>' in line : <EOL> continue <EOL> comps = line . strip ( ) . split ( '<STR_LIT:U+0020>' ) <EOL> if not line . startswith ( '<STR_LIT:U+0020>' ) : <EOL> if tmp is not None : <EOL> ret [ iface ] = tmp . copy ( ) <EOL> iface = comps . pop ( <NUM_LIT:0> ) <EOL> tmp = { '<STR_LIT>' : [ ] } <EOL> for item in comps : <EOL> if '<STR_LIT::>' in item : <EOL> parts = item . split ( '<STR_LIT::>' ) <EOL> key = parts [ <NUM_LIT:0> ] . strip ( ) <EOL> value = parts [ <NUM_LIT:1> ] . strip ( ) <EOL> if key == '<STR_LIT>' : <EOL> value = value . lstrip ( '<STR_LIT:">' ) . rstrip ( '<STR_LIT:">' ) <EOL> tmp [ key ] = value <EOL> elif '<STR_LIT:=>' in item : <EOL> parts = item . split ( '<STR_LIT:=>' ) <EOL> tmp [ parts [ <NUM_LIT:0> ] . strip ( ) ] = parts [ <NUM_LIT:1> ] . strip ( ) <EOL> else : <EOL> tmp [ '<STR_LIT>' ] . append ( item ) <EOL> ret [ iface ] = tmp . copy ( ) <EOL> if style == '<STR_LIT:list>' : <EOL> return ret . keys ( ) <EOL> return ret </s>
