
    x[h!              
           U d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ d	g d
edgdZeed<    ej$                  e      ZdedefdZd Zd Zdedede	deddf
dZy)z<Yum Add Repo: Add yum repository configuration to the system    N)ConfigParser)util)Cloud)Config)
MetaSchema)PER_INSTANCEcc_yum_add_repo)	almalinux
azurelinuxcentos
cloudlinux	eurolinuxfedoramariner	openeulerOpenCloudOSopenmandrivaphotonrhelrocky	TencentOS	virtuozzo	yum_repos)iddistros	frequencyactivate_by_schema_keysmetarepo_idreturnc                 &    | j                  dd      S )af  Canonicalize repo id.

    The sole name convention for repo ids is to not contain namespaces,
    and typically the separator used is `-`. More info:
    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-setting_repository_options

    :param repo_id: Repo id to convert.
    :return: Canonical repo id.
     -)replace)r   s    B/usr/lib/python3/dist-packages/cloudinit/config/cc_yum_add_repo.py_canonicalize_idr&   /   s     ??3$$    c                 
   t        | t              rt        t        |             S t        | t        t
        f      r(dj                  | D cg c]  }t        |       c}      S t        | t              st        |       S | S c c}w )N
)
isinstanceboolstrintlisttuplejoin_format_repo_value)valvs     r%   r1   r1   <   sg    #3s8}#e}% yy=A,Q/=>>c33xJ >s   
B c                    t               }|j                  |        |j                         D ]!  \  }}|j                  | |t	        |             # t        j                         }|j                  |       |j                  d       |j                         }|j                  ddt        j                         z         dj                  |      S )Nr   z# Created by cloud-init on %s
 )r   add_sectionitemssetr1   ioStringIOwriteseek	readlinesinsertr   time_rfc2822r0   )r   repo_configto_bekr3   to_be_streamliness          r%   _format_repository_configrE   K   s    NE	g!!# 51 			'10345 ;;=L	KKa""$E	LL59J9J9LMN775>r'   namecfgcloudargsc                    |j                  d      }|st        j                  d|        y t        j                  |dd      }i }i }|j                         D ]4  \  }}	t        |      }
t        j                  j                  |d|
z        }t        j                  j                  |      rt        j                  d||       l|
|v rt        j                  d||       |	si }	i }|	j                         D ];  \  }}|j                         j                         j                  dd	      }|s7|||<   = |}	d
}g d}|D ]  }||	vs|dz  } |t        |      k(  r(t        j!                  d|dj                  |             +|	||
<   |||
<   7 |j                         D ]6  \  }}t#        ||j                  |            }t        j$                  ||       8 y )Nr   z<Skipping module named %s, no 'yum_repos' configuration foundyum_repo_dirz/etc/yum.repos.d/z%s.repoz)Skipping repo %s, file %s already exists!z*Skipping repo %s, file %s already pending!r#   _r   )baseurlmetalink
mirrorlist   z^Repository %s should contain atleast one of the following configuration entries: %s, skipping!z, )getLOGdebugr   get_cfg_option_strr7   r&   ospathr0   existsinfolowerstripr$   lenwarningrE   
write_file)rF   rG   rH   rI   reposrepo_base_pathrepo_locationsrepo_configsr   r@   canon_repo_idrepo_fn_pthn_repo_configrB   r3   missing_required
req_fields	req_field	c_repo_idrV   	repo_blobs                        r%   handlerj   [   s   GGK E		J	
 	,,^0N NL % )8(1ggll>93NO77>>+&HH;
 n,HH<
 K%%' 	%DAq	!))#s3A#$a 	% $:
# 	&I+ A% 	& s:.KKB		*%	 +6L',7N=)S)8V *//1 )	4-|''	2
	 	i(	)r'   )__doc__r9   loggingrU   configparserr   	cloudinitr   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr   r   __annotations__	getLogger__name__rR   r,   r&   r1   rE   r.   rj    r'   r%   <module>rw      s    C 	  	 %  ! # . + "  +})j 0 g!
%c 
%c 
%
 <) <)6 <)% <)t <) <)r'   