U
    w7e                  	   @   s   U d Z ddlmZ ddlm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mZ ddlmZ eeZd	Zd
ZeZdgZdddedeedededgedgdZeed< eeZ eee
eddddZdd ZdS )z0Apk Configure: Configures apk repositories file.    )dedent)log)
temp_utils	templaterutil)Cloud)Config)
MetaSchemaget_meta_doc)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 %}

ZalpineZcc_apk_configurezAPK ConfigurezConfigure apk repositories filez        This module handles configuration of the /etc/apk/repositories file.

        .. note::
          To ensure that apk configuration is valid yaml, any strings
          containing special characters, especially ``:`` should be quoted.
    z        # Keep the existing /etc/apk/repositories file unaltered.
        apk_repos:
            preserve_repositories: true
        z        # Create repositories file for Alpine v3.12 main and community
        # using default mirror site.
        apk_repos:
            alpine_repo:
                community_enabled: true
                version: 'v3.12'
        a          # Create repositories file for Alpine Edge main, community, and
        # testing using a specified mirror site and also a local repo.
        apk_repos:
            alpine_repo:
                base_url: 'https://some-alpine-mirror/alpine'
                community_enabled: true
                testing_enabled: true
                version: 'edge'
            local_repo_base_url: 'https://my-local-server/local-alpine'
        	apk_repos)idnametitleZdescriptiondistrosZexamples	frequencyZactivate_by_schema_keysmetaN)r   cfgcloudargsreturnc                 C   s   | d}|std|  dS t|ddr<td|  dS | d}|sZtd|  dS | d	}|sxt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 foundNZ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_repoZlocal_repo_base_url )getLOGdebugr   Zget_cfg_option_bool_write_repositories_file)r   r   r   r   Zapk_sectionr   alpine_version
local_repo r    C/usr/lib/python3/dist-packages/cloudinit/config/cc_apk_configure.pyhandleo   s:    
  

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/repositoriesZbase_urlcommunity_enabledtesting_enabled)alpine_baseurlr   r#   r$   r   ztemplate_name-z.tmpl)prefixsuffix   )Zcontentz3Generating Alpine repository configuration file: %sN)r   DEFAULT_MIRRORr   Zmkstempr   Z
write_fileREPOSITORIES_TEMPLATEr   r   r   Zrender_to_fileZdel_file)r   r   r   Z	repo_filer%   ZparamsZtfileZtemplate_fnr    r    r!   r      s    	r   )__doc__textwrapr   Z	cloudinitr   Zloggingr   r   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar	   r
   Zcloudinit.settingsr   Z	getLogger__name__r   r)   r*   r   r   r   __annotations__strlistr"   r   r    r    r    r!   <module>   sF   
	
 25