
    /I_z,                          S SK Jr  S SK7  S SKJr  S SKJr  S SKJs  J	r	   " S S\\5      rg! \
\4 a     S SKJr  S SK7  S SKJr  S SKJr  S SKJ	r	   N4f = f)    )Addon)*)Link)
moduleBaseNc                       \ rS rSrSrSSS/S.SSS	/S
.SSSS/S/S.S.S.rS r\S 5       r\S 5       r	\S 5       r
S rS#S jrS$S jrS rS rS rS rS r\\\\S.rS  rS#S! jrS"rg)%vlan   z*ifupdown2 addon module to configure vlans zvlan module configures vlan interfaces. This module understands vlan interfaces with dot notations. eg swp1.100. Vlan interfaces with any other names need to have raw device and vlan id attributeszvlan raw devicez<interface>)help	validvalszvlan id04096)r
   
validrangezvlan protocolz802.1qz802.1adzvlan-protocol 802.1q)r
   defaultr   example)vlan-raw-devicevlan-idvlan-protocol)mhelpattrsc                 d    [         R                  " U 5        [        R                  " U /UQ70 UD6  g N)r   __init__r   )selfargskargss      #/usr/share/ifupdown2/addons/vlan.pyr   vlan.__init__/   s&    tD14151    c                 X    U R                  S5      nU(       a  gSU R                  ;   a  gg)Nr   T.F)get_attr_value_firstname)ifaceobjvlan_raw_devices     r   _is_vlan_devicevlan._is_vlan_device3   s+    "778IJHMM!r   c                     SU ;   $ )Nr     )	ifacenames    r   _is_vlan_by_namevlan._is_vlan_by_name<   s    ir   c                     U R                  SS5      n[        U5      S:X  a  US   $ [        U5      S:X  a  US   S-   US   -   $ g)zReturns vlan raw device from ifname
Example:
    Returns eth0 for ifname eth0.100
    Returns eth0.100 for ifname eth0.100.200
    Returns None if vlan raw device name cannot
    be determined
