o
    3'f                  
   @   s   U d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZ ddlmZ eeZd	gZd
ddedeedgedgdZeed< eeZ dZdedede	deddf
ddZdd ZdS )z;Autoinstall: Support ubuntu live-server autoinstall syntax.    N)dedent)subputil)Cloud)Config)
MetaSchemaSchemaProblemSchemaValidationErrorget_meta_doc)PER_ONCEubuntucc_ubuntu_autoinstallzUbuntu Autoinstallz)Support Ubuntu live-server install syntaxa&          Ubuntu's autoinstall YAML supports single-system automated installs
        in either the live-server install, via the ``subiquity`` snap, or the
        next generation desktop installer, via `ubuntu-desktop-install` snap.
        When "autoinstall" directives are provided in either
        ``#cloud-config`` user-data or ``/etc/cloud/cloud.cfg.d`` validate
        minimal autoinstall schema adherence and emit a warning if the
        live-installer is not present.

        The live-installer will use autoinstall directives to seed answers to
        configuration prompts during system install to allow for a
        "touchless" or non-interactive Ubuntu system install.

        For more details on Ubuntu's autoinstaller:
            https://ubuntu.com/server/docs/install/autoinstall
    a              # Tell the live-server installer to provide dhcp6 network config
            # and LVM on a disk matching the serial number prefix CT
            autoinstall:
              version: 1
              network:
                version: 2
                ethernets:
                  enp0s31f6:
                    dhcp6: yes
              storage:
                layout:
                  name: lvm
                  match:
                    serial: CT*
        autoinstall)idnametitledescriptiondistrosexamples	frequencyactivate_by_schema_keysmeta)	subiquityzubuntu-desktop-installerr   cfgcloudargsreturnc                 C   sz   d|vrt d|  d S tddg\}}d }tD ]
}t||r#|}q|s1t ddt d S t| t d| d S )Nr   z?Skipping module named %s, no 'autoinstall' key in configurationsnaplistzaSkipping autoinstall module. Expected one of the Ubuntu installer snap packages to be present: %sz, z8Valid autoinstall schema. Config will be processed by %s)	LOGdebugr   LIVE_INSTALLER_SNAPSresearchwarningjoinvalidate_config_schema)r   r   r   r   	snap_list_installer_present	snap_name r+   H/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_autoinstall.pyhandleM   s.   r-   c                 C   sz   | d }t |tsttddt|j gd|vr#ttddgt |dts;ttddt|d j gdS )a>  Supplemental runtime schema validation for autoinstall yaml.

    Schema validation issues currently result in a warning log currently which
    can be easily ignored because warnings do not bubble up to cloud-init
    status output.

    In the case of the live-installer, we want cloud-init to raise an error
    to set overall cloud-init status to 'error' so it is more discoverable
    in installer environments.

    # TODO(Drop this validation When cloud-init schema is strict and errors)

    :raise: SchemaValidationError if any known schema values are present.
    r   zExpected dict type but found: versionzMissing required 'version' keyzautoinstall.versionzExpected int type but found: N)
isinstancedictr	   r   type__name__getint)r   autoinstall_cfgr+   r+   r,   r&   i   s4   


r&   )__doc__loggingr"   textwrapr   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r   r	   r
   cloudinit.settingsr   	getLoggerr2   r   r   r   __annotations__r!   strr   r-   r&   r+   r+   r+   r,   <module>   s:   
/