<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import salt . utils <EOL> import salt . utils . decorators as decorators <EOL> log = logging . getLogger ( __name__ ) <EOL> __func_alias__ = { <EOL> '<STR_LIT>' : '<STR_LIT:list>' <EOL> } <EOL> __virtualname__ = '<STR_LIT>' <EOL> @ decorators . memoize <EOL> def _check_nictagadm ( ) : <EOL> '''<STR_LIT>''' <EOL> return salt . utils . which ( '<STR_LIT>' ) <EOL> def _check_dladm ( ) : <EOL> '''<STR_LIT>''' <EOL> return salt . utils . which ( '<STR_LIT>' ) <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if salt . utils . is_smartos_globalzone ( ) and _check_nictagadm ( ) and _check_dladm ( ) : <EOL> return __virtualname__ <EOL> return ( <EOL> False , <EOL> '<STR_LIT>' . format ( <EOL> __virtualname__ <EOL> ) <EOL> ) <EOL> def list_nictags ( include_etherstubs = True ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> nictagadm = _check_nictagadm ( ) <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> estubs = '<STR_LIT>' if not include_etherstubs else '<STR_LIT>' <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> retcode = res [ '<STR_LIT>' ] <EOL> if retcode != <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = res [ '<STR_LIT>' ] if '<STR_LIT>' in res else '<STR_LIT>' <EOL> else : <EOL> header = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:type>' ] <EOL> for nictag in res [ '<STR_LIT>' ] . splitlines ( ) : <EOL> nictag = nictag . split ( '<STR_LIT:|>' ) <EOL> nictag_data = { } <EOL> for field in header : <EOL> nictag_data [ field ] = nictag [ header . index ( field ) ] <EOL> ret [ nictag_data [ '<STR_LIT:name>' ] ] = nictag_data <EOL> del ret [ nictag_data [ '<STR_LIT:name>' ] ] [ '<STR_LIT:name>' ] <EOL> return ret <EOL> def vms ( nictag ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> nictagadm = _check_nictagadm ( ) <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> nictag = nictag <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> retcode = res [ '<STR_LIT>' ] <EOL> if retcode != <NUM_LIT:0> : <EOL> ret [ '<STR_LIT>' ] = res [ '<STR_LIT>' ] if '<STR_LIT>' in res else '<STR_LIT>' <EOL> else : <EOL> ret = res [ '<STR_LIT>' ] . splitlines ( ) <EOL> return ret <EOL> def exists ( * nictag , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> nictagadm = _check_nictagadm ( ) <EOL> if len ( nictag ) == <NUM_LIT:0> : <EOL> return { '<STR_LIT>' : '<STR_LIT>' } <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> nictags = '<STR_LIT:U+0020>' . join ( nictag ) <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if not kwargs . get ( '<STR_LIT>' , False ) : <EOL> ret = res [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> else : <EOL> missing = res [ '<STR_LIT>' ] . splitlines ( ) <EOL> for nt in nictag : <EOL> ret [ nt ] = nt not in missing <EOL> return ret <EOL> def add ( name , mac , mtu = <NUM_LIT> ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> nictagadm = _check_nictagadm ( ) <EOL> dladm = _check_dladm ( ) <EOL> if mtu > <NUM_LIT> or mtu < <NUM_LIT> : <EOL> return { '<STR_LIT>' : '<STR_LIT>' } <EOL> if mac != '<STR_LIT>' : <EOL> cmd = '<STR_LIT>' . format ( <EOL> dladm = dladm <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if mac not in res [ '<STR_LIT>' ] . splitlines ( ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' . format ( mac ) } <EOL> if mac == '<STR_LIT>' : <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> mtu = mtu , <EOL> name = name <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> else : <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> mtu = mtu , <EOL> mac = mac , <EOL> name = name <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if res [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> return { '<STR_LIT>' : '<STR_LIT>' if '<STR_LIT>' not in res and res [ '<STR_LIT>' ] == '<STR_LIT>' else res [ '<STR_LIT>' ] } <EOL> def update ( name , mac = None , mtu = None ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> nictagadm = _check_nictagadm ( ) <EOL> dladm = _check_dladm ( ) <EOL> if name not in list_nictags ( ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' . format ( name ) } <EOL> if not mtu and not mac : <EOL> return { '<STR_LIT>' : '<STR_LIT>' } <EOL> if mtu : <EOL> if mtu > <NUM_LIT> or mtu < <NUM_LIT> : <EOL> return { '<STR_LIT>' : '<STR_LIT>' } <EOL> if mac : <EOL> if mac == '<STR_LIT>' : <EOL> return { '<STR_LIT>' : '<STR_LIT>' } <EOL> else : <EOL> cmd = '<STR_LIT>' . format ( <EOL> dladm = dladm <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if mac not in res [ '<STR_LIT>' ] . splitlines ( ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' . format ( mac ) } <EOL> if mac and mtu : <EOL> properties = "<STR_LIT>" . format ( mtu , mac ) <EOL> elif mac : <EOL> properties = "<STR_LIT>" . format ( mac ) if mac else "<STR_LIT>" <EOL> elif mtu : <EOL> properties = "<STR_LIT>" . format ( mtu ) if mtu else "<STR_LIT>" <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> properties = properties , <EOL> name = name <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if res [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> return { '<STR_LIT>' : '<STR_LIT>' if '<STR_LIT>' not in res and res [ '<STR_LIT>' ] == '<STR_LIT>' else res [ '<STR_LIT>' ] } <EOL> def delete ( name , force = False ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> nictagadm = _check_nictagadm ( ) <EOL> if name not in list_nictags ( ) : <EOL> return True <EOL> cmd = '<STR_LIT>' . format ( <EOL> nictagadm = nictagadm , <EOL> force = "<STR_LIT>" if force else "<STR_LIT>" , <EOL> name = name <EOL> ) <EOL> res = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if res [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> return True <EOL> else : <EOL> return { '<STR_LIT>' : '<STR_LIT>' if '<STR_LIT>' not in res and res [ '<STR_LIT>' ] == '<STR_LIT>' else res [ '<STR_LIT>' ] } </s>
