
    gˉ                         S SK Jr  S SKrS SKrS SKJrJr  S SKJr  S SK	J
r
  S SKJrJrJr  S SKJrJr   " S S	\R$                  5      r " S
 S5      rg)    )defaultdictN)AF_INETAF_INET6)AbstractSet)NetplanRoute)SystemConfigStateNetplanConfigStateDEVICE_TYPES)is_valid_macaddressroute_table_lookupc                       \ rS rSrS rSrg)DiffJSONEncoder   c                     [        U[        5      (       a  UR                  5       $ [        R                  R                  X5      $ N)
isinstancer   to_dictjsonJSONEncoderdefault)selfobjs     0/usr/share/netplan/netplan_cli/cli/state_diff.pyr   DiffJSONEncoder.default   s4    c<((;;=  ''22     N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    3r   r   c                      \ rS rSrSrS\S\4S jrS\4S jr	S-S\
S\4S	 jjrS\4S
 jrS\
S\
S\S\4S jrS\S\SS4S jrS\S\4S jrS\S\4S jrS\
S\
4S jrS\S\SS4S jrS\S\SS4S jrS\S\SS4S jrS\S\SS4S jrS\S\
SS4S jrS\S\SS4S jrS\S\4S  jrS\S\\   4S! jrS"\\   S#\\
   S\S\4S$ jrS\4S% jr S\SS4S& jr!S\4S' jr"S(\S\4S) jr#S*\
S\4S+ jr$S,r%g).NetplanDiffState&   z
DiffState is mainly responsible for getting both system's and Netplan's configuration
state, compare them and provide a data-structure containing the differences it found.
system_statenetplan_statec                 *    Xl         X l        0 U l        g r   )r%   r&   route_lookup_table_names)r   r%   r&   s      r   __init__NetplanDiffState.__init__,   s    (*(*%r   returnc                     S0 0nU R                  5       nU R                  5       n[        [        UR	                  5       5      [        UR	                  5       5      -   5      nU H  n0 US   U'   M     UR                  5        H  u  pVUS   U   R                  U5        M     UR                  5        H  u  pVUS   U   R                  U5        M     U R                  R                   H"  nUR                  US   UR                     S'   M$     U$ )zs
Return the states of both the system and Netplan in a common representation
that makes it easier to compare them.

interfacesdata_sources)_get_system_interfaces_get_netplan_interfacessetlistkeysitemsupdater%   interface_listr.   name)r   
full_statesystem_interfacesnetplan_interfacesall_interfaces	interfaceconfigs          r   get_full_stateNetplanDiffState.get_full_state2   s    "

 !779!99; T"3"8"8":;dCUCZCZC\>]]^'I24J|$Y/ ( "3!8!8!:I|$Y/66v> "; "4!9!9!;I|$Y/66v> "< **99IGPG]G]J|$Y^^4^D : r   r<   c                    U R                  5       nU R                  UR                  S0 5      5      nU(       a  UR                  U5      =n(       a  X0nO0 nU R                  5       nU R	                  XQ5        UR                  5        H  u  pUR                  S0 5      R                  S5      nUR                  S0 5      R                  S5      nU R                  XaU5      nU R                  XH5        U R                  XH5        U R                  XH5        U R                  XH5        U R                  XH5        U R                  XH5        US   R                  U5        M     [        [        US   R                  5       S S95      US'   U$ )aV  
Compare the configuration of interfaces currently found in the system against Netplan configuration.
A number of heuristics are used to eliminate configuration that is automatically set in the system,
such as certain routes and IP addresses. That is necessary because this configuration will not be found
in Netplan. For example, if Netplan is enabling DHCP on an interface and not defining any extra IP addresses,
we don't count the IPs automatically assigned to the interface as a difference. We do though count the eventual
absence of addresses that should be assigned by DHCP as a difference.
r-   r%   idindexc                 *    U S   R                  S5      $ )N   rB   )get)ifaces    r   <lambda>+NetplanDiffState.get_diff.<locals>.<lambda>u   s    [`ab[c[g[gho[pr   key)r>   _get_comparable_interfacesrE   _create_new_report_analyze_missing_interfacesr4   _create_new_iface_analyze_ip_addresses_analyze_nameservers_analyze_search_domains_analyze_mac_addresses_analyze_routes_analyze_parent_linksr5   dictsorted)	r   r<   r8   r-   r=   report	netdef_idrB   rF   s	            r   get_diffNetplanDiffState.get_diffO   s_    ((*
44Z^^LRT5UV
#	22v2'0

((*((;!+!1!1!3I

>26::4@IJJ~r266w?E**9GE&&v5%%f4((7''6  /&&v5< ''. "4  $F6,+?+E+E+GMp$qr|r   c                     0 0 0 S.$ )N)r-   missing_interfaces_systemmissing_interfaces_netplanr   )r   s    r   rL   #NetplanDiffState._create_new_reportx   s    )+*,
 	
r   rX   rB   c                     UUUU0 0 S.0$ )N)rB   r7   rA   r%   r&   r   )r   rX   r<   rB   s       r   rN   "NetplanDiffState._create_new_iface   s#    ! "!#
 	
r   r=   rF   Nc                    [        UR                  5       5      S   nUR                  S0 5      R                  S/ 5       Vs1 s H  oDiM     nnU R                  U5      nUR                  S0 5      R                  SS5      nUR                  S0 5      R                  SS5      nUR                  S0 5      R                  S/ 5      n[	        5       n	UR                  S0 5      R                  S0 5      R                  5        GH  u  p[        R                  " U
5      nUR                  S	/ 5      n1 S
kR                  U5      (       d  U	R                  U
5        SU;   a  UR                  (       a  [        UR                  [        R                  5      (       a  SU;  a  U	R                  U
5        [        UR                  [        R                  5      (       a  SU;  a  U	R                  U
5        [        UR                  [        R                  5      (       a  SS1R                  U5      (       a  Sn[        UR                  [        R                  5      (       a  SU;   a  SnUR                  S0 5      R                  S5      nSU;   d  GM  USL d  GM  U	R                  U
5        GM     UR                  U	5      nU	R                  U5      nU(       a
  SX#   S   S'   U(       a
  SX#   S   S'   U(       a*  X#   S   R!                  S[        [#        U5      5      05        U(       a+  X#   S   R!                  S[        [#        U5      5      05        g g s  snf )Nr   r&   	addressesdhcp4Fdhcp6
link_localr%   flags>   radhcplinkdynamicri   ipv4ipv6rh   rj   	accept_rarg   Tmissing_dhcp4_addressmissing_dhcp6_addressmissing_addresses)r2   r3   rE   _normalize_ip_addressesr1   r4   	ipaddressip_interfaceintersectionaddis_link_localr   ipIPv4AddressIPv6Address
differencer5   rV   )r   r=   rF   r7   rw   netplan_ipsrn   ro   re   
system_ipsaddr	addr_datarf   rm   present_only_in_netplanpresent_only_in_systems                   r   rO   &NetplanDiffState._analyze_ip_addresses   s   EJJL!!$$*JJ$C$G$GUW$XY$Xbr$XY22;? &

?B ? C CGU S &

?B ? C CGU SZZ488rJ
U
%zz."=AA+rRXXZOD''-BMM'2.E 5AA%HHt$
 2#3#3beeY%:%:;;j@XNN4(beeY%:%:;;j@XNN4( "%%!6!677I&33E::,1)"%%!6!677U?,1) 

?B7;;KHIu}e!3t$E  [H #."8"8"D!+!6!6{!C CGEK'(?@ CGEK'(?@!K(//#T&1G*H%I1  #K'..#T&1H*I%J0  #s Zs   Mr-   c                     0 nUR                  5        HW  u  p4UR                  S5      b  UR                  S5      c  M+  UR                  S0 5      R                  S5      (       d  MS  XBU'   MY     U$ )a  In order to compare interfaces, they must exist in the system AND in Netplan.
Here we filter out interfaces that don't have a system_state, a netplan_state
or a netdef ID.

There is a special case where the interface will have a system_state and a netdef_id
but will be missing in Netplan. That will happen when the user removes the interface
only from Netplan but doesn't run netplan apply.
r%   r&   rA   )r4   rE   )r   r-   filteredr<   r=   s        r   rK   +NetplanDiffState._get_comparable_interfaces   sm     !+!1!1!3Izz.)1VZZ5P5X::nb155d;;"(Y "4 r   rb   c                 p    [        5       nU H%  nU R                  U5      nUR                  U5        M'     U$ )z\Apply some transformations to IP addresses so their representation
will match the system's.
)r1   _compress_ipv6_addressru   )r   rb   new_ips_setrw   s       r   rq   (NetplanDiffState._normalize_ip_addresses   s9     eB,,R0BOOB  r   addressc                      [         R                  " U5      nSU;   a  UR                  $ [        UR                  5      $ ! [
         a    Us $ f = f)z
Compress IPv6 addresses to match the system representation
Example: 1:2:0:0::123/64 -> 1:2::123/64
         1:2:0:0::123 -> 1:2::123
If "address" is not an IPv6Address, return the original value
/)rr   rs   with_prefixlenstrrw   
ValueError)r   r   r}   s      r   r   'NetplanDiffState._compress_ipv6_address   sL    	))'2Dg~***tww< 	N	s   '? ? AAc                 4   [        UR                  5       5      S   nUR                  S0 5      R                  S0 5      n[        UR                  S0 5      R                  S/ 5      5      n[        UR                  S0 5      R                  S/ 5      5      nU Vs1 s H  otU   S:X  d  M  UiM     nnU Vs1 s H  otU   S:X  d  M  UiM     n	nU Vs1 s H  otU   S	:X  d  M  UiM     n
nUR                  S0 5      R                  S
5      SLnSUR                  S0 5      R                  S/ 5      ;   nU(       d  U	(       d  U
(       aa  UR                  S0 5      R                  S5      (       a  Xh-
  nU(       a  Xi-
  nU Vs1 s H  owU
;   d  M
  UiM     nnU(       a  U(       a  Xm-
  nOU(       d  UR                  S0 5      R                  S5      (       aG  U Vs1 s H:  n[	        [
        R                  " U5      [
        R                  5      (       a  M8  UiM<     nnUR                  S0 5      R                  S5      (       aG  U Vs1 s H:  n[	        [
        R                  " U5      [
        R                  5      (       a  M8  UiM<     nnUR                  U5      nUR                  U5      nU(       a!  X#   S   R                  S[        U5      05        U(       a"  X#   S   R                  S[        U5      05        g g s  snf s  snf s  snf s  snf s  snf s  snf )Nr   r.   dnsr&   nameservers_addressesr%   DHCPv4DHCPv6NDiscrm   Frl   re   rc   rd   missing_nameservers_addresses)r2   r3   rE   r1   r   rr   
ip_addressrx   ry   rz   r5   )r   r=   rF   r7   r.   netplan_nameserverssystem_nameserversnsdhcp4_nsdhcp6_nsndisc_nsaccept_ra_enabledlink_local_enabledlink_local_nsr   r   s                   r   rP   %NetplanDiffState._analyze_nameservers   s   EJJL!!$zz."599%D
 "&**_b"A"E"EF]_a"bc NB!?!C!CD[]_!`a!-N2b1AX1MBN!-N2b1AX1MBN!-M2b1AW1LBM #JJ;??LTYY#vzz/2'F'J'J<Y['\\x8zz/2.227;;%7%B" !%7%B"*<O*<BhR*<MO!&7%7%G" '::or266w??7I *n7I1;I<P<PQS<TV_VkVk1l +-7I& *n::or266w??7I *n7I1;I<P<PQS<TV_VkVk1l +-7I& *n #6"@"@AS"T!3!>!>?R!S!K(///6L1M1  #K'../6M1N0  #] ONM P*n*nsH   K<)K<5LLL!L?	LL7LL7L Lc                    [        UR                  5       5      S   n[        UR                  S0 5      R                  S/ 5      5      n[        UR                  S0 5      R                  S/ 5      5      nUR                  S0 5      R                  S0 5      nU Vs1 s H  ovU   S:X  d  M  UiM     nnU Vs1 s H  ovU   S:X  d  M  UiM     n	nU(       d  U	(       aY  UR                  S0 5      R                  S	5      (       a  XX-
  nUR                  S0 5      R                  S
5      SLn
U
(       a  XY-
  nO]U(       dV  UR                  S0 5      R                  S	5      (       d&  UR                  S0 5      R                  S5      (       a
  [        5       nUR	                  U5      nUR	                  U5      nU(       a!  X#   S   R                  S[        U5      05        U(       a"  X#   S   R                  S[        U5      05        g g s  snf s  snf )Nr   r&   nameservers_searchr%   r.   searchr   r   rc   rm   Frd   missing_nameservers_search)r2   r3   r1   rE   rz   r5   )r   r=   rF   r7   netplan_search_domainssystem_search_domainsr.   sdhcp4_searchdhcp6_searchr   r   r   s                r   rQ   (NetplanDiffState._analyze_search_domains7  s   EJJL!!$!$VZZ%D%H%HI]_a%b!c #FJJ~r$B$F$FG[]_$` azz."599(BG#/O<a?h3N<O#/O<a?h3N<O<zz/2.227;;(=(L% !'

?B ? C CK PX] ] (=(L% *::or266w??6::o_aCbCfCfgnCoCo,/E)"8"C"CDY"Z!6!A!ABX!Y!K(//,d3I.J1  #K'..,d3J.K0  #; POs   H)H5H
H
c                 |   [        UR                  5       5      S   nUR                  S0 5      R                  S5      nUR                  S0 5      R                  S5      nU(       a  [        U5      (       d  g U(       a?  U(       a7  XE:w  a1  X#   S   R	                  SU05        X#   S   R	                  SU05        g g g g )Nr   r%   
macaddressr&   missing_macaddress)r2   r3   rE   r   r5   )r   r=   rF   r7   system_macaddressnetplan_macaddresss         r   rR   'NetplanDiffState._analyze_mac_addresses^  s    EJJL!!$"JJ~r:>>|L#ZZ<@@N &9:L&M&M!3 6N+22(*<4  O,33(*;5 	 7 "4r   c                 F   [        UR                  5       5      S   n[        UR                  S0 5      R                  S/ 5      5      n[        UR                  S0 5      R                  S/ 5      5      nU R	                  U5      nU R                  UR                  S0 5      5      =n(       a  UR                  U5        UR                  S0 5      R                  S0 5       Vs/ s H  owPM     nnU R                  XXU5      nUR                  U5      n	UR                  U5      n
U
(       a1  X#   S   R                  S[        U
S S9 Vs/ s H  oPM     sn05        U	(       a2  X#   S   R                  S[        U	S	 S9 Vs/ s H  oPM     sn05        g g s  snf s  snf s  snf )
Nr   r&   routesr%   rb   missing_routesc                     U R                   $ r   tors    r   rG   2NetplanDiffState._analyze_routes.<locals>.<lambda>  s    cdcgcgr   rI   c                     U R                   $ r   r   r   s    r   rG   r     s    dedhdhr   )
r2   r3   r1   rE   _normalize_routes_normalize_gatewaysr5   _filter_system_routesrz   rV   )r   r=   rF   r7   netplan_routessystem_routesnetplan_gatewaysrw   system_addressesr   r   routes               r   rS    NetplanDiffState._analyze_routesq  s   EJJL!!$VZZ<@@2NOFJJ~r:>>xLM//?  $77

?TV8WXXX!!"23 *0NB)G)K)KKY[)\])\2B)\]22=TZ["0";";M"J!.!9!9.!I!K(// f=SYg6h"i6hU56h"i1  #K'.. f=TZh6i"j6iU56i"j0  # ^ #j
 #ks   !FF
?F
rW   c                   ^ ^ T R                   R                   Vs1 s H  o3iM     nnT R                  R                   Vs1 s H!  o3R                  (       d  M  UR                  iM#     nnUR                  U5      n[        [        U 4S jU5      5      n/ nT R                  R                   H0  nUR                  U;  d  M  UR                  UR                  5        M2     [        U5      n[        U5      nT(       a   [        U4S jU5      n[        U4S jU5      nT R                  R                  5       nU HQ  nT R                   R                  R                  U5      R                  n	S[        R                  " U	S5      0US   U'   MS     U HK  nUR                  U5      R                  SS5      UR                  U5      R                  S5      S.US	   U'   MM     g s  snf s  snf )
Nc                 h   > TR                   R                  R                  U 5      R                  S:g  $ )Nwifis)r&   netdefsrE   type)ir   s    r   rG   >NetplanDiffState._analyze_missing_interfaces.<locals>.<lambda>  s(    T-?-?-G-G-K-KA-N-S-SW^-^r   c                    > U T:H  $ r   r   r   r<   s    r   rG   r     s	    ANr   c                    > U T:H  $ r   r   r   s    r   rG   r     s	    1	>r   r   otherr\   rB   )r   rB   r]   )r&   r   r%   r6   rX   rz   r2   filterappendr7   rV   get_datarE   r   r
   )
r   rW   r<   rF   r:   system_interfaces_netdef_idsnetplan_onlysystem_onlyr%   
iface_types
   ` `       r   rM   ,NetplanDiffState._analyze_missing_interfaces  s   151C1C1K1KL1Ke1KLEIEVEVEeEe'yEeEixixEe$'y)445QR F#^`lmn&&55E&88""5::. 6 l+[)!":LIL !9;GK((113!E++3377>CCJ((W=:F./6 " !E$((/33FGD%))%044W=;F/07 !9 M'ys   G  G%G%c                    [        UR                  5       5      S   nUR                  S0 5      R                  S5      UR                  S0 5      R                  S5      /nUR                  S0 5      R                  S5      UR                  S0 5      R                  S5      /nUR                  S0 5      R                  S5      UR                  S0 5      R                  S5      /nUR                  S0 5      R                  S/ 5      UR                  S0 5      R                  S/ 5      /nUSS/:w  a:  US   US	   :w  a.  US   (       a  US   X#   S   S
'   US	   (       a  US	   X#   S   S
'   USS/:w  a:  US   US	   :w  a.  US   (       a  US   X#   S   S'   US	   (       a  US	   X#   S   S'   USS/:w  a:  US   US	   :w  a.  US   (       a  US   X#   S   S'   US	   (       a  US	   X#   S   S'   U/ / /:w  a`  [        US   5      n[        US	   5      n	X:w  a>  X-
  =n
(       a  [        U
5      X#   S   S'   X-
  =n(       a  [        U5      X#   S   S'   gggg)zo
Analyse if interfaces such as bonds, bridges and VRFs are correctly attached to their
members and vice versa.
r   r%   bondr&   bridgevrfr-   NrD   missing_bond_linkmissing_bridge_linkmissing_vrf_linkmissing_interfaces)r2   r3   rE   r1   )r   r=   rF   r7   r   r   r   r-   systemnetplanmissing_systemmissing_netplans               r   rT   &NetplanDiffState._analyze_parent_links  s   
 EJJL!!$

>2.226:FJJXZ<[<_<_`f<gh**^R044X>

?\^@_@c@cdl@mnzz."-11%8&**_VX:Y:]:]^c:dejj488rJFJJWfhjLkLoLop|  A  MB  C
D$<DGtAw$6AwDHGO,-@AAwCG7N+,?@dD\!fQi6!9&<ayFLQiO,-BCayEKAYN+,AB4,3q6SV#31vCFq6O,-?@1vBEa&N+,>?"b!A'F*Q-(G %,%55>5HL^H\EK/0DE&,&66?6IMoI^EK01EF 7	 !	 "r   r   c                    [        5       nU H  nUR                  [        R                  :X  a  U R	                  S5      Ul        U R                  UR                  5      Ul        U R                  UR                  5      Ul        U R                  UR                  5      Ul        UR                  S:w  a7  UR                  R                  S5      nUS   S:X  d	  US   S:X  a
  US   Ul        UR                  U5        M     U$ )z^Apply some transformations to Netplan routes so their representation
will match the system's.
mainr   r   rD   32128r   )r1   tabler   _TABLE_UNSPEC_$_default_route_tables_name_to_numberr   r   	from_addrviasplitru   )r   r   new_routes_setr   	ip_prefixs        r   r   "NetplanDiffState._normalize_routes  s     E{{l999"GGO 22588<EH"99%//JEO33EII>EI xx9$!HHNN3/	Q<4'9Q<5+@(|EHu%# & r   c                    [        5       nU R                  R                  5       nUR                  S5      nUR	                  5        Vs/ s H  nUR                  S5      U:X  d  M  UPM     nnU VVs/ s H  oUR                  S/ 5        H  owPM     M     nnnUR                  S5      =n	(       a  U Vs/ s HX  nUR                  S5      S:X  d  M  UR                  S5      [
        R                  :X  d  M?  UR                  S5      S:X  d  MV  UPMZ     n
n[        SU	[
        R                  SS	9n[        U
5      S
:X  aR  U
S   R                  S5      =n(       a  Xl	        U
S   R                  S5      =n(       a  U R                  U5      Ul        UR                  U5        UR                  S5      =n(       Ga  U Vs/ s HX  nUR                  S5      S:X  d  M  UR                  S5      [        R                  :X  d  M?  UR                  S5      S:X  d  MV  UPMZ     n
nU R                  U5      n[        SU[        R                  SS	9n[        U
5      S
:X  aR  U
S   R                  S5      =n(       a  Xl	        U
S   R                  S5      =n(       a  U R                  U5      Ul        UR                  U5        U$ s  snf s  snnf s  snf s  snf )af  Convert the gateway4 and gateway6 properties to NetplanRoutes.
The only information stored by these properties is the destination IP for
the default route. Networkd and Network Manager will set a default metric
for it when the route is installed. As we have no control over it, there
will always be a diff. The same is true for the route table number.
To avoid the noise in the diff report when these properties are used,
we use the following heuristic: if there is one and only one static default
route in the system and gateway4 and/or gateway6 are used, we set the same
metric and table as found in the system.
rA   r   gateway4r   r   familyprotocolstatic)r   r   r   r   rD   r   metricr   gateway6)r1   r%   r   rE   valuesr   valuer   lenr   r   r   ru   r   r   )r   r=   
routes_setr9   r<   rF   ifacesr   r   r   default_routesr   r   r   s                 r   r   $NetplanDiffState._normalize_gateways  s    U
 --668JJt$	%6%=%=%? 3%?EYYt_	1 %? 3%+QVE8R9P%9P%VQzz*--8-17 E!&4I!= $"'))H"5"F $ #())J"78"C $N E
 !I8GMM\deE>"a'+A.228<<6<#)L*1-11'::5:"&"K"KE"REKNN5!zz*--8-17 E!&4I!= $"'))H"5"G $ #())J"78"C $N E 228<H I8HNN]efE>"a'+A.228<<6<#)L*1-11'::5:"&"K"KE"REKNN5!O3QE EsB   J?%J?2$K5K
!K
7K
K
?K!KKKr   r   c                    U Vs/ s H,  n[        [        R                  " U5      R                  5      PM.     nn[	        [        S U5      5      nU Vs/ s H,  n[        [        R                  " U5      R                  5      PM.     nnUR                  S0 5      R                  S/ 5      n[        5       nU GH3  n	U	R                  S:X  aA  U	R                  S:w  a1  [        R                  " U	R                  5      R                  (       d  MU  U	R                  S:X  a  Mg  UR                  S0 5      R                  S5      n
U	R                  S:X  a  U
S	La  M  U	R                  S:w  a  [        R                  " U	R                  5      nUR                  (       aN  U	R                  [        R                  :X  a	  S
U;   a  GM  U	R                  [         R                  :X  a	  SU;   a  GM.  U	R                  S:X  aR  U	R"                  S:X  aB  U	R                  U;   d/  [        R                  " U	R                  5      R$                  (       a  GM  U	R                  [        R                  :X  a#  U	R"                  S:X  a  U	R                  S:X  a  GM  U	R                  [        R                  :X  a3  U	R                  S:w  a#  U	R                  U;   d  U	R                  U;   a  GM"  UR'                  U	5        GM6     U$ s  snf s  snf )ac  
Some routes found in the system are installed automatically/dynamically without
being configured in Netplan.
Here we implement some heuristics to remove these routes from the list we want
to compare. We do that because these type of routes will probably never be found in the
Netplan configuration so there is no point in comparing them against Netplan.
c                     U S:g  $ )Nz	fe80::/64r   )ns    r   rG   8NetplanDiffState._filter_system_routes.<locals>.<lambda>4  s	    qK/?r   r&   re   ri   r   rh   rm   rg   Frl   rk   hostlocal	multicastzff00::/8)r   rr   rs   networkr2   r   rw   rE   r1   scoper   rv   r   r   r   r   r   r   is_loopbackru   )r   r   r   r=   rw   local_networksrb   re   r   r   rm   route_tos               r   r   &NetplanDiffState._filter_system_routes)  s<    M]]L\b#i44R8@@AL\]f%?PQBRSBRBS//3667BR	SZZ488rJ
"E{{f$Y)>yG]G]^c^f^fGgGuGu ~~' 

?B7;;KHI~~%)5*@ xx9$$11%((;))||x~~5&J:N ||w}}4:9M  v%%***?XX*i.D.DUXX.N.Z.Z ||x~~-%**2KPUPXPX\fPf .5>>T3I^3uxx97LJJuM #N [ ^ Ts   3K13K6c                 4   U R                   R                  5       n0 nU R                  R                  R	                  5        GH  u  p40 nSSU00XS'   XS   S   n[
        R                  " UR                  S5      US'   UR                  US'   UR                  US'   UR                  US'   UR                  b  UR                  US'   UR                   Vs/ s H  owPM     nnU(       ac  0 US	'   U HX  n0 n	UR                  (       a  UR                  U	S
'   UR                  (       a  UR                  U	S'   SU	0US	   [        U5      '   MZ     [!        UR"                  5      =n
(       a  XS'   [!        UR$                  5      =n(       a  XS'   [!        UR&                  5      =n(       a  XS'   UR(                  =n(       a  XS'   UR*                  =n(       a  XS'   UR,                  =n(       a  XS'   UR.                  R                  S5      =n(       a  UR0                  US'   UR.                  R                  S5      =n(       a  UR0                  US'   UR.                  R                  S5      =n(       a  UR0                  US'   X1;  ae  SnUR	                  5        H1  u  nnUR                  S5      =n(       d  M   UU:X  d  M(  SnXS   UU'   M3     U(       d  UR3                  U5        GM  GM  UR3                  U5        GM     U R5                  U5        U$ s  snf )Nr&   rA   r   r   rc   rd   re   rm   rb   labellifetimerf   r   r   r   r   r   r   r   r   r   FT)r%   r   r&   r   r4   r
   rE   r   rc   rd   re   rm   rb   r  r  r   r2   nameserver_addressesnameserver_searchr   	_gateway4	_gateway6r   linksrA   r5   _netplan_state_find_parents)r   r9   r-   r<   r=   rF   	iface_refr}   rb   rf   nameserversr   r   r   r   macr   r   r   
found_somerJ   r   rX   s                          r   r0   (NetplanDiffState._get_netplan_interfacesa  s    --668
!%!3!3!;!;!A!A!CIE /$	1BCE(9I , 0 0g FIf!'Ig!'Ig&,&7&7Il#+)/)9)9	+&*0*:*:;*:$*:I;)+	+&%DEzz)-g}},0MMj)9@%8HIk*3t95 & #6#>#>??{?5@12f6677v728./fmm,,v,&,(#!+++x+(0*%!+++x+(0*%'''s'*-,'))(33v3&,ii	(#||''//t/$(GG	&!ll&&u--s-#&66	% 1 #
"3"9"9";JC$)IIdO3y3$	1)-J.3.>JsO	 #< "%%e, " !!%(U "DX 	((4{ <s   Lc                    [        [        5      nUR                  5        H  u  p4US   R                  S5      =n(       a  X%   R	                  U5        US   R                  S5      =n(       a  X%   R	                  U5        US   R                  S5      =n(       d  M~  X%   R	                  U5        M     UR                  5        H  u  p6[        U5      X   S   S'   M     g)z)Associates interfaces with their parents r&   r   r   r   r-   N)r   r1   r4   rE   ru   r2   )r   r-   parentsr<   r=   ri   memberss          r   r  ,NetplanDiffState._netplan_state_find_parents  s    c"!+!1!1!3Io.228<<t<!!),o.226::t:!!),o.22599t9!!), "4 #*--/ICG=J!/2<@ #2r   c                 t   0 nU R                   R                  5       R                  5        GH  u  p#US:X  a  M  UR                  S5      nSSU00X'   UR                  S5      =n(       a
  XQU   S   S'   X   S   nUR                  S5      =n(       a  XvS'   0 nUR                  S/ 5       Hk  n	[	        U	R                  5       5      S   n
U	R                  U
5      R                  S5      nU
 S	U 3nS
U	R                  U
5      R                  S
/ 5      0X'   Mm     U(       a  XS'   UR                  S5      =n(       a  XS'   UR                  S5      =n(       a  XS'   UR                  S5      =n(       a%  U Vs/ s H  nU R                  U5      PM     snUS'   UR                  S5      =n(       a  UUS'   UR                  S5      =n(       a  UUS'   UR                  S5      =n(       a  UUS'   UR                  S5      =n(       a  UUS'   UR                  S5      =n(       d  GM  UUS'   GM     U$ s  snf )Nznetplan-global-stater   r%   rA   rB   rb   r   prefixr   rf   dns_addressesr   
dns_searchr   r   r   r-   r   r   r   )r%   r   r4   rE   r2   r3   _system_route_to_netplan)r   r-   r<   r=   device_typerX   r  rB   rb   r}   rw   r   	full_addrr  r   r   r   r  uplink_interfacesr   r   r   s                         r   r/   'NetplanDiffState._get_system_interfaces  sM   
!%!2!2!;!;!=!C!C!EI22 **V,K%3fk5J$KJ!"JJt,,y,>G9%n5d;"-n=I

7++u+%*'"I

;3$))+&q)"))(3!d!F8,	(/"1A1A'21N'O	$ 4 )2+&$jj99{95@12L11v128./H--v-Y_&`Y_PUt'D'DU'KY_&`	(#jj..s.*-	,'$*JJ|$<< <*;	,'zz&))t)$(	&!H--v-&,	(#jj''s''#&	% _ "Fb # 'as   9H5system_routec                 4   0 nUR                  S5      =n(       a  X2S'   UR                  S5      =n(       a  XBS'   UR                  S5      =n(       a  XRS'   UR                  S5      =n(       a  XbS'   UR                  S5      =n(       a  XrS'   UR                  S5      =n(       a  XS'   UR                  S5      =n	(       a  XS'   UR                  S	5      =n
(       a  XS	'   UR                  S
5      =n(       a  U R                  U5      US
'   [        S0 UD6$ )Nr   r   r   fromr   r   r  r   r   r   r   )rE   r   r   )r   r(  r   r   r   r   r   r   r  
route_typer   r   s               r   r#  )NetplanDiffState._system_route_to_netplan  s)   !%%h//6/$(O!!$''2'$K""5))3)%L$((0090!*+!%%h//6/$(O $$W--5-"'N%))&11:1&&M#''
3383 (* $$W--5-!FFuME'N$e$$r   r7   c                     UR                  5       (       a  [        U5      $ U R                  (       d  [        5       U l        U R                  R	                  US5      $ )Nr   )isdigitintr(   r   rE   )r   r7   s     r   r   5NetplanDiffState._default_route_tables_name_to_number  sD    <<>>t9,,,>,@D),,00q99r   )r&   r(   r%   ) )&r   r   r   r    __doc__r   r	   r)   rU   r>   r   rY   rL   r/  rN   rO   rK   r1   rq   r   rP   rQ   rR   rS   rM   rT   r   r   r   r   r2   r   r0   r  r/   r#  r   r!   r   r   r   r#   r#   &   s   
+%6 +GY + :'# 't 'R
D 
	
3 	
3 	
s 	
t 	
>D > >$ >@T d ,	 	 	c c ;4 ; ; ;z%d %4 %D %NT $ 4 &d 4 D 6!$ !3 !4 !F&_D &_ &_$ &_P  46$ 6;|3L 6p6;|3L 6`deh`i 6sw 6| 6pP PdQd Qt Q4 4l%T %l %0: : :r   r#   )collectionsr   rr   r   socketr   r   typingr   netplan.netdefr   netplan_cli.cli.stater   r	   r
   netplan_cli.cli.utilsr   r   r   r   r#   r   r   r   <module>r9     s@   $ $   $  ' U U I3d&& 3p: p:r   