
    f                     n   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g d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d<    ee      Z  ej4                  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)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.
)	almalinuxcentos
cloudlinux	eurolinuxfedoramariner	openeulerOpenCloudOSopenmandrivaphotonrhelrocky	TencentOS	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.gpg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distrosexamples	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*   r6   r6      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setr6   ioStringIOwriteseek	readlinesinsertr   time_rfc2822r5   )r$   repo_configto_bekr8   to_be_streamliness          r*   _format_repository_configrJ      s    NE	g##% 5A 			'10345 ;;=L	KKa""$E	LL59J9J9LMN775>r,   r   cfgcloudargsc                    |j                  d      }|st        j                  d|        y t        j                  |dd      }i }i }|j                         D ],  \  }}	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
}dD ]#  }||	vst        j                  d||       |dz  }% |s|	||
<   |||
<   t        j                  d||       / |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   )baseurlzBRepository %s does not contain a %s configuration 'required' entry   z6Repository %s is missing %s required fields, skipping!)getLOGdebugr   get_cfg_option_strr<   r+   ospathr5   existsinfolowerstripr)   warningrJ   
write_file)r   rK   rL   rM   reposrepo_base_pathrepo_locationsrepo_configsr$   rE   canon_repo_idrepo_fn_pthn_repo_configrG   r8   missing_required	req_field	c_repo_idrX   	repo_blobs                       r*   handlerj      s   GGK E		J	
 	,,^0N NL"'++- ,+(1ggll>93NO77>>+&HH;
 n,HH<
 K!'') 	%FQ	!))#s3A#$a 	% $$ 	&I+6	 !A% 	&  *5L',7N=)KKH Q,Z ,113 )D-|''	2
	 	i(	)r,   )#__doc__r>   loggingrW   configparserr   textwrapr   	cloudinitr   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.settingsr
   MODULE_DESCRIPTIONr   COPR_BASEURLCOPR_GPG_URLEPEL_TESTING_BASEURLr#   __annotations__	getLogger__name__rT   r1   r+   r6   rJ   r3   rj    r,   r*   <module>r|      sU   ? 	  	 %   ! # < + $' 
  
   =%	
 	 ' ( & '	
 	 .. /	
 		
O8r  +}AAj AF t
g!
%c 
%c 
%
 >) >)6 >)% >)t >) >)r,   