o
    x[hë  ã                
   @   s¨   U d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ e e¡ZdZd	Zd
dgedgdœZeed< dede	dededdf
dd„Zdd„ ZdS )z0Apk Configure: Configures apk repositories file.é    N)Ú
temp_utilsÚ	templaterÚutil)ÚCloud)ÚConfig)Ú
MetaSchema)ÚPER_INSTANCEz+https://alpine.global.ssl.fastly.net/alpinea  ## template:jinja
#
# Created by cloud-init
#
# This file is written on first boot of an instance
#

{{ alpine_baseurl }}/{{ alpine_version }}/main
{% if community_enabled -%}
{{ alpine_baseurl }}/{{ alpine_version }}/community
{% endif -%}
{% if testing_enabled -%}
{% if alpine_version != 'edge' %}
#
# Testing - using with non-Edge installation may cause problems!
#
{% endif %}
{{ alpine_baseurl }}/edge/testing
{% endif %}
{% if local_repo != '' %}

#
# Local repo
#
{{ local_repo }}/{{ alpine_version }}
{% endif %}

Úcc_apk_configureÚalpineÚ	apk_repos)ÚidÚdistrosÚ	frequencyÚactivate_by_schema_keysÚmetaÚnameÚcfgÚcloudÚargsÚreturnc                 C   s”   |  d¡}|st d| ¡ dS t |dd¡rt d| ¡ dS |  d¡}|s-t d| ¡ dS |  d	¡}|s<t d
| ¡ dS |  dd¡}t|||ƒ dS )a{  
    Call to handle apk_repos sections in cloud-config file.

    @param name: The module name "apk_configure" from cloud.cfg
    @param cfg: A nested dict containing the entire cloud config contents.
    @param cloud: The CloudInit object in use.
    @param log: Pre-initialized Python logger object to use for logging.
    @param _args: Any module arguments from cloud.cfg
    r   z6Skipping module named %s, no 'apk_repos' section foundNÚpreserve_repositoriesFz8Skipping module named %s, 'preserve_repositories' is setÚalpine_repoz>Skipping module named %s, no 'alpine_repo' configuration foundÚversionz@Skipping module named %s, 'version' not specified in alpine_repoÚlocal_repo_base_urlÚ )ÚgetÚLOGÚdebugr   Úget_cfg_option_boolÚ_write_repositories_file)r   r   r   r   Úapk_sectionr   Úalpine_versionÚ
local_repo© r#   úC/usr/lib/python3/dist-packages/cloudinit/config/cc_apk_configure.pyÚhandle>   s6   
ÿÿ
þ
þr%   c                 C   sx   d}|   dt¡}|||   d¡|   d¡|dœ}tjddd�}|d	 }tj|td
� t d|¡ t	 
|||¡ t |¡ dS )a  
    Write the /etc/apk/repositories file with the specified entries.

    @param alpine_repo: A nested dict of the alpine_repo configuration.
    @param alpine_version: A string of the Alpine version to use.
    @param local_repo: A string containing the base URL of a local repo.
    z/etc/apk/repositoriesÚbase_urlÚcommunity_enabledÚtesting_enabled)Úalpine_baseurlr!   r'   r(   r"   ztemplate_name-z.tmpl)ÚprefixÚsuffixé   )Úcontentz3Generating Alpine repository configuration file: %sN)r   ÚDEFAULT_MIRRORr   Úmkstempr   Ú
write_fileÚREPOSITORIES_TEMPLATEr   r   r   Úrender_to_fileÚdel_file)r   r!   r"   Ú	repo_filer)   ÚparamsÚtfileÚtemplate_fnr#   r#   r$   r   s   s   	ûr   )Ú__doc__ÚloggingÚ	cloudinitr   r   r   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   Úcloudinit.settingsr   Ú	getLoggerÚ__name__r   r.   r1   r   Ú__annotations__ÚstrÚlistr%   r   r#   r#   r#   r$   Ú<module>   s"   
ü5