
    /I_!)                          S SK Jr  S SK7  S SKJr  S SKJr  S SKJr  S SK	J
s  Jr  S SKrS SKrS SKrS SKr " S S\\5      rg! \ 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  S SKJr   NHf = f)	    )Addon)*)utils)
moduleBase)moduleNotSupportedNc                       \ rS rSrSrSSSS.S/ SQSS	/S
.SSS/S.SSS/S.SS/SS.SSS/S.SSS/S.SSS/S.SSS/S.S.	S.rS rS rS  rS! r	S" r
S# rS-S% jrS& rS' rS( r\\\S).rS* rS-S+ jrS,rg$).openvswitch_port   z6ifupdown2 addon module to configure openvswitch ports z.openvswitch module configure openvswitch portsz(Interfaces to be part of this ovs bridgeT)helprequiredzovs interface type)OVSPort
OVSIntPortOVSBond	OVSTunnelOVSPatchPortzovs-type OVSPort)r   	validvalsr   examplez?This option lets you add extra arguments to a ovs-vsctl commandFz5ovs_options bond_mode=balance-tcp lacp=active tag=100)r   r   r   a  This option lets you run additional ovs-vsctl commands,separated by "--" (double dash). Variables can be part of the "ovs_extra"option. You can provide all the standard environmental variablesdescribed in the interfaces(5) man page. You can also pass shellcommands.extra argszEovs_extra set interface ${IFACE} external-ids:iface-id=$(hostname -s)z&Interfaces to be part of this ovs bondz<interface-list>)r   r   r   z2For "OVSTunnel" interfaces, the type of the tunnelzovs-tunnel-type grezmFor "OVSTunnel" interfaces, this field should be used to specify the tunnel options like remote_ip, key, etc.z>ovs-tunnel-options options:remote_ip=182.168.1.2 options:key=1zovs patch peerzovs-patch-peer patch0zmtu of the ovs interfacezovs-mtu 9000)	
ovs-bridgeovs-typeovs-options	ovs-extra	ovs-bondsovs-tunnel-typeovs-tunnel-optionsovs-patch-peerovs-mtu)mhelpattrsc                     [         R                  " U /UQ70 UD6  [        R                  " U 5        [        R                  R                  S5      (       d  [        S5      eg )N/usr/bin/ovs-vsctlz/module init failed: no /usr/bin/ovs-vsctl found)r   __init__r   ospathexistsr   )selfargskargss      //usr/share/ifupdown2/addons/openvswitch_port.pyr!   openvswitch_port.__init__Y   sK    T2D2E2tww~~233$%VWW 4    c                 f    UR                  S5      nUR                  S5      nU(       a  U(       a  gg)Nr   r   TF)get_attr_value_first)r%   ifaceobjovstype	ovsbridges       r(   _is_ovs_portopenvswitch_port._is_ovs_port_   s-    //<11<@	yr*   c                 f    UR                  S5      nU(       a  [        UR                  5       5      $ g )Nr   )r,   sortedsplit)r%   r-   	ovs_bondss      r(   _get_bond_ifaces!openvswitch_port._get_bond_ifacesf   s*    11;?	9??-..r*   c                    U(       Ga  UR                   (       a  UR                   OS[        R                  S'   UR                   (       a  UR                   OS[        R                  S'   UR                  (       a  UR                  OS[        R                  S'   UR                  (       a  SR                  UR                  5      OS[        R                  S'   SnU H  nUS-   U-   nM      U R                  R                  S	U-  5        [        R                  " U5        g g ! [        R                   a"  n[        S
U< SUR                  < 35      eS nAf[         a  n[        SU-  5      eS nAff = f)N IFACELOGICALMETHOD,ADDRFAMr    z -- z
Running %sz	Command "z	 failed: z%s)namer"   environaddr_methodaddr_familyjoinloggerdebugr   exec_user_command
subprocessCalledProcessError	Exceptionoutput)r%   r-   cmdlistfinalcmdcmdces          r(   
_ovs_vsctlopenvswitch_port._ovs_vsctll   s   3;==(--bBJJw5=]]HMMBJJy!;C;O;O8#7#7UWBJJx FNFZFZCHHX-A-A$B`bBJJy!+H#f,s2 +!!<8#<=''1  00 Sh!QRR +**+s$   ,4D" "E36EE3 E..E3c                 f   UR                   nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      n/ nUS:X  a.  Uc  [        S5      eSU< S	U< S	U< 3n	UR	                  U	5        OS
U< S	U< 3n	UR	                  U	5        SU-  n	UR	                  U	5        SU-  n	UR	                  U	5        U(       a  SU< S	U< 3n	UR	                  U	5        US:X  a  SU-  n	UR	                  U	5        US:X  a]  UR                  S5      n
U
c  [        S5      eUR                  S5      nUc  [        S5      eSU< SU
< S	U< 3n	UR	                  U	5        US:X  a:  UR                  S5      nUc  [        S5      eSU< SU< 3n	UR	                  U	5        UR                  S5      nU R                  U5      nUbI  US:X  a(  Ub%  U H  nSU< SU< 3n	UR	                  U	5        M      OSU< SU< 3n	UR	                  U	5        Ub  UR                  U5        U R                  X5        US:w  aY  US:w  aR  U R                  R                  UR                   5      (       d'  U R                  R                  UR                   S5        g g g g )Nr   r   r   r   r   r   zmissing ovs-bonds optionz"--may-exist --fake-iface add-bond  z--may-exist add-port zx--if-exists clear port %s bond_active_slave bond_mode cvlans external_ids lacp mac other_config qos tag trunks vlan_modezL--if-exists clear interface %s mtu_request external-ids other_config optionsz	set Port r   zset Interface %s type=internalr   r   zmissing ovs-tunnel-type optionr   z!missing ovs-tunnel-options optionzset Interface z type=r   r   zmissing ovs-patch-peerz type=patch options:peer=r   z mtu_request=openvswitch)r?   r,   get_attr_valuerI   appendr6   extendrP   cachelink_existsiproute2link_add_openvswitch)r%   r-   ifacer/   
ovsoptionsr.   ovsbondsovsextracmd_listrM   ovstunneltypeovstunneloptionsovspatchpeerovsmtuovsbonds_listslaves                   r(   _addportopenvswitch_port._addport   s   11<@	22MB
//<00+>**;7i :;; ?H%QYZ3??3	   09%@3??3 I  KP  Q ]^cd%*J7COOC  l"2E:COOC k!$99;LMM$!ABB'<<=QR'!DEE (16GWXCOOC n$#88:JKL#!9:: $AFUCOOC  ..	:--h7)#(A*E=B6JCOOC( +
 :?vF$ OOH%+k!g&?::))(--88228==-P 9 '@!r*   c                 v    UR                   nUR                  S5      nSU< SU< 3nU R                  X/5        g )Nr   z--if-exists del-port rS   )r?   r,   rP   )r%   r-   r\   r/   rM   s        r(   _delportopenvswitch_port._delport   s3    11<@	,5u=%(r*   Nc                     U R                  U5      (       d  g U=R                  [        R                  -  sl        UR	                  S5      nU/$ )Nr   )r0   link_privflagsifaceLinkPrivFlagsOPENVSWITCHr,   )r%   r-   ifaceobjs_allr/   s       r(   get_dependent_ifacenames)openvswitch_port.get_dependent_ifacenames   sF      (++#5#A#AA11<@	{r*   c                 &    U R                  U5        g N)rg   r%   r-   s     r(   _upopenvswitch_port._up   s    x r*   c                     [         R                  R                  (       d+  U R                  R	                  UR
                  5      (       d  g U R                  U5        g rt   )ifupdownflagsflagsPERFMODErX   rY   r?   rj   ru   s     r(   _downopenvswitch_port._down   s8    ""++DJJ4J4JHMM4Z4Zx r*   c                 Z    U R                   R                  UR                  5      (       d  g g rt   )rX   rY   r?   )r%   r-   ifaceobjcurrs      r(   _query_checkopenvswitch_port._query_check   s!    zz%%x}}55r*   )zpre-upz	post-downquery-checkcurrc                 6    U R                   R                  5       $ )z-returns list of ops supported by this module )_run_opskeys)r%   s    r(   get_opsopenvswitch_port.get_ops   s    }}!!$$r*   c                     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 Openvswitch port 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.
Nzquery-runningr   )r   getr0   )r%   r-   	operationquery_ifaceobj
extra_args
op_handlers         r(   runopenvswitch_port.run   sT      ]]&&	2
(1B1BH1M1M))7'r*    rt   )__name__
__module____qualname____firstlineno____doc___modinfor!   r0   r6   rP   rg   rj   rq   rv   r|   r   r   r   r   __static_attributes__r   r*   r(   r	   r	      s   B B C 
 -^ ./	 Z!ST.
 "cd A01! M!12 W!\]	# )!34 3!*+]3
6HpX+,LQ\)!! 'H%(r*   r	   )ifupdown2.lib.addonr   ifupdown2.ifupdown.ifaceifupdown2.ifupdown.utilsr   #ifupdown2.ifupdownaddons.modulebaser   ifupdown2.ifupdown.exceptionsr    ifupdown2.ifupdown.ifupdownflagsifupdownry   rI   	lib.addonifupdown.ifaceifupdown.utilsifupdownaddons.modulebaseifupdown.exceptionsifupdown.ifupdownflagsloggingrerG   r"   r	   r   r*   r(   <module>r      s`   3)*.>@<<  	  	v(uj v(  3 $4623s   &A )A10A1