+
    i6                     z  a  R% t)0 t R t^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	 ^ RI
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ]! R	R
.4      tRRRR.R]RR.]! ]4      ,           /t] ^ k ]P4                  ! ]4      tRtRtR&tR R lt R R lt!R'R R llt"R'R lt#R R lt$R R lt%R R  lt&R! R" lt'R# R$ lt(R# )(z1ubuntu_pro: Configure Ubuntu Pro support servicesN)AnyList)urlparse)performancesubputilCloud)Config)
MetaSchema)PER_INSTANCEzubuntu-advantageubuntu_advantageidcc_ubuntu_prodistrosubuntu	frequencyactivate_by_schema_keys
ubuntu_proREDACTEDzUUnable to determine if this is an Ubuntu Pro instance. Fallback to normal Pro attach.c                $    V ^8  d   QhR\         /#    pro_sectiondict)formats   "@/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_pro.py__annotate__r   *   s        $      c                    R V 9  d   R# V R ,          p\        V\        4      '       g9   R\        V4      P                   2p\        P                  V4       \        V4      hRV9  d   R# VR,          p\        V\        4      '       g9   R\        V4      P                   2p\        P                  V4       \        V4      hR# )featuresNz.'ubuntu_pro.features' should be a dict, not a disable_auto_attachzB'ubuntu_pro.features.disable_auto_attach' should be a bool, not a )
isinstancer   type__name__LOGerrorRuntimeErrorbool)r   r!   msgr"   s   &   r   validate_schema_featuresr+   *   s    $ :&Hh%%X''(* 	 			#3 H,"#89)400/099:< 	 			#3 1r   c                $    V ^8  d   QhR\         /# r   
pro_configr   )r   s   "r   r   r   E   s     $
 $
t $
r   c                   . p\        V P                  4       4       Fa  w  r#V\        9  d   \        P	                  RV4       K(  Vf   K.   \        V4      pVP                  R9  d   VP                  RV 24       Ka  Kc  	  V'       d*   \        RP                  RP                  V4      4      4      hR#   \        \        3 d    TP                  RT 24        K  i ; i)a  Validate user-provided ua:config option values.

This function supplements flexible jsonschema validation with specific
value checks to aid in triage of invalid user-provided configuration.

Note: It does not log/raise config values as they could be urls containing
sensitive auth info.

@param pro_config: Dictionary of config value under 'ubuntu_pro'.

@raises: ValueError describing invalid values provided.
z4Not validating unknown ubuntu_pro.config.%s propertyNz-Expected URL scheme http/https for ua:config:zExpected a URL for ua:config:z$Invalid ubuntu_pro configuration:
{}
)httphttps)sorteditemsKNOWN_PRO_CONFIG_PROPSr&   warningr   schemeappendAttributeError
ValueErrorr   join)r.   errorskeyvalue
parsed_urls   &    r   supplemental_schema_validationr@   E   s     FZ--/0
,,KKF ]	A!%J  (99CC5I : 1& 3::499V;LM
 	
  
+ 	AMM9#?@	As   0B44%CCc                $    V ^8  d   QhR\         /# r-   )r   )r   s   "r   r   r   l   s     )
 )
s )
r   c                    V f   R # \        V \        4      '       g#   \        R\        V 4      P                   R24      h\        V 4       . p\        V P                  4       4       F  w  r#R p/ pVf   \        P                  RV4       RRRV.pMpV R2p\        P                  RV4       \        P                  ! R	V4      '       d   V R
\        P                  ! V4       2pMV R
V 2pRRRV.pRVR R V.,           /p \        P                  ! V3/ VB  K  	  V'       dR   V F  w  r\        P'                  RW4       K  	  \        RP)                  RP+                  R V 4       4      4      4      hR #   \        P                   dD   p\        T4      p	Te   T	P!                  T\"        4      p	TP%                  Y)34        R p?EKd  R p?ii ; i)Nz+ubuntu_pro: config should be a dict, not a z%; skipping enabling config parameterszDisabling Pro config for %sproconfigunsetz	=REDACTEDzEnabling Pro config %sz\s=set	logstringz#Failure enabling/disabling "%s":
%sz3Failure enabling/disabling Ubuntu Pro config(s): {}, c              3   H   "   T F  w  rR P                  V4      x  K  	  R# 5i)z"{}"N)r   ).0param_s   &  r   	<genexpr>!set_pro_config.<locals>.<genexpr>   s     M}85&--..}s    ")r#   r   r(   r$   r%   r@   r3   r4   r&   debugresearchescaper   ProcessExecutionErrorstrreplacer   r8   r6   r   r;   )r.   enable_errorsr=   r>   redacted_key_valuesubp_kwargs
config_cmd	key_valueeerr_msgrL   r'   s   &           r   set_pro_configr_   l   s   j$''z"++, -33
 	

 #:.MZ--/0
