ó
    /I_4&  ã                   óH   • S r SSKrSSKrSSKr " S S5      r\" 5       qS rg)a9  
The PolicyManager should be subclassed by addon modules
to read a JSON policy config file that is later used to
set defaults:

Initialize: This module defines a list of config file location based
          on module.  There are defined in the __init__():  All the
          addon modules need to do is import the policymanager module.

          import ifupdown2.ifupdown.policymanager as policymanager


Provides: an API to retrieve link attributes based on addon module name,
          interface name, and attribute.

        The ifupdown.policymanager module provides a global object policymanager_api
        that can be called like so:

        speed_default = policymanager.policymanager_api.get_default(
            module_name='ethtool',
            ifname=ifaceobj.name,
            attr='link-speed'
            )
é    Nc                   óD   • \ rS rSrS rS
S jrSS jrSS jrS rS r	S	r
g)Úpolicymanageré$   c                 óJ  • [         R                  " SU R                  R                  -   5      U l        U R                  R                  S5        [        R                  " S5      n[        R                  " S5      n0 U l        U GH)  n0 n [        US5       n[        R                  " U5      nS S S 5        U R                  R                  SU-  5        [        UR!                  5       5       H¼  nXpR                  ;   aE  U R                  R                  S	U< S
U< 35        U R                  U   R#                  XG   5        MW  XG   n[%        U[&        5      (       a  XG   U R                  U'   Mƒ  US:w  d  M‹  U R                  R                  SU< SU< S[)        U5      < S35        M¾     GM,     0 U l        U GH  n0 n	 [        US5       n[        R                  " U5      n	S S S 5        U R                  R                  SU-  5        [        U	R!                  5       5       Hš  nXpR                  ;   a#  U R                  R                  SU< SU< 35        XpR*                  ;   aE  U R                  R                  SU< S
U< 35        U R*                  U   R#                  X—   5        M‰  X—   U R*                  U'   Mœ     GM
     g ! , (       d  f       GN!= f! [         aP  nU R                  R                  SU-  5        U R                  R                  S[        U5      -  5         S nAGN[S nAff = f! , (       d  f       GNY= f! [         aP  nU R                  R                  SU-  5        U R                  R                  S[        U5      -  5         S nAGN“S nAff = f)Nz	ifupdown.zpolicymanager initz&/etc/network/ifupdown2/policy.d/*.jsonz"/var/lib/ifupdown2/policy.d/*.jsonÚrz(reading %s system policy defaults configz/could not read %s system policy defaults configz    exception is %sz%policymanager: merging system module z policy with file ÚREADMEzfile z) contains an invalid policy schema, key "z" contains z when a dictionary is expectedz&reading %s policy user defaults configz-could not read %s user policy defaults configz-warning: overwriting system with user module z from file z#policymanager: merging user module )ÚloggingÚ	getLoggerÚ	__class__Ú__name__ÚloggerÚinfoÚglobÚsystem_policy_arrayÚopenÚjsonÚloadÚdebugÚ	ExceptionÚwarningÚstrÚlistÚkeysÚupdateÚ
isinstanceÚdictÚtypeÚuser_policy_array)
ÚselfÚ
user_filesÚdefault_filesÚfilenameÚsystem_arrayÚfdÚeÚmoduleÚ	json_dictÚ
user_arrays
             Ú./usr/share/ifupdown2/ifupdown/policymanager.pyÚ__init__Úpolicymanager.__init__%   s  € ô ×'Ò'¨Ø ŸN™N×3Ñ3ñ)4ó 5ˆŒð 	‰×ÑÐ-Ô.ô —Y’YÐGÓHˆ
äŸ	š	Ð"FÓGˆà#%ˆÔ Ü%ˆHØˆLðDÜ˜( CÔ(¨BÜ#'§9¢9¨R£=L÷ )à—‘×!Ñ!Ð"LØ$,ñ#-ô .ô ˜|×0Ñ0Ó2Ö3Ø×5Ñ5Ó5Ø—K‘K×%Ò%ÓgmÒowÐ&xÔyØ×,Ñ,¨VÑ4×;Ñ;¸LÑ<PÖQà ,Ñ 4Iä! )¬T×2Ñ2Ø;GÑ;O˜×0Ñ0°Ó8Ø 8Õ+ØŸ™×+Ò+ó &£v¬t°I®ð@öô 4ñ &ð: "$ˆÔÜ"ˆHØˆJðDÜ˜( CÔ(¨BÜ!%§¢¨2£J÷ )à—‘×!Ñ!Ð"JØ$,ñ#-ô .ô ˜zŸ™Ó0Ö1Ø×5Ñ5Ó5à—K‘K×%Ò%Û)/²ð':ô ;à×3Ñ3Ó3Ø—K‘K×%Ò%ÓekÒmuÐ&vÔwØ×*Ñ*¨6Ñ2×9Ñ9¸*Ñ:LÖMà5?Ñ5GD×*Ñ*¨6Ó2ô 2ñ #ð, 	÷c )Ö(ûô ó DØ—‘×#Ñ#Ð$UØ$,ñ%-ô .à—‘×#Ñ#Ð$9¼CÀ»FÑ$B×CÒCûðDú÷4 )Ö(ûô ó DØ—‘×#Ñ#Ð$SØ$,ñ%-ô .à—‘×#Ñ#Ð$9¼CÀ»FÑ$B×CÒCûðDúsb   Â
KÂKÂ-&KÇMÇL6Ç$&MË
K	ËKË
L3Ë#AL.Ì.L3Ì6
M	Í MÍ
N"ÍANÎN"Nc                 óØ  • U(       a  U(       a  U(       d  gSn U R                   U   S   U   U   nU$ ! [        [        [        4 a     Of = f U R                   U   S   U   nU$ ! [        [        [        4 a     Of = f U R                  U   S   U   U   nU$ ! [        [        [        4 a     Of = f U R                  U   S   U   nU$ ! [        [        [        4 a     U$ f = f)av  
get_iface_default: Addon modules must use one of two types of access methods to
the default configs.   In this method, we expect the default to be
either in
    [module]['iface_defaults'][ifname][attr] or
    [module]['defaults'][attr]
We first check the user_policy_array and return that value. But if
the user did not specify an override, we use the system_policy_array.
NÚiface_defaultsÚdefaults©r   Ú	TypeErrorÚKeyErrorÚ
IndexErrorr   )r   Úmodule_nameÚifnameÚattrÚvals        r)   Úget_iface_defaultÚpolicymanager.get_iface_defaultj   s  € ö žd®+Øàˆð	à×(Ñ(¨Ñ5Ð6FÑGÈÑOÐPTÑUˆCØˆJøÜœ8¤ZÐ0ó 	Ùð	úð	à×(Ñ(¨Ñ5°jÑAÀ$ÑGˆCØˆJøÜœ8¤ZÐ0ó 	Ùð	úð	à×*Ñ*¨;Ñ7Ð8HÑIÈ&ÑQÐRVÑWˆCØˆJøÜœ8¤ZÐ0ó 	Ùð	úð	à×*Ñ*¨;Ñ7¸
ÑCÀDÑIˆCØˆJøÜœ8¤ZÐ0ó 	Øð ˆ
ð		úsE   š4 ´AÁAÁA' Á'A?Á>A?ÂB ÂB5Â4B5Â9C ÃC)Ã(C)c                 óò   • U(       a  U(       d  gSn U R                   U   S   U   nU$ ! [        [        [        4 a     Of = f U R                  U   S   U   nU$ ! [        [        [        4 a     U$ f = f)a<  
get_attr_default: Addon modules must use one of two types of access methods to
the default configs.   In this method, we expect the default to be in

[module]['defaults'][attr]

We first check the user_policy_array and return that value. But if
the user did not specify an override, we use the system_policy_array.
Nr.   r/   ©r   r3   r5   r6   s       r)   Úget_attr_defaultÚpolicymanager.get_attr_default—   s’   € ö žKØð ˆð	à×(Ñ(¨Ñ5°jÑAÀ$ÑGˆCØˆJøÜœ8¤ZÐ0ó 	Ùð	úð	à×*Ñ*¨;Ñ7¸
ÑCÀDÑIˆCØˆJøÜœ8¤ZÐ0ó 	Øàˆ
ð	úó!   “* ªAÁAÁA ÁA6Á5A6c                 óò   • U(       a  U(       d  gSn U R                   U   S   U   nU$ ! [        [        [        4 a     Of = f U R                  U   S   U   nU$ ! [        [        [        4 a     U$ f = f)aD  
get_module_globals: Addon modules must use one of two types of access methods to
the default configs.   In this method, we expect the default to be in

[module]['module_globals'][attr]

We first check the user_policy_array and return that value. But if
the user did not specify an override, we use the system_policy_array.
NÚmodule_globalsr/   r:   s       r)   Úget_module_globalsÚ policymanager.get_module_globalsµ   s”   € ö žKØð ˆð	à×(Ñ(¨Ñ5Ð6FÑGÈÑMˆCØˆJøÜœ8¤ZÐ0ó 	Ùð	úð	à×*Ñ*¨;Ñ7Ð8HÑIÈ$ÑOˆCØˆJøÜœ8¤ZÐ0ó 	Øàˆ
ð	úr=   c                 ó*  • U(       d  [        S5      e[        5       nUR                  U R                  R	                  U0 5      R	                  S0 5      5        UR                  U R
                  R	                  U0 5      R	                  S0 5      5        U$ )z
get_module_defaults: returns a merged dictionary of default values
specified in policy files. Users provided values override system
values.
z.get_module_defaults: module name can't be Noner.   )ÚNotImplementedErrorr   r   r   Úgetr   ©r   r3   r.   s      r)   Úget_module_defaultsÚ!policymanager.get_module_defaultsÔ   sy   € ö Ü%Ð&WÓXÐXä“6ˆØ‰˜×0Ñ0×4Ñ4°[À"ÓE×IÑIÈ*ÐVXÓYÔZØ‰˜×.Ñ.×2Ñ2°;ÀÓC×GÑGÈ
ÐTVÓWÔXØˆó    c                 óN  • [        5       nU(       d  U R                  R                  S5        U$ UR                  U R                  R                  U0 5      R                  S0 5      5        UR                  U R                  R                  U0 5      R                  S0 5      5        U$ )Nz-get_iface_defaults: module name can't be Noner-   )r   r   r   r   r   rD   r   rE   s      r)   Úget_iface_defaultsÚ policymanager.get_iface_defaultsã   s‰   € Ü“6ˆæØK‰K×ÑÐMÔNð ˆð O‰O˜D×4Ñ4×8Ñ8¸ÀbÓI×MÑMÐN^Ð`bÓcÔdØO‰O˜D×2Ñ2×6Ñ6°{ÀBÓG×KÑKÐL\Ð^`ÓaÔbØˆrH   )r   r   r   )NNN)NN)r   Ú
__module__Ú__qualname__Ú__firstlineno__r*   r7   r;   r@   rF   rJ   Ú__static_attributes__© rH   r)   r   r   $   s#   † òCôJ+ôZô<ò>õrH   r   c                  ó   • [        5       qg )N)r   Úpolicymanager_apirP   rH   r)   ÚresetrS   ð   s
   € ä%›ÑrH   )Ú__doc__r   r   r	   r   rR   rS   rP   rH   r)   Ú<module>rU      s1   ðñó2 Û Û ÷Gñ GñT "“OÐ ó(rH   