
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me                 @   s<  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mZ dd	lmZ d
ZddddddddddddddgZdZdZdZdddeeedede d e d!ed"e d#ed$ged%gd&ZeeeZ ejeZeed'd(d)Zd*d+ Zd,d- Zeeee dd.d/d0Z!dS )1z<Yum Add Repo: Add yum repository configuration to the system    N)ConfigParser)dedent)util)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEa  Add yum repository configuration to ``/etc/yum.repos.d``. Configuration files
are named based on the opaque dictionary key under the ``yum_repos`` they are
specified with. If a config file already exists with the same name as a config
entry, the config entry will be skipped.
Z	almalinuxZcentosZ
cloudlinuxZ	eurolinuxZfedoraZmarinerZ	openeulerZOpenCloudOSZopenmandrivaZphotonZrhelZrockyZ	TencentOSZ	virtuozzoz_https://download.copr.fedorainfracloud.org/results/@cloud-init/cloud-init-dev/epel-8-$basearch/zXhttps://download.copr.fedorainfracloud.org/results/@cloud-init/cloud-init-dev/pubkey.gpgZcc_yum_add_repozYum Add Repoz.Add yum repository configuration to the systemz            yum_repos:
              my_repo:
                baseurl: http://blah.org/pub/epel/testing/5/$basearch/
            yum_repo_dir: /store/custom/yum.repos.d
            a,              # Enable cloud-init upstream's daily testing repo for EPEL 8 to
            # install latest cloud-init from tip of `main` for testing.
            yum_repos:
              cloud-init-daily:
                name: Copr repo for cloud-init-dev owned by @cloud-init
                baseurl: z
                type: rpm-md
                skip_if_unavailable: true
                gpgcheck: true
                gpgkey: z1
                enabled_metadata: 1
            a               # Add the file /etc/yum.repos.d/epel_testing.repo which can then
            # subsequently be used by yum for later operations.
            yum_repos:
            # The name of the repository
             epel-testing:
               baseurl: z
               enabled: false
               failovermethod: priority
               gpgcheck: true
               gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
               name: Extra Packages for Enterprise Linux 5 - Testing
            a              # Any yum repo configuration can be passed directly into
            # the repository file created. See: man yum.conf for supported
            # config keys.
            #
            # Write /etc/yum.conf.d/my-package-stream.repo with gpgkey checks
            # on the repo data of the repository enabled.
            yum_repos:
              my package stream:
                baseurl: http://blah.org/pub/epel/testing/5/$basearch/
                mirrorlist: http://some-url-to-list-of-baseurls
                repo_gpgcheck: 1
                enable_gpgcheck: true
                gpgkey: https://url.to.ascii-armored-gpg-key
            	yum_repos)idnametitledescriptiondistrosZexamplesZ	frequencyZactivate_by_schema_keys)repo_idreturnc             C   s   | 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    r   %/usr/lib/python3.6/cc_yum_add_repo.py_canonicalize_id   s    
r   c             C   sN   t | trtt| S t | ttfr8djdd | D S t | tsJt| S | S )N
c             S   s   g | ]}t |qS r   )_format_repo_value).0vr   r   r   
<listcomp>   s    z&_format_repo_value.<locals>.<listcomp>)
isinstanceboolstrintlisttuplejoin)valr   r   r   r      s    

r   c             C   sz   t  }|j|  x&|j D ]\}}|j| |t| qW tj }|j| |jd |j	 }|j
ddtj   dj|S )Nr   z# Created by cloud-init on %s
 )r   Zadd_sectionitemssetr   ioStringIOwriteseek	readlinesinsertr   Ztime_rfc2822r#   )r   repo_configZto_bekr   Zto_be_streamlinesr   r   r   _format_repository_config   s    


r1   )r   cfgcloudargsr   c             C   sp  |j d}|stjd|  d S tj|dd}i }i }x |j D ]\}}	t|}
tjj	|d|
 }tjj
|rtjd|| q@n|
|krtjd|| q@|	si }	i }x4|	j D ](\}}|j j jdd	}|r|||< qW |}	d
}x*dD ]"}||	krtjd|| |d7 }qW |s&|	||
< |||
< q@tjd|| q@W x2|j D ]&\}}t||j |}tj|| qBW d S )Nr
   z<Skipping module named %s, no 'yum_repos' configuration foundZ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   baseurlzBRepository %s does not contain a %s configuration 'required' entry   z6Repository %s is missing %s required fields, skipping!)r6   )getLOGdebugr   Zget_cfg_option_strr&   r   ospathr#   existsinfolowerstripr   Zwarningr1   Z
write_file)r   r2   r3   r4   ZreposZrepo_base_pathZrepo_locationsZrepo_configsr   r.   Zcanon_repo_idZrepo_fn_pthZn_repo_configr/   r   Zmissing_requiredZ	req_fieldZ	c_repo_idr<   Z	repo_blobr   r   r   handle   sh    




rA   )"__doc__r(   Zloggingr;   Zconfigparserr   textwrapr   Z	cloudinitr   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr	   ZMODULE_DESCRIPTIONr   ZCOPR_BASEURLZCOPR_GPG_URLZEPEL_TESTING_BASEURLmetaZ	getLogger__name__r9   r   r   r   r1   r!   rA   r   r   r   r   <module>   sb   