!=II3S97C8J$'5	!2II.0BCyy&&"e1RYYu%5$67	"e1UG,	5)<J&
3B;M:N(NOK	1IIj0K0! 1, )LEKK>M *AHH		M}MM
 	
  )) 	1!fG!-!//%:  #00		1s    E66G7G		Gc                   Vf   . pMp\        V\        4      '       d   \        P                  R4       V.pMA\        V\        4      '       g,   \        P                  R\        V4      P                  4       . pV'       d   RRRV .pMRRV .pVRR \        .,           p\        P                  RRP                  V4      4        \        P                  ! V^ ^0VR	7       T'       g   R# . ROT,           p \        P                  ! TR^ ^0R7      w  r \         P"                  ! T4      p
. pT
P'                  R. 4       FA  pTR,          R8X  d    \        P                  RTR,          4       K0  TP)                  T4       KC  	  T'       d   . pT Fj  pTP'                  R4      pTe"   TP)                  T4       RT RTR,           2pMRTR,           RTR,           2p\        P                  ! \        T4       Kl  	  \        RRP                  T4      ,           4      hR#   \        P                   dQ   p\        T4      P                  T \        4      pR
T 2p\        P                  ! \        T4       \        T4      ThRp?ii ; i  \        P                   d(   p\        RRP                  T4      ,           4      ThRp?ii ; i  \         P$                   d   p\        RT 24      ThRp?ii ; i)z=Call ua command line client to attach and/or enable services.NzNubuntu_pro: enable should be a list, not a string; treating as a single enablezIubuntu_pro: enable should be a list, not a %s; skipping enabling servicesrC   attachz--no-auto-enablezAttaching to Ubuntu Pro. %s )rcsrH   zFailure attaching Ubuntu Pro:
T)capturerc   z!Error while enabling service(s): rI   zPro response was not json: r<   message_codezservice-already-enabledzService `%s` already enabled.servicezFailure enabling `z`: messagezFailure of type `r$   z(Failure enabling Ubuntu Pro service(s): rP   )rC   enablez--assume-yesz--formatjson)r#   rV   r&   r6   listr$   r%   r   rQ   r;   r   rU   rW   r   logexcr(   ri   loadsJSONDecodeErrorgetr8   )tokenrh   
attach_cmdredacted_cmdr]   err*   cmdenable_stdoutrM   enable_resprX   errerror_servicesrf   s   &&             r   configure_prorx      s   ~	FC	 	 5	
 %%0L!!	

  X'95A
Xu-
cr?hZ/LII+SXXl-CD'		*1a&LA 
?&
HC99S$QFCjj/< !#Mx,~";;II5s9~FS!	 - $& Cggi(G"%%g.*7)3s9~6FG)#f+c#i.9IJKKS! ! 6ii'(
 	
 o %% 'V^^E8,/t4C3Q&	' %% /$))F2CC
	  )-9
	sI   H 4J K J3AI>>JK"J==KK.K))K.c                $    V ^8  d   QhR\         /# )r   cloudr   )r   s   "r   r   r      s      % r   c                ^   \         P                  ! R4      '       d   R#  V P                  P                  4         T P                  P                  R.4       R#   \         d    \
        P                  ! \        R4       h i ; i  \         d    \
        P                  ! \        R4       h i ; i)z.Install ubuntu-advantage-tools if not present.rC   NzPackage update failedzubuntu-advantage-toolsz(Failed to install ubuntu-advantage-tools)	r   whichdistroupdate_package_sources	Exceptionr   rk   r&   install_packages)rz   s   &r   maybe_install_ua_toolsr      s    zz%++-%%'?&@A	  C01
  CCDs   A B (B(B,c                0    V ^8  d   QhR\         R\        /# )r   r   return)r   r)   )r   s   "r   r   r     s     % %T %d %r   c                    \        V P                  R / 4      P                  RR4      4      pV'       d   R# ^ RIHp ^ RIHp  \        P                  ! RRR7      ;_uu_ 4        V! 4       pRRR4       VP
                  #   + '       g   i     XP
                  # ; i  T d;   p\        P                  R	T4       \        P                  \        4        Rp?R# Rp?ii ; i)
r!   r"   F)UserFacingError)should_auto_attachz6Checking if the instance can be attached to Ubuntu Proalwayslog_modeNz%Error during `should_auto_attach`: %s)r)   rn   uaclient.api.exceptionsr   4uaclient.api.u.pro.attach.auto.should_auto_attach.v1r   r   Timedr&   rQ   r6   ERROR_MSG_SHOULD_AUTO_ATTACH)r   r"   r   r   resultexs   &     r   _should_auto_attachr     s    
B'++,A5I  8	D
 
 ()F	
 $$$
 
 $$$	  		92>01s6    B #A?+B ?B	
B B C$/CCc                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r   (  s     A A Ar   c                 .   V P                  R 4      pV'       g#   Rp\        P                  V4       \        V4      hV P                  R4      pV'       d&   \        P	                  RRP                  V4      4       \        WP                  R4      R7       R# )ro   z8`ubuntu_pro.token` required in non-Pro Ubuntu instances.enable_betaz<Ignoring `ubuntu_pro.enable_beta` services in Pro attach: %srI   rh   )ro   rh   N)rn   r&   r'   r(   rQ   r;   rx   )r   ro   r*   r   s   &   r   _attachr   (  sm    OOG$EH		#3//-0K		JIIk"	
 ooh&?@r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r   7  s     ( (d (r   c                    ^ RI HpHp ^ RIHpHp V P                  R4      pV P                  R4      pV! VVR7      p \        P                  ! RRR7      ;_uu_ 4        V! VR	7       R
R
R
4       R
#   + '       g   i     R
# ; i  T d%    Tf   Te   \        P                  R4        R
#  R
# T d6   pRTP                   2p	\        P                  T	4       \        T	4      ThR
p?ii ; i)    )AlreadyAttachedErrorr   )FullAutoAttachOptionsfull_auto_attachrh   r   )rh   r   zAttaching to Ubuntu Pror   r   )optionsNzThe instance is already attached to Pro. Leaving enabled services untouched. Ignoring config directives ubuntu_pro: enable and enable_betaz!Error during `full_auto_attach`: )r   r   r   2uaclient.api.u.pro.attach.auto.full_auto_attach.v1r   r   rn   r   r   r&   r6   r*   r'   r(   )
r   r   r   r   r   rh   r   r   r   r*   s
   &         r   _auto_attachr   7  s     N __X&F//-0K#G(88LLW- MLLL "f&8KK6 '9  (1"&&:		#3R'(sA    B 
A2(B 2B	=B B $C+0C+5C+60C&&C+c          
      L    V ^8  d   QhR\         R\        R\        R\        RR/# )r   namecfgrz   argsr   N)rV   r
   r	   rj   )r   s   "r   r   r   Y  s6     B B B6 B% Bt B Br   c                    R p\        \        P                  V4      4      pV'       df   \        V4      ^8  d"   \	        RRP                  V4      ,          4      h\        P                  RRP                  V4      4       W^ ,          ,          pRV9   d/   V'       d   \        P                  RV^ ,          4       VR,          pVf   \        P                  RV 4       R # \        V\        4      '       g9   R\        V4      P                   2p\        P                  V4       \	        V4      hRV9   d#   R	p\        P                  V4       \	        V4      h\        V4       \        VP!                  R
4      4       \#        V4       \        P                  R4       \%        V4      '       d   \'        V4       R # VP)                  4       R08:  g   \+        V4       R # R # )NzLUnable to configure Ubuntu Pro. Multiple deprecated config keys provided: %srI   z^Deprecated configuration key(s) provided: %s. Expected "ubuntu_pro"; will attempt to continue.r   z;Ignoring deprecated key %s and preferring ubuntu_pro configz=Skipping module named %s, no 'ubuntu_pro' configuration foundz%'ubuntu_pro' should be a dict, not a commandszPDeprecated configuration "ubuntu-advantage: commands" provided. Expected "token"rD   zETo discover more log info, please check /var/log/ubuntu-advantage.logr!   )rj   DEPRECATED_KEYSintersectionlenr(   r;   r&   r6   rQ   r#   r   r$   r%   r'   r   r_   rn   r+   r   r   keysr   )r   r   rz   r   r   
deprecatedr*   s   &&&&   r   handler   Y  s   Ko22378Jz?Q%'+yy'<=  	@IIj!	

 Q-(sKKM1 ,'		K	
 	T**[!**+- 	 			#3[   	 			#35!;??8,- [)IIO ;''[! J</ 0r   c                @    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   # )r   meta)__conditional_annotations__r   )r   s   "r   r   r      s     7 7  j ! 8r   )
http_proxyhttps_proxyglobal_apt_http_proxyglobal_apt_https_proxyua_apt_http_proxyua_apt_https_proxy)N)*r   __doc__ri   loggingrR   typingr   r   urllib.parser   	cloudinitr   r   r   cloudinit.cloudr	   cloudinit.configr
   cloudinit.config.schemar   cloudinit.settingsr   rG   r   rj   r   	getLoggerr%   r&   r   r   r5   r+   r@   r_   rx   r   r   r   r   r   r   )r   s   @r   <module>r      s    8   	  ! - - ! # . +)+=>? 	/z~_0EE	  !&   6$
N)
Xa
H %8A(DBr   