r       r         N)splitlen)r)   vlists     r   #_get_vlan_raw_device_from_ifacename(vlan._get_vlan_raw_device_from_ifacename@   sM     Q'u:?8OZ1_8c>E!H,,r   c                 l    UR                  S5      nU(       a  U$ U R                  UR                  5      $ )Nr   )r!   r3   r"   )r   r#   r$   s      r   _get_vlan_raw_devicevlan._get_vlan_raw_deviceP   s1    "778IJ""77FFr   Nc                     U R                  U5      (       d  g U=R                  [        R                  -  sl        U R	                  U5      /$ r   )r%   	link_kindifaceLinkKindVLANr6   )r   r#   ifaceobjs_alls      r   get_dependent_ifacenamesvlan.get_dependent_ifacenamesV   sA    ##H--m000))(344r   c                     U R                   R                  U5      (       a?  U(       a  U R                  R                  X5        gU R                  R	                  X5        gg)zMIf the lower device is a vlan aware bridge, add/del the vlanid
to the bridge N)cachebridge_is_vlan_awarenetlinklink_add_bridge_vlanlink_del_bridge_vlan)r   
bridgenamevlanidadds       r   _bridge_vid_add_delvlan._bridge_vid_add_del\   sE     ::**:6611*E11*E	 7r   c                     U R                   R                  U5      (       d  gU R                   R                  U5      u  pEU(       a  X5;  a  [        R                  Ul        SUl        gg)z\If the lower device is a vlan aware bridge, check if the vlanid
is configured on the bridge Nzbridge vid error)r@   rA   get_pvid_and_vidsifaceStatusERRORstatus
status_str)r   ifaceobjcurrrE   rF   _vidss         r   _bridge_vid_checkvlan._bridge_vid_checke   sU     zz..z::**..z:v)"-"3"3L&8L# *r   c           
         U R                  U5      nUS:X  a  [        S5      eU R                  U5      nU(       d  [        S5      eUR                  n[        R
                  R                  (       a  0 nOU R                  R                  U5      nUR                  S5      nUR                  [        R                  5      nU(       d  U R                  S5      nU(       aM  UR                  5       UR                  5       :w  a+  [        UR                  < SU< SUR                  < S35      e[        R
                  R                  (       Gd  U R                  R                  UR                  5      nU(       an  UR                  S5      n	U R                  R!                  U5      n
U
(       a;  U	(       a4  X:w  a/  [        UR                  < S	U
< S
U	< SUR                  < S35      eU R                  R                  U5      (       d.  [        R
                  R"                  (       a  g [        SU-  5      eU(       a  U R%                  X25        g U R&                  R)                  X1R                  X&5        U R%                  X25        g )Ncould not determine vlanid#could not determine vlan raw devicer   z!: cannot change vlan-protocol to zA: operation not supported. Please delete the device with 'ifdown z&' and recreate it to apply the change.r   z%: cannot change vlan-raw-device from z to zrawdevice %s not present)_get_vlan_id	Exceptionr6   r"   ifupdownflagsflagsPERFMODEr@   get_link_info_datar!   getr   IFLA_VLAN_PROTOCOLget_attr_default_valuelowerlink_existsget_lower_device_ifnameDRYRUNrH   rB   link_add_vlan)r   r#   rF   vlanrawdeviceifnamecached_vlan_ifla_info_datavlan_protocolcached_vlan_protocolvlan_existsuser_vlan_raw_devicecached_vlan_raw_devices              r   _upvlan._upo   s   ""8,R<89911(;ABB'')+&)-)F)Fv)N& 55oF9==d>U>UV 77HMM$7$7$9=Q=W=W=Y$Y  (}}mX]]L M M
 ""+++**00?K'/'D'DEV'W$)-)K)KF)S&).BG]Gu#'/}}6LNbdldqdq%s t t ::))-88 &&--#$>$NOO((?""=--W  7r   c                    U R                  U5      nUS:X  a  [        S5      eU R                  U5      nU(       d  [        S5      e[        R                  R
                  (       d+  U R                  R                  UR                  5      (       d  g  U R                  R                  UR                  5        U R                  X2SS9  g ! [         a$  nU R                  [        U5      5         S nAg S nAff = f)NrV   rW   rX   F)rG   )rY   rZ   r6   r[   r\   r]   r@   rc   r"   rB   link_delrH   log_warnstr)r   r#   rF   rg   es        r   _down
vlan._down   s    ""8,R<89911(;ABB""++DJJ4J4J8==4Y4Y	"LL!!(--0$$]$F 	"MM#a&!!	"s   5C 
C5C00C5c                 P   U R                   R                  UR                  5      (       d  g SUR                  ;  Gaj  UR                  nU R                   R                  U5      nUR	                  SUXAR                  S5      :g  5        U R                   R                  U5      nUR                  S5      nU(       d  [        U R                  U5      5      nUR                  [        R                  5      n[        U5      nUR	                  SXU:g  5        UR                  S5      n	U	(       ah  UR                  [        R                  5      n
U	R                  5       U
R                  5       :w  a  UR	                  SU
S5        OUR	                  SU	S5        U R                  X$U5        g g )Nr    r   r   r   r/   r   )r@   rc   r"   rd   update_config_with_statusr!   r^   rt   rY   r_   r   IFLA_VLAN_IDr`   upperrS   )r   r#   rP   rh   rn   cached_vlan_info_datavlanid_configcached_vlan_idcached_vlan_id_strprotocol_configrk   s              r   _query_checkvlan._query_check   sz   zz%%hmm44hmm# ]]F%)ZZ%G%G%O"
 22!&&*G*GHY*ZZ %)JJ$A$A&$I!
 %99)DM  #D$5$5h$? @266t7H7HIN!$^!4229>PcuRuv
 ';;OLO'<'@'@AXAX'Y$"((*.B.H.H.JJ ::', !::'' ""<Xc $r   c           	         UR                   nU R                  R                  U5      (       d  g U R                  R                  U5      S:X  d  g SU;   a  g U R                  R	                  U5      nS[
        R                  4S[
        R                  44 H/  u  pEUR                  U[        UR                  U5      5      5        M1     UR                  SU R                  R                  U5      5        g )Nr   r    r   r   r   )r"   r@   rc   get_link_kindr^   r   rz   r`   update_configrt   r_   rd   )r   ifaceobjrunningrh   r|   	attr_namenl_attrs         r   _query_runningvlan._query_running   s     %%zz%%f--zz''/69 &= $

 = =f E D--. $"9"9:#
I )))S9N9R9RSZ9[5\]	#
 	%%&79[9[\b9cdr   )zpre-upz	post-downquery-checkcurrquery-runningc                 H    [        U R                  R                  5       5      $ )z-returns list of ops supported by this module )list_run_opskeys)r   s    r   get_opsvlan.get_ops  s    DMM&&())r   c                     UR                   [        R                  :X  a  gU R                  R	                  U5      nU(       d  gUS:w  a  U R                  U5      (       d  gUS:X  a
  U" XU5        gU" X5        g)a  run vlan configuration on the interface object passed as argument

Args:
    **ifaceobj** (object): iface object

    **operation** (str): any of 'pre-up', 'post-down', 'query-checkcurr',
                         'query-running'
Kwargs:
    **query_ifaceobj** (object): query check ifaceobject. This is only
        valid when op is 'query-checkcurr'. It is an object same as
        ifaceobj, but contains running attribute values and its config
        status. The modules can use it to return queried running state
        of interfaces. status is success if the running state is same
        as user required state in ifaceobj. error otherwise.
Nr   r   )type	ifaceTypeBRIDGE_VLANr   r_   r%   )r   r#   	operationquery_ifaceobj
extra_args
op_handlers         r   runvlan.run  sj      ==I111]]&&y1
(((22))t~6t&r   r(   r   )T)__name__
__module____qualname____firstlineno____doc___modinfor   staticmethodr%   r*   r3   r6   r=   rH   rS   ro   rv   r   r   r   r   r   __static_attributes__r(   r   r   r   r      s    6N *+_ 
 ""Fm
 (#&	223	
H.2        G5F928h"4Yle2 ''	H*'r   r   )ifupdown2.lib.addonr   ifupdown2.ifupdown.ifaceifupdown2.nlmanager.nlmanagerr   #ifupdown2.ifupdownaddons.modulebaser    ifupdown2.ifupdown.ifupdownflagsifupdownr[   ImportErrorModuleNotFoundError	lib.addonifupdown.ifacenlmanager.nlmanagerifupdownaddons.modulebaseifupdown.ifupdownflagsr   r(   r   r   <module>r      sR   3)*2><<Q'5* Q' 	() 3 (423s    / %AA