%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/schema.cpython-312.pyc

�

���f�	��b�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZmZmZm Z m!Z!m"Z"m#Z#ddl$Z$ddl%m&Z&m'Z'm(Z(m)Z)dd
l*m+Z+ddl,m-Z-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:	ddl;m<Z<ej~e@�ZAdZBdZCdZDdZEdddd�ZFdZGdZHdZIdZJeKe-j��D�cgc]
}|dd k(s�|��c}�ZMerddlZdd!lNmOZOmPZPGd"�d#eP�ZQneRZQGd$�d%e<�ZSGd&�d'e�ZTeeTZUGd(�d)e�ZVeVj�d*eCieVj�d*eEieVj�d*eDieVj�d*eEiiZ[Gd+�d,e�Z\Gd-�d.e�Z]Gd/�d0e�Z^dd1d2�d3eUd4ee_d5e_d6e_fd7�Z`Gd8�d9ea�ZbGd:�d;eb�Zcd<�Zd	d�d>eRd6e_fd?�Zed6ee<fd@�ZfeSfdegdAeRdBe_dCe!e>fdD�Zheehd�E�ZieehdF�E�ZjeSfdCe!e>fdG�ZkeSfdCe!e>fdH�ZldI�Zmd�dAeRfdK�ZndLeRd6eeofdM�Zp			d�dLeRdNegdOegdPegd6egf
dQ�ZqdeVj�d=d=dJd=fd>eRdAeeRdReVdNegdSegdPegdTegd6egfdU�ZrGdV�dW�ZsdddX�dYeRdZe_d[eRd\eeUd]eeUd6e"e_etffd^�Zud_e_d6eeTfd`�Zv	d�dae_d_e_dbee_d6e^fdc�ZweVj�d=dfdae_dAeRdReVdOegdbee_d6egfdd�Zxde�Zydf�ZzdgeRdhe_d6ee_fdi�Z{dgeRdjeRd6e_fdk�Z|d6e_fdl�Z}dmeRdjeRfdn�Z~dmeRfdo�ZdpeRd6e_fdq�Z�d�dAeRdjeRd6e_fdr�Z�dseQd6e_fdt�Z�dseQd6e_fdu�Z�d�dseQdAeeRd6e_fdv�Z�d6eRfdw�Z�dxe�d6e_fdy�Z�d6e_fdz�Z�d6eRfd{�Z�eVj�fdReVd6eRfd|�Z�d�d}�Z�d~�Z�d6e e_ee]ffd�Z�d��Z�d��Z�e@d�k(re�j e���yy#e=$re>Z<Y���wxYwcc}w)�zFschema.py: Set of module functions for processing cloud-config schema.�N)�defaultdict)�Iterable)�suppress)�deepcopy)�Enum)�EACCES)�partial)�chain)	�
TYPE_CHECKING�DefaultDict�List�
NamedTuple�Optional�Tuple�Type�Union�cast)�features�importer�	lifecycle�safeyaml)�read_cfg_paths)�INCLUSION_TYPES_MAP�type_from_starts_with)�Paths)�DataSourceNotFoundException)�mkdtemp)�error�get_modules_from_dir�load_text_file�	load_yaml�
write_file)�ValidationErrorz!versions.schema.cloud-config.jsonzschema-cloud-config-v1.jsonzschema-network-config-v1.jsonzschema-network-config-v2.json�true�false�null)TFNap
{name}
{title_underbar}

{title}

.. tab-set::

{prefix3}.. tab-item:: Summary

{description}

{prefix6}**Internal name:** ``{id}``

{prefix6}**Module frequency:** {frequency}

{prefix6}**Supported distros:** {distros}

{prefix6}{activate_by_schema_keys}

{prefix3}.. tab-item:: Config schema

{property_doc}

{prefix3}.. tab-item:: Examples

{prefix6}::

{examples}
z5{prefix}* **{prop_name}:** ({prop_type}){description}zJ{prefix}* Each object in **{prop_name}** list supports the following keys:�
deprecated�#)�NotRequired�	TypedDictc��eZdZUeed<eed<eed<eed<ejeed<ejeeefed<eed<e	eeed<y	)
�
MetaSchema�id�name�title�description�distros�examples�	frequency�activate_by_schema_keysN)
�__name__�
__module__�__qualname__�str�__annotations__�typingr
r�dictr)���9/usr/lib/python3/dist-packages/cloudinit/config/schema.pyr,r,ysR�����	��
������S�!�!��+�+�e�D�#�I�.�/�/���!,�T�#�Y�!7�7r=r,c�(��eZdZdedef�fd�Z�xZS)�SchemaDeprecationError�message�versionc�4��t�|�|fi|��||_y�N)�super�__init__rB)�selfrArB�kwargs�	__class__s    �r>rFzSchemaDeprecationError.__init__�s���	����+�F�+�#��r=)r5r6r7r8rF�
__classcell__�rIs@r>r@r@�s���$��$��$�$r=r@c�.�eZdZUeed<eed<defd�Zy)�
SchemaProblem�pathrA�returnc�8�|j�d|j��S)N�: )rNrA�rGs r>�formatzSchemaProblem.format�s���)�)��B�t�|�|�n�-�-r=N)r5r6r7r8r9rSr<r=r>rMrM�s��

�I�
�L�.��.r=rMc� �eZdZdZdZdZdZdZy)�
SchemaTypeaSupported schema types are either cloud-config or network-config.

    Vendordata and Vendordata2 format adheres to cloud-config schema type.
    Cloud Metadata is unique schema to each cloud platform and likely will not
    be represented in this enum.
    zcloud-config�network-configznetwork-config-v1znetwork-config-v2N)r5r6r7�__doc__�CLOUD_CONFIG�NETWORK_CONFIG�NETWORK_CONFIG_V1�NETWORK_CONFIG_V2r<r=r>rUrU�s���"�L�%�N�+��+�r=rU�latestc�&�eZdZdZdZdZdZdZd�Zy)�InstanceDataTypez-Types of instance data provided to cloud-initz	user-datarVzvendor-datazvendor2-datac��|jSrD��valuerRs r>�__str__zInstanceDataType.__str__�s���z�z�r=N)	r5r6r7rW�USERDATArY�
VENDORDATA�VENDOR2DATArbr<r=r>r^r^�s��7��H�%�N��J� �K�r=r^c�,�eZdZUeed<eed<eed<y)�InstanceDataPart�config_type�schema_type�config_pathN)r5r6r7r^r9rUr8r<r=r>rgrg�s��!�!����r=rgc�"�eZdZUeed<eed<y)�UserDataTypeAndDecodedContent�
userdata_type�contentN)r5r6r7r8r9r<r=r>rlrl�s
����
�Lr=rl�, ��prefix�	separator�schema_problemsrqrrrOc�N�|jtd�|��}|r|�|��}|S)Nc�"�|j�SrD)rS)�ps r>�<lambda>z)_format_schema_problems.<locals>.<lambda>�s��Q�X�X�Z�r=)�join�map)rsrqrr�	formatteds    r>�_format_schema_problemsr{�s1�����s�#7��I�J�I�
��h�y�k�*�	��r=c�J��eZdZdZ		ddeedeef�fd�
Zdefd�Z�xZ	S)�SchemaValidationErrorz<Raised when validating a cloud-config file against a schema.�
schema_errors�schema_deprecationsc�p���d��fd�}||d��|_||d��|_t�|�
��y)z�Init the exception an n-tuple of schema errors.

        @param schema_errors: An n-tuple of the format:
            ((flat.config.key, msg),)
        @param schema_deprecations: An n-tuple of the format:
            ((flat.config.key, msg),)
        �c�x��|s|S�r�dz
�ttt|���}�t||��z
�|S)N�

�rq)�sorted�list�setr{)�problemsrqrAs  �r>�handle_problemsz7SchemaValidationError.__init__.<locals>.handle_problems�sB��������6�!���d�3�x�=�1�2�H��.�x��G�G�G��Or=zCloud config schema errors: r��"Cloud config schema deprecations: N)r~rrErF)rGr~rr�rArIs    @�r>rFzSchemaValidationError.__init__�sH�����	�-��1�
���$3��7�$
�� �	����!r=rOc�,�t|j�SrD)�boolr~rRs r>�
has_errorsz SchemaValidationError.has_errorss���D�&�&�'�'r=)NN)
r5r6r7rWr�SchemaProblemsrFr�r�rJrKs@r>r}r}�s<���F�37�8<� "���/� "�&�n�5� "�D(�D�(r=r}c��eZdZdZy)�"SchemaValidationInvalidHeaderErrorz>Raised when no valid header is declared in the user-data file.N)r5r6r7rWr<r=r>r�r�
s��Hr=r�c��	ddlm}|jj	|d�xst|tf�S#t$rYywxYw)zWTYPE_CHECKER override allowing bytes for string type

    For jsonschema v. 3.0.0+
    r)�Draft4ValidatorF�string)�
jsonschemar��ImportError�TYPE_CHECKER�is_type�
isinstance�bytes)�checker�instancer�s   r>�is_schema_byte_stringr�sO��
�.��'�'�/�/��(��(�	�H�u�h�	'�(������s�7�	A�AF�configc����dtf��fd�}|r|ngd�}djt||��}�jdd�}|�|��j	�S)z�combine description with new/changed/deprecated message

    deprecated/changed/new keys require a _version key (this is verified
    in a unittest), a _description key is optional
    �keyc�����j|��sy�j|�d�d�}�j|�d�d|�d��}|j��d|�d|��}�rd|��Sd	|j��d
�S)Nr��_description�_versionz	<missing z'_version key, please file a bug report>z in version �. � z

*�*)�get�
capitalize�strip)r��key_description�v�msg�annotater�s    ��r>�format_messagez:_add_deprecated_changed_or_new_msg.<locals>.format_message%s�����z�z�S�E�#�� �*�*��u�L�%9�2�>���J�J��e�8����u�C�D�
�����!�"�,�q�c��O�3D�E����s�e�9���s�y�y�{�m�1�%�%r=)r'�changed�newr�r0)r8rxryr��rstrip)r�r��
filter_keyr��filter_keys�changed_new_deprecatedr0s``     r>�"_add_deprecated_changed_or_new_msgr�s`���
&�C�
&�"!�
�&F��
 �W�W�S���%E�F���*�*�]�B�/�K��]�1�2�3�:�:�<�<r=c�X�g}d}t|t�xrd|v}|D�]	}|r�|d|jjdi�jdi�jdg�vr|gcSt	|d�r%|j
dddk(s�k|j
|��}|js��|jddk(s��|j
|���t|j�|k(r|j
|���t|j�|kDs��t|j�}|g}��|S)z�Return the best_match errors based on the deepest match in the json_path

    This is useful for anyOf and oneOf subschemas where the most-specific error
    tends to be the most appropriate.
    r�type�
properties�enum�	json_path���N)	r�r;�schemar��hasattrr��appendrN�len)�errorsr��best_matches�
path_depthr��errs      r>�cloud_init_deepest_matchesr�?s���L��J���4�(�?�V�x�-?�G��!������3�:�:�>�>�,��#C�#G�#G���$��c�&�"�o���u���s�K�(��=�=���%��/� �'�'��,����c�h�h�q�k�V�3��#�#�C�(�
����]�j�
(�����$�
����]�Z�
'��S�X�X��J��5�L�)!�*�r=r�r��
error_typec#�fK�|r+t|d|g��}|||jdd����yy�w)z�Jsonschema validator for `deprecated` items.

    It yields an instance of `error_type` if deprecated that must be handled,
    otherwise the instance is consider faulty.
    T)r�r��deprecated_version�develN)r�r�)�
_validatorr'�	_instancer�r�r�r�s       r>r�r�`s>�����0��T�z�l�
����f�j�j�)=�w�G�H�H�	�s�/1)r�r�c#��K�ddlm}g}g}d}t|�D]�\}	}
t|j	||
|	���}tt�fd�|��}tt�fd�|��}
|s|j
|
�nrt|t�r1d|vr-d|
jd	d
�vrd|d��|
d	vrd}|Ed
{���|j
|���|s
||���t|�d�|����|Ed
{���y
7�@7��w)a�Jsonschema validator for `anyOf`.

    It treats occurrences of `error_type` as non-errors, but yield them for
    external processing. Useful to process schema annotations, as `deprecated`.

    Cloud-init's network schema under the `config` key has a complexity of
    allowing each list dict item to declare it's type with a `type` key which
    can contain the values: bond, bridge, nameserver, physical, route, vlan.

    This schema 'flexibility' makes it hard for the default
    jsonschema.exceptions.best_match function to find the correct schema
    failure because it typically returns the failing schema error based on
    the schema of greatest match depth. Since each anyOf dict matches the
    same depth into the network schema path, `best_match` just returns the
    first set of schema errors, which is almost always incorrect.

    To find a better schema match when encountering schema validation errors,
    cloud-init network schema introduced schema $defs with the prefix
    `anyOf_type_`. If the object we are validating contains a 'type' key, and
    one of the failing schema objects in an anyOf clause has a name of the
    format anyOf_type_XXX, raise those schema errors instead of calling
    best_match.
    r)�
best_matchF��schema_pathc���t|��SrD�r���er�s �r>rwz_anyOf.<locals>.<lambda>������A�z�)B�%B�r=c���t|��SrDr�r�s �r>rwz_anyOf.<locals>.<lambda>�����Z��:�6�r=r��
anyOf_type�$refr��anyOf_type_TNz, is not valid under any of the given schemas)�context)�jsonschema.exceptionsr��	enumerater��descend�filter�extendr�r;r�r#)�	validator�anyOfr��_schemar�r��
all_errors�all_deprecations�skip_best_match�index�	subschema�all_errs�errs�deprecationss    `         r>�_anyOfr�xs*�����<1��J����O�%�e�,�
���y�����h�	�u��E�
���F�B�H�M�N����6��A�
����#�#�L�1���x��&��(�"��	�
�
�f�b� 9�9��X�f�-�.�/�9�V�3D�D�#'��������$��+
�.��Z�(�(��@H�J��
�	
� ��� �� �s$�B<D�?D�:D�:D�;D�Dc#�D�K�t|�}g}g}|D]z\}}	t|j||	|���}
tt�fd�|
��}tt�fd�|
��}|s|	}
|j	|�n'|j	|��|t||�Ed{���|D��cgc]\}}|j
||�s�|��}}}|r<|j
�djd�|D��}t|�d|�����y|Ed{���y7�tcc}}w7�
�w)z�Jsonschema validator for `oneOf`.

    It treats occurrences of `error_type` as non-errors, but yield them for
    external processing. Useful to process schema annotations, as `deprecated`.
    r�c���t|��SrDr�r�s �r>rwz_oneOf.<locals>.<lambda>�r�r=c���t|��SrDr�r�s �r>rwz_oneOf.<locals>.<lambda>�r�r=Nroc3�2K�|]}t|����y�wrD)�repr)�.0r�s  r>�	<genexpr>z_oneOf.<locals>.<genexpr>�s����@�6�$�v�,�@���z is valid under each of )
r�r�r�r�r�r��is_validr�rxr#)r��oneOfr�r�r��
subschemasr�r�r�r�r�r�r��first_valid�i�s�
more_valid�reprss    `             r>�_oneOfr��s0������5�!�J��J���&�D���y�����h�	�u��E�
���F�B�H�M�N����6��A�
���#�K��#�#�L�1�����$��D�.�j�(�C�C�C� *�N���1�i�.@�.@��1�.M�!�N�J�N�����+�&��	�	�@�Z�@�@���.6��>�
�	
�$�#�#�	D��N�	$�s7�BD �!D�"	D �+D�D�
AD �D�D �D c��ddlm}m}ddlm}t|j�}ddi|dd<i}t|d�r*d	|d
<|jjdt�}d|i}n|j}ttf|d<d|i}t|j�}t |t"<t$|d
<t&|d<t(|d<|d||dd�|��}dd�}	|	|_||fS)z�Get metaschema validator and format checker

    Older versions of jsonschema require some compatibility changes.

    @returns: Tuple: (jsonschema.Validator, FormatChecker)
    @raises: ImportError when jsonschema is not present
    r)r��
FormatChecker)�creater�r�r��labelr�F�additionalProperties�type_checker�
default_typesr�r�r��draft4)�meta_schema�
validatorsrBc�X�td�|j||��}t|d�duS)zgOverride version of `is_valid`.

        It does ignore instances of `SchemaDeprecationError`.
        c�$�t|t�SrD)r�r@�r�s r>rwz<get_jsonschema_validator.<locals>.is_valid.<locals>.<lambda>%s��*��)���r=N)r��iter_errors�next)rGr�r��__r�s     r>r�z*get_jsonschema_validator.<locals>.is_valids9��
�
�
���X�w�/�	
���F�D�!�T�)�)r=r<rD)r�r�r��jsonschema.validatorsr�r�META_SCHEMAr�r��redefiner��
DEFAULT_TYPESr8r�r;�
VALIDATORS�_validator_deprecated�DEPRECATED_KEY�_validator_changedr�r�r�)
r�r�r�r�validator_kwargsr�typesr�cloudinitValidatorr�s
          r>�get_jsonschema_validatorr�s��:�,��?�6�6�7�K�+1�(�);�K���g�&������/�.3��*�+�&�3�3�<�<��+�
��
�L�
��
 �-�-����,��h��+�U�3���o�0�0�1�J�!6�J�~��.�J�y�� �J�w�� �J�w���������	��*�#+����
�.�.r=Tc
�8�ddlm}	|j|�y#|$rz}|rXtt	dj|jD�cgc]
}t|���ncc}wc}�|j�g��|�tjd|�Yd}~yd}~wwxYw)a Validate provided schema meets the metaschema definition. Return strict
    Validator and FormatChecker for use in validation
    @param validator: Draft4Validator instance used to validate the schema
    @param schema: schema to validate
    @param throw: Sometimes the validator and checker are required, even if
        the schema is invalid. Toggle for whether to raise
        SchemaValidationError or log warnings.

    @raises: ImportError when jsonschema is not present
    @raises: SchemaValidationError when the schema is invalid
    r)�SchemaError�.�r~zGMeta-schema validation failed, attempting to validate config anyway: %sN)r�r�check_schemar}rMrxrNr8rA�LOG�warning)r�r��throwrr�rvs      r>�validate_cloudconfig_metaschemar1s���2�
����v�&���
��'�!����#�(�(�!;�Q�#�a�&�!;��!;�<�c�k�k�����

�	���
��	
�	
��
�s ��B�%B�A�9B�B�network_configc�T�d|vr|djd�S|jd�S)z6Return the version of the network schema when present.�networkrB)r�)r s r>�network_schema_versionr#Ts1���N�"��i�(�,�,�Y�7�7����i�(�(r=�strictr��log_detailsc	��	ddlm}m}t
�}tjj|d�}t|�}d|vrd|i}tj|�}	t||	d��|�}
g}	|
j|�tjj+|�rt-j.|�|r�|r=|r0tj0|	�\}
}t3t5||	||�
��t7|��|r*t9|t:j<j>�d�d��}nt:j<j>�d�}tjA|�y#t$rtjd�YywxYw#|$rX}|jt!d	j#|j$|j&�
�d|j(����Yd}~��Pd}~wwxYw)ajOn systems with netplan, validate network_config schema for file

    Leverage NetplanParser for error annotation line, column and detailed
    errors.

    @param network_config: Dict of network configuration settings validated
        against
    @param strict: Boolean, when True raise SchemaValidationErrors instead of
       logging warnings.
    @param annotate: Boolean, when True, print original network_config_file
        content with error annotations
    @param log_details: Boolean, when True logs details of validation errors.
       If there are concerns about logging sensitive userdata, this should
       be set to False.

    @return: True when schema validation was performed. False when not on a
        system with netplan and netplan python support.
    @raises: SchemaValidationError when netplan's parser raises
        NetplanParserExceptions.
    r)�NetplanParserException�Parserz<Skipping netplan schema validation. No netplan API availableFzetc/netplan/network-config.yamlr"i�)�mode�format-l{line}.c{col}��line�colzInvalid netplan schema. Nr� failed schema validation!
�
rp�^ failed schema validation! You may run 'sudo cloud-init schema --system' to check the details.T)!�netplanr'r(r�r�debugr�osrNrxrr�dumpsr"�load_yaml_hierarchyr�rMrSr,�columnrA�exists�shutil�rmtree�load_with_marks�print�annotated_cloudconfig_filer}r{rUrYrar)r r$r�r%r'r(�	parse_dir�netplan_file�net_cfg�src_content�parserr�r��_�marksrAs                r>�netplan_validate_network_schemarD[s���4�:��	�I��7�7�<�<�	�+L�M�L��~�&�G�����g�&���.�.��)�K��|�[�u�5�
�X�F�
�F�

�	�"�"�9�-�
�w�w�~�~�i� ��
�
�i� �
���#�3�3�K�@���5��.��#��&,�	��(��/�/��-��!�0�0�6�6�7�8+�+��
�G��,�,�2�2�3�4%�%�
�
	���G����E���	�	�J�	
��	��6"�
��
�
��'�.�.�A�F�F����.�I�*�1�9�9�+�6�
�	
�	
��
�s*�E�4E=�E:�9E:�=G�A
G�Gri�strict_metaschema�log_deprecationsc	���ddlm}|tjk(rAt	|�}|dk(rtj
}n|dk(rtj}t|�}|tj
k(rt|||��ry|�ry|�t|�}	t�\}	}
|rt|	|d��|	||
��
�}g}g}
g}t|j|�d���D�];}d
j!|j"D�cgc]
}t%|���c}�}|sE|j&dk(r6|j(|k(r't+j,d|j.�}|r|d}t1|t2�r�|j4dk(s.t7j8|j4t:j<�r&|
j?tA||j.����|j?tA||j.����|j?tA||j.����>|rH|r"tC|d��}tjE|�|
r"tC|
d��}tjG|�|r|s|
s|rtI||
|z��|rB|rtC||jJ�d�d��}n|jJ�d�}tjM|�y#t$rtjd	�YywxYwcc}w)aPValidate provided config meets the schema definition.

    @param config: Dict of cloud configuration settings validated against
        schema. Ignored if strict_metaschema=True
    @param schema: jsonschema dict describing the supported schema definition
       for the cloud config module (config.cc_*). If None, validate against
       global schema.
    @param schema_type: Optional SchemaType.
       One of: SchemaType.CLOUD_CONFIG or SchemaType.NETWORK_CONFIG_V1 or
            SchemaType.NETWORK_CONFIG_V2
       Default: SchemaType.CLOUD_CONFIG
    @param strict: Boolean, when True raise SchemaValidationErrors instead of
       logging warnings.
    @param strict_metaschema: Boolean, when True validates schema using strict
       metaschema definition at runtime (currently unused)
    @param log_details: Boolean, when True logs details of validation errors.
       If there are concerns about logging sensitive userdata, this should
       be set to False.
    @param log_deprecations: Controls whether to log deprecations or not.

    @raises: SchemaValidationError when provided config does not validate
        against the provided schema.
    @raises: RuntimeError when provided config sourced from YAML is not a dict.
    @raises: ValueError on invalid schema_type not in CLOUD_CONFIG or
        NETWORK_CONFIG_V1 or NETWORK_CONFIG_V2
    r��	available��)r r$r%TF)rz5Ignoring schema validation. jsonschema is not present)�format_checkerc��|jSrD)rNrs r>rwz-validate_cloudconfig_schema.<locals>.<lambda>
s
��Q�V�V�r=�r�rr�z#.*\('(?P<name>.*)' was unexpected\)r.r�z"Deprecated cloud-config provided: r�r.r/rpr0)'�cloudinit.net.netplanrIrUrYr#r[rZ�
get_schemarDrrr�rr2r�rrxrNr8r�r��re�matchrAr�r@rBr�should_log_deprecationr�DEPRECATION_INFO_BOUNDARYr�rMr{�infor'r}rar)r�r�rir$rEr%rF�netplan_available�network_versionrr�r�r�r��info_deprecations�schema_errorrvrN�
prop_matchrA�detailss                     r>�validate_cloudconfig_schemar\�s���FE��j�/�/�/�0��8���a��$�6�6�K�
��
!�$�6�6�K��K�(���j�2�2�2�*�!�&�k�
��
�
 ��
�~��K�(���.F�.H�+�	�]��+�"�F�%�
�#�6�-�/�J�I��F�#%�L�(*������f�%�+;��E���x�x��):�):�;�A��Q��;�<����&�&�*@�@��#�#�v�-����6��8L�8L��J��!�&�)����0�
��$�$��/��3�3� �(�(�(�*L�*L���#�#�M�$��8L�8L�$M�N�!�(�(�!�$��(<�(<�=��
�M�M�-��l�.B�.B�C�D�=E�@��-�!�;��G�
�H�H�W���-��;��G�
�N�N�7�#�
�6�\�->�#�F�L�;L�,L�M�M�
��-��%�+�+�,�,H�I���G��$�$�%�&%�%�
�
	���G����Q���	�	�I�J����<s�K�?K+
�K(�'K(c���eZdZdededefd�Zededeedefd��Zd	e	fd
�Z
e	ddeedeed
eedededefd��Zdeedededeefd�Z
de	de	defd�Zy)�
_Annotator�cloudconfig�original_content�schemamarksc�.�||_||_||_yrD)�_cloudconfig�_original_content�_schemamarks)rGr_r`ras    r>rFz_Annotator.__init__Ls��(���!1���'��r=r/rnrOc�6�dj|�}d|�d|�d�S)Nr/�# z: -------------
r�)rx)r/rn�bodys   r>�
_build_footerz_Annotator._build_footerVs&���y�y��!���E�7�+�D�6��6�6r=rsc�>�tt�}|D]�\}}tjd|�}|r1|j	�\}}|t|�j
|�n#d}||j|j
|�|��udj||��}��|S)Nz&format-l(?P<line>\d+)\.c(?P<col>\d+).*zLine {line} column {col}: {msg})r,r-r�)	rr�rQrR�groups�intr�rerS)rGrs�errors_by_linerNr�rRr,r-s        r>�_build_errors_by_linez _Annotator._build_errors_by_line[s���=H��=N��(�	�I�D�#��H�H�F��M�E��!�L�L�N�	��c��s�4�y�)�0�0��5����t�0�0��6�7�>�>�s�C���7�>�>��3�C�?���	��r=r��labels�footerr��label_prefixc�z�|D]5}|�|��}|j|�|jd|�d|���|dz
}�7|S)NrgrQrK)r�)r�rorpr�rq�problemr�s       r>�
_add_problemsz_Annotator._add_problemsksV�� �	�G�#�n�U�G�,�E��M�M�%� ��M�M�B�u�g�R��y�1�2��Q�J�E�		�
�r=�linesrm�deprecations_by_linec���g}g}g}d}d}t|d�D]y\}	}
||	}||	}|s|rUg}
�j||
||d��}�j||
||d��}|j|
dzdj|
�z��i|j|
��{|j	t�fd�t
d�d	|fd
|ff���|S)NrK�E)rq�Dz		# �,c�"���j|�SrD)ri)�seqrGs �r>rwz._Annotator._annotate_content.<locals>.<lambda>�s���.�D�.�.��4�r=c��t|d�S)NrK)r�)r|s r>rwz._Annotator._annotate_content.<locals>.<lambda>�s���S��V��r=�Errors�Deprecations)r�rtr�rxr�ryr�)rGrurmrv�annotated_content�error_footer�deprecation_footer�error_index�deprecation_index�line_numberr,r�r�ros`             r>�_annotate_contentz_Annotator._annotate_contentzs�����"$��(*������!*�5�!�!4�	/��K��#�K�0�F�/��<�L���$&��"�0�0��F�L�+�C�1���%)�$6�$6� ��&�%�!$�%7�%�!�"�(�(����3�8�8�F�;K�)K�L�!�(�(��.�#	/�&	� � ��4��,�!�<�0�'�);�<���	
�	
�!� r=r~rc���|s|s|jS|jjd�}|j|�}|j|�}|j|||�}dj	|�S)Nr/)rd�splitrnr�rx)rGr~rrurmrvr�s       r>r�z_Annotator.annotate�sy��
�%8��)�)�)��&�&�,�,�T�2���3�3�M�B��#�9�9�:M�N�� �2�2��>�#7�
���y�y�*�+�+r=N)r�)r5r6r7r;r8rF�staticmethodr
rir�rnrlrtr�r�r<r=r>r^r^Ks��(��(��(��	(��7�S�7�4��9�7��7��7��^�� ����s�)���S�	���S�	���	�
��

�
���*!��C�y�*!��*!�#�	*!�

�c��*!�X
,�%�
,�,�
,�

�	
,r=r^�r~rr_r`rar~rc�L�t|||�j|xsg|xsg�S)a�Return contents of the cloud-config file annotated with schema errors.

    @param cloudconfig: YAML-loaded dict from the original_content or empty
        dict if unparsable.
    @param original_content: The contents of a cloud-config file
    @param schemamarks: Dict with schema marks.
    @param schema_errors: Instance of `SchemaProblems`.
    @param schema_deprecations: Instance of `SchemaProblems`.

    @return Annotated schema
    )r^r�)r_r`rar~rs     r>r<r<�s1��&�k�#3�[�A�J�J����0�6�B��r=rnc
���ddlm}||vrgSg}t|j�d�D]F\}}|j	|�s�|jt
d|�d�|j|d����H|S)a�Annotate and return schema validation errors in merged cloud-config.txt

    When merging multiple cloud-config parts cloud-init logs an error and
    ignores any user-data parts which are declared as #cloud-config but
    cannot be processed. the handler.cloud_config module also leaves comments
    in the final merged config for every invalid part file which begin with
    MERGED_CONFIG_SCHEMA_ERROR_PREFIX to aid in triage.
    r)�MERGED_PART_SCHEMA_ERROR_PREFIXrKzformat-lz.c1zIgnored invalid user-data: )�cloudinit.handlers.cloud_configr�r��
splitlines�
startswithr�rM�replace)rnr�r��line_numr,s     r>�)process_merged_cloud_config_part_problemsr��s���P�&�g�5��	�"$�F�#�G�$6�$6�$8�!�<�
���$��?�?�:�;��M�M���x�j��,��L�L�7�5���
�
��Mr=rj�instance_data_pathc
��ddlm}m}m}m}t|�}d}|dk(r	||||�}d
}t|�}|sG|jd�\}
}}tt|d|�d
|
�ddjt����g��|dk7rtd|�d��t||�S#|$r}	t
t|d�g�|	�d}	~	w|$r#}	tdt|	�zd�	�Yd}	~	��d}	~	w|$r }	tt|	�d�	�Yd}	~	��d}	~	wwxYw)a�
    Return tuple of user-data-type and rendered content.

    When encountering jinja user-data, render said content.

    :return: UserDataTypeAndDecodedContent
    :raises: SchemaValidationError when non-jinja content found but
        header declared ## template: jinja.
    :raises JinjaSyntaxParsingException when jinja syntax error found.
    :raises JinjaLoadError when jinja template fails to load.
    r)�JinjaLoadError�JinjaSyntaxParsingException�
NotJinjaError�render_jinja_payload_from_filezformat-l1.c1ztext/jinja2zRDetected type '{user_data_type}' from header. But, content is not a jinja templateNz&Failed to render templated user-data. T��sys_exitzformat-l2.c1r/z!Unrecognized user-data header in z: "z%".
Expected first line to be one of: ro�text/cloud-configzUser-data type 'z.' not currently evaluated by cloud-init schema)�!cloudinit.handlers.jinja_templater�r�r�r�rr}rMrr8�	partitionr�rx�USERDATA_VALID_HEADERSr;rl)rjrnr�r�r�r�r��user_data_type�schema_positionr��header_linerBs            r>�&_get_config_type_and_rendered_userdatar��sb�� ��+�7�3�N�$�O���&�	)�4���&8��G�()��.�w�7���#�-�-�d�3���Q��0��#�7��}�E�$�
�&&�&*�i�i�0F�&G�%H�J��
�	
�		
�
�.�	.�
��~�.�/$�
$�	
�)���A�A��I�		�'�!�'�?�����
��+�	��8�3�q�6�A��
�
���	)��#�a�&�4�(�(��	)�s/�
B � D
�%B<�<D
�C"�"D
�*D�D
c��ddlm}t|�}|std|j�d|�d��y|t
jfvrt|j|�}n
t|||�}|jdvry|j}t|�}		|rtj|�\}
}ntj|�}
i}t9|
t:�s|st=|j�d|�d���|t
jk(r�|
j?d|
�std�ytA|
�}|dk(r2t
jB}tE|
d|��ry|�r,td�y|dk(rt
jF}tI|�}	tK|
||dd��std|j�d��y	y#tj $r�}dx}
}d	}t#|d
�rt%|d
�r
t%|d
�}n$t#|d�rt%|d�rt%|d�}|r|j&dz}
|j(dz}|	j+t-dj/|
|�
�dj/|t1|����t3|	�}|r"tt5i|i|j6���||�d	}~wwxYw#t2$r�}|jM�r|	|j6z
}	|r$tt5|
|||	|jN���n/|jNr#tQ|jNdd��}t|�|	r
t3|	��|�Yd	}~yd	}~wwxYw)a�Validate cloudconfig file adheres to a specific jsonschema.

    @param config_path: Path to the yaml cloud-config file to parse, or None
        to default to system userdata from Paths object.
    @param schema: Dict describing a valid jsonschema to validate against.
    @param schema_type: One of SchemaType.NETWORK_CONFIG or CLOUD_CONFIG
    @param annotate: Boolean set True to print original config file with error
        annotations on the offending lines.
    @param instance_data_path: Path to instance_data JSON, used for text/jinja
        rendering.

    :return: True when validation was performed successfully
    :raises SchemaValidationError containing any of schema_errors encountered.
    :raises RuntimeError when config_path does not exist.
    rrHzEmpty 'z' found at z. Nothing to validate.F)rVr�rKN�context_mark�problem_markr*r+zFile {0} is not valid YAML. {1}rr�z is not a YAML dict.r"z:Skipping network-config schema validation on empty config.rJT)r r$r�zSSkipping network-config schema validation for version: 2. No netplan API available.)r�rir$rFz	Skipping z2 schema validation. Jsonschema dependency missing.r�r�rorp))rOrIr r;rarUrYrlr�rmrnr�rr:�yaml�	safe_load�	YAMLErrorr��getattrr,r6r�rMrSr8r}r<r~r�r;�RuntimeErrorr�r#r[rDrZrPr\r�rr{)rjr�rir�r�rV�decoded_content�decoded_configrnr�r_rCr�r,r6�markrYrWrAs                   r>�validate_cloudconfig_filer�1sk��,E�$�[�1�O��
�� � �+�
/�	
���z�0�0�2�2�6�����
��@���*<�
���#�#�,����$�$�G�
6�w�
?�F�"��!)�!9�!9�'�!B��K���.�.��1�K��E�2�k�4�(����$�$�%�Q�{�m�3G�H��
��j�/�/�/����y�+�6��N�O��0��=���a��$�6�6�K�.�*�4�(���"�$��1���
��
!�$�6�6�K���,�F�"E�*���#��"�
�
��K�-�-�.�/2�2�
��
�D��m�>�>�"����v����1�n�%�'�!�^�*D��1�n�-�D�
�Q��
'�G�A�~�,F��1�n�-�D���9�9�q�=�D��[�[�1�_�F��
�
��'�.�.�D�f�.�E�1�8�8��c�!�f�M�
�	
�-�V�4����*����<�3M�3M��
�
��!��/"��@!�E��<�<�>��a�o�o�%�F���*����"(�()�(=�(=��
��
"�
"�-��%�%�;���G�

�'�N��'�f�=�1�D����-E�s2�2F.�)J/�.J,�C&J'�'J,�/	M�8BM�Mc��|dk(ry|dk(ryy)z�Provide a sorting weight for documentation of property types.

    Weight values ensure 'array' sorted after 'object' which is sorted
    after anything else which remains unsorted.
    �arrayrJ�objectrKrr<r`s r>�_sort_property_orderr��s��
����	�(�	��r=c#�K�|D]@}t|t�r*t|ttf�st	|�Ed{����=|���By7��wrD)r�rr8r��_flatten)�xs�xs  r>r�r��sA����
����a��"�:�a�#�u��+F���{�"�"��G�	�"�s�:A�A	�
A�
property_dict�	multi_keyc��g}|j|i�D]�}|jt�r�|jd�rH|j|jdg�D�cgc]}dtj||��d���c}��r|jd�s��|j	|d���tt
|��Scc}w)Nr��``r�)r�rr��	_YAML_MAPr�r�r�)r�r��property_typesr��
enum_values     r>�_collect_subschema_typesr��s����N�"�&�&�y�"�5�5�	��=�=��(���=�=�� ��!�!�'0�m�m�F�B�&?��"�����z�:�>�?�r�B��
��]�]�6�
"��!�!�)�F�"3�4�5����(�)�)��s�!C
�defsc���t||�|jdg�}t|t�s|g}|jd�r+|dD�cgc]}dtj||��d���}}nY|jd�r|jt
|d��n,|jd�r|jt
|d��t|�dk(r|d}n'|jt��d	j|�}|jd
i�}|jdg�}t|t�s|g}t|�}t|jdi�|jdi��D]'}t||�}	|r|	dk(r�|j|	��)|rJt|�dk(r
|�d|d��S|jt��d
d	j|��d�}
|�d|
��S|xsdScc}w)zNReturn a string representing a property type from a given
    jsonschema.
    r�r�r�r�r�rKrrN�/�items�	UNDEFINEDz of �(�))�flatten_schema_refsr�r�r�r�r�r�r��sortr�rxr�r
�_get_property_typer�)r�r�r��k�
property_typer��sub_property_types�prune_undefined�sub_item�sub_type�sub_property_docs           r>r�r��s���
�t�,�"�&�&�v�r�2�N��n�d�+�(�)������ �2?��2G�
�-.�b����q�!�$�%�R�(�
��
�
�	�	�7�	#����6�}�g�N�O�	�	�	�7�	#����6�}�g�N�O�
�>��a��&�q�)�
���� 4��5�����0�
����g�r�*�E����6�2�.���(�$�/�0�1���-�.�O��%�)�)�G�R�0�%�)�)�G�R�2H�I�,��%�h��5���x�;�6�
��!�!�(�+�
,���!�"�a�'�#�_�D�);�A�)>�(?�@�@����$8��9��s�x�x�(:�;�<�A�>�����%5�$6�7�7��'�K�'��?
s�
!G,c���|}tjdd|�}tjddj|�|�}tjddj|�|�}|S)a�Parse description from the meta in a format that we can better
    display in our docs. This parser does three things:

    - Guarantee that a paragraph will be in a single line
    - Guarantee that each new paragraph will be aligned with
      the first paragraph
    - Proper align lists of items

    @param description: The original description in the meta.
    @param prefix: The number of spaces used to align the current description
    z
(\S)\n(\S)z\1 \2z\n\nz\n\n{}z\n( +)-z\n{}-)rQ�subrS)r0rq�list_paragraphs   r>�_parse_descriptionr�s^���N��&�&���+�>�K��&�&��)�"2�"2�6�":�K�H�K��&�&��H�O�O�N�3�[��K��r=�src_cfgc��d|vr5|jd�jdd�}|j||�d|vr�d|dvr;|djd�jdd�}|dj||�d|dvrG|ddD]<}d|vs�|jd�jdd�}|j||��>t|j	dg�|j	dg�|j	dg��D]<}d|vs�|jd�jdd�}|j||��>y)	zEFlatten schema: replace $refs in src_cfg with definitions from $defs.r�z#/$defs/r�r�r�r��allOfN)�popr��updater
r�)r�r��	reference�
sub_schemas    r>r�r�'sU��
����K�K��'�/�/�
�B�?�	����t�I��'��'���W�W�%�%���(�,�,�V�4�<�<�Z��L�I��G��#�#�D��O�4��g�g�&�&�%�g�.�w�7�
7�
��Z�'� *���v� 6� >� >�z�2� N�I��%�%�d�9�o�6�
7�����G�R� ����G�R� ����G�R� ��/�
�
�Z��"���v�.�6�6�z�2�F�I����d�9�o�.�/r=c�^�|jdd�}|sy|D]}|j|��y)z�Flatten schema: Merge allOf.

    If a schema as allOf, then all of the sub-schemas must hold. Therefore
    it is safe to merge them.
    r�N)r�r�)r��sub_schemasr�s   r>�flatten_schema_all_ofr�As5���+�+�g�t�,�K���!�#�
����z�"�#r=�prop_configc��dtdtdtfd�}|jdi�}|jdi�}g}g}||||�t||�D]}||||��dj	t||��}|rd|��}|S)	aGReturn accumulated property description.

    Account for the following keys:
    - top-level description key
    - any description key present in each subitem under anyOf or allOf

    Order and deprecated property description after active descriptions.
    Add a trailing stop "." to any description not ending with ":".
    r��descriptions�deprecated_descriptionsc���tt|jd��r|jt	|��y|jd�r|jt	|��yy)N)r��changed_version�new_versionr0)�anyryr�r�r�)r�r�r�s   r>�assign_descriptionsz6_get_property_description.<locals>.assign_descriptionsYs]�����
�
�H�
�
�
$�*�*�2�6�:�
��Z�Z�
�
&���� B�6� J�K�'r=r�r�r�r�)r;r�r�r
rx)r�r�r�r�r�r�r�r0s        r>�_get_property_descriptionr�Ns���
L��
L�$(�
L�CG�
L�
�O�O�G�R�(�E��O�O�G�R�(�E��L�$&����\�3J�K��%��'�M���H�l�4K�L�M��)�)�E�,�0G�H�I�K���+��'���r=c
��|dz}g}|jd�durydD�cgc]}d|vs||dvr|��}}|D�cgc]}|j|i���}}|D�]�}|j�D�]�\}	}
t|
|�t|
�|
jd�dur�2t	|
�}|
jd|	�}|jtj||t||dz�t|
|����|
jd�}
|
r�t|
|�|
jd	�s|
jd
�rC|jtj||���|jt|
||���|
jd
g�D]h}|jd	�s|jd
�s�&|jtj||���|jt|||����jd	|
vsd
|
vs���|jt|
||���������dj|�Scc}wcc}w)zDReturn restructured text describing the supported schema properties.�  �hiddenTr�)r��patternPropertiesr�)rq�	prop_namer0�	prop_typer�r�r�)rqr��r�rqr�r�)
r�r�r�r�r�r��SCHEMA_PROPERTY_TMPLrSr�r��SCHEMA_LIST_ITEM_TMPL�_get_property_docrx)r�r�rq�
new_prefixr�r��
property_keys�property_schemas�prop_schema�prop_keyr�r0r�r��
alt_schemas               r>r�r�xsh���$��J��J�
�z�z�(��t�#��7����6�!�S��x�0@�%@�	��M��
8E�E���
�
�3��+�E��E�'�5��%0�%6�%6�%8�4	�!�H�k���T�2�!�+�.����x�(�D�0��3�K�@�K� �O�O�G�X�6�E����$�+�+�!�#� 2�;���
� N�0��d�C�	,��
� �O�O�G�,�E��#�E�4�0��9�9�\�*�e�i�i�8K�.L��%�%�-�4�4�#-��5���
�%�%�)�%�d�:�N��#(�)�)�G�R�"8�
�J�!�~�~�l�3�z�~�~�+�8�#�)�)�1�8�8�'1�U�9���
#�)�)�-� *��j���
���+�&�+�5��!�!�%�#�$�z���a4	�5�l�;�;�z�"�"��{��
Fs
�H8�H=�metac	��t�}tjj|jd�}|jd�}|syd}|D]�}t
|t�r@|dr
d|d�d�}nd}|ttjj||d��z}tj|d�jd�}|dj|�z
}��|S)	zAReturn restructured text describing the meta examples if present.�module-docsr2r��commentrgr/�file�   )rr3rNrx�docs_dirr�r�r;r �textwrap�indentr�)r��paths�module_docs_dirr2�rst_content�exampler��indented_liness        r>�
_get_examplesr�s�����E��g�g�l�l�5�>�>�=�A�O��x�x�
�#�H����K��1���g�t�$��y�!��w�y�1�2�"�5�����������_�g�f�o�>�!��G�"����%�8�>�>�t�D���t�y�y��0�0��1��r=c�h�|jd�sydjd�|dD��}d|�d�S)Nr4r�roc3�(K�|]
}d|�d����y�w)r�Nr<)r�r�s  r>r�z3_get_activate_by_schema_keys_doc.<locals>.<genexpr>�s������"�Q�C�r�
��s�z**Activate only on keys:** r�)r�rx)r��schema_keyss  r>� _get_activate_by_schema_keys_docr�sD���8�8�-�.���)�)�� �!:�;���K�)��
�T�:�:r=c��|�
t�}|r|std��t|j��}hd�}dh}d}||z
rdj	||z
�}n||z
|z
rdj	||z
�}|rt|��t
t|��}d|d<d|d	<d
|d<tjtt|d�d�|d<|jd
i�}|j|d�r%|j|di�}tt|�}t|dj��r	t||d��|d<|jdd�sd|d<tjt'|�d�|d<|dsd|d<dj)|d�|d<t+j,dd|d�|d<t/|�|d<t1jdi|��}|S#t $rt"j%d�d|d<Y��wxYw)z�Return reStructured text rendering the provided metadata.

    @param meta: Dict of metadata to render.
    @param schema: Optional module schema, if absent, read global schema.
    @raise KeyError: If metadata lacks an expected key.
    z"Expected non-empty meta and schema>r-r.r/r1r2r3r0r4r�z(Missing required keys in module meta: {}z3Additional unexpected keys found in module meta: {}�property_headerz      �prefix6r��prefix3r0z$defsr-r�r��property_docz3Unable to render property_doc due to invalid schemaz+      No schema definitions for this moduler2z$         No examples for this moduleror1r�-r.�title_underbarr<)rP�
ValueErrorr��keysrS�KeyErrorr;rrrrr8r�r��valuesr��AttributeErrorrrrrxrQr�r�SCHEMA_DOC_TMPL)	r�r�r�
required_keys�
optional_keys�
error_message�	meta_copyr��templates	         r>�get_meta_docr�s:���~�����v��=�>�>��t�y�y�{��D��M�/�/�M��M��t��B�I�I��D� �
�
�
�
�	�
�	-�A�H�H��}�$�
�	�
��}�%�%��X�d�^�$�I�#%�I�� �#�I�i�� �I�i��'����S�)�M�*�+�X� �I�m���:�:�g�r�"�D��x�x��T�
�����$�t�*�b�)���d�F�#��
�6�,��&�&�(�)�	+�(9��T�(�)�I�n�%��=�=���,�9�	�.�!�%�O�O�M�$�,?��J�I�j���Z� � F�	�*���9�9�T�)�_�5�I�i��"$�&�&��s�D��L�"A�I���+K��,�I�'�(��%�%�2�	�2�H��O��#�	+��K�K�M�N�(*�I�n�%�	+�s�6G#�##H	�H	c��tjjtjjt��}t|�SrD)r3rN�dirname�abspath�__file__r)�configs_dirs r>�get_modulesr$(s,���'�'�/�/�"�'�'�/�/�(�";�<�K���,�,r=�requested_modulesc���d}tt�j��dgz}t|�j	t|��}|r5tdj
t|�dj|��d��t�}t�}t|�D]�}d|vs||vs�tj|dgdg�\}}|s�+tj|d	�}	|j|	jd
�rV|	jj!|j|	jd
i��|t#|	j|�xsdz
}��||	j$xsdz
}��|S)zaLoad module docstrings

    Docstrings are generated on module load. Reduce, reuse, recycle.
    r��allz+Invalid --docs value {}. Must be one of: {}roTr�zcloudinit.configr�rr-)r�r$rr��
differencerrSrx�get_module_docsrPr�r�find_module�
import_moduler�r�r�rrW)
r%�docs�all_modules�invalid_docs�module_docsr��mod_name�mod_locsrB�mods
          r>�load_docr3-sM��
�D��{�}�+�+�-�.�%��8�K��(�)�4�4�S��5E�F�L��
�9�@�@��\�"��	�	�+�&�
��	
�"�#�K�
�\�F��;�'�.���%�%��5F�)F�$�0�0��-�.����M�X�q���,�,�X�a�[�9���?�?�3�8�8�D�>�2��H�H�O�O�K�O�O�C�H�H�T�N�B�$G�H��L����6�:�@�b�@�D��C�K�K�-�2�-�D�.��Kr=c��tjjtjjtjj	t
��d�S)N�schemas)r3rNrxr r!r"r<r=r>�get_schema_dirr6Os1��
�7�7�<�<������������(A�B�I�N�Nr=c���t�}i}tjj|jd�}tj
|�d��D]%}|j
tt|����'|S)z<Return a dict keyed on cc_<mod_name> with documentation infor�z/*/data.yaml)	rr3rNrxr��globr�r!r )r�mod_docsr�mod_docs    r>r)r)Ssb����E��H��g�g�l�l�5�>�>�=�A�O��9�9��0��=�>�<�����	�.��"9�:�;�<��Or=c��tjjt�t|d�}d}	tjt|��}|S#ttf$r&tjd|j|�icYSwxYw)ziReturn jsonschema for a specific type.

    Return empty schema when no specific schema file exists.
    r\Nz<Skipping %s schema validation. No JSON schema file found %s.)
r3rNrxr6�SCHEMA_FILES_BY_TYPE�json�loadsr �IOError�OSErrorrrra)ri�schema_file�full_schemas   r>rPrP]s���
�'�'�,�,���.�{�;�H�E��K��K���j�j���!<�=�����
�W������J�����	
�
�	�
�s�A�2B�
Bc	��|stjdd��}|jddd��|jdd	ttj
jtjjgd
tj
����|jdd
tdt�jd�����|jdddd��|jdddd��|jdddd��|S)z0Return a parser for supported cmdline arguments.�cloudconfig-schemaz�Schema validation and documentation of instance-data configuration provided to cloud-init. This includes: user-data, vendor-data and network-config)�progr0z-cz
--config-filez@Path of the cloud-config or network-config YAML file to validate)�helpz-tz
--schema-typezSWhen providing --config-file, the schema type to validate config against. Default: )r��choicesrFz-iz--instance-datazbPath to instance-data.json file for variable expansion of '##template: jinja' user-data. Default: �
instance_data)r�rFz--system�
store_trueFzVValidate the system instance-data provided as vendor-data user-data and network-config)�action�defaultrFz-dz--docs�+zCPrint schema module docs. Choices: all or space-delimited cc_names.)�nargsrFz
--annotatez;Annotate existing instance-data files any discovered errors)
�argparse�ArgumentParser�add_argumentr8rUrXrarYr�get_runpath�rAs r>�
get_parserrSrs<����(�(�%�=�
�������N�	�������
��#�#�)�)��%�%�+�+�
�

"�",�"9�"9�!:�
<��������
�
:���+�+�O�<�=�
?��	�������
,���������
)���������
J�	���Mr=c�j�|j|j|jg}t|D�cgc]}|s�|��	c}�dk7r
t	dd��t|j|jg�r|jrtd�|jr|jrt	dd��yyycc}w)z:Error or warn on invalid exclusive parameter combinations.rKz;Expected one of --config-file, --system or --docs argumentsTr�z[WARNING: The --schema-type parameter is inapplicable when either --system or --docs presentz;Invalid flag combination. Cannot use --annotate with --docsN)	�config_filer,�systemr�rr�rir;r�)�args�exclusive_args�args   r>�_assert_exclusive_argsrZ�s����&�&��	�	�4�;�;�?�N�
�>�1�C�S�C�1�2�a�7�
�I��	
��D�K�K����#�$��)9�)9�
�
*�	
��}�}����
�I��	
�#�}��2s
�B0�B0c
�j�dtdtdtdtfd�}	td��}|jr
|j}n:tj�dk7r|jd�}n|jd
�}g}|jr�|j rt#|j �}nt"j$}|t"j&k(rt(j&}nt(j*}|j-t/|||j���nRtj�dk7r
t1dd��||dd�}|j-t/t(j*t"j$|��t/t(j2t"j$||dd��t/t(j4t"j$||dd��t/t(j&t"j&|j7d�xsd�g}	|	D]J}
|
j8s�tj:j=|
j8�s�:|j-|
��Ltj:j=|dj8�st1d|dj8�d�dd��||fS#ttf$r?}|j
tk(r tjd�t�}n�Yd	}~���d	}~wt$r#t�}tjd
�Y��wxYw)aReturn appropriate instance-data.json and instance data parts

    Based on command line args, and user permissions, determine the
    appropriate instance-data.json to source for jinja templates and
    a list of applicable InstanceDataParts such as user-data, vendor-data
    and network-config for which to validate schema. Avoid returning any
    InstanceDataParts when the expected config_path does not exist.

    :return: A tuple of the instance-data.json path and a list of
        viable InstanceDataParts present on the system.
    r�primary_path_key�raw_fallback_path_keyrOc�6�|j|�xsd}tt�5tj|�j
s?|j|�xsd}tj|�j
r|cddd�Sddd�|S#1swY|SxYw)akGet processed data path when non-empty of fallback to raw data path.

        - When primary path and raw path exist and are empty, prefer primary
          path.
        - When primary path is empty but the raw fallback path is non-empty,
          this indicates an invalid and ignored raw user-data was provided and
          cloud-init emitted a warning and did not process unknown raw
          user-data.
          In the case of invalid raw user-data header, prefer
          raw_fallback_path_key so actionable sensible warnings can be
          reported to the user about the raw unparsable user-data.
        r�N)�	get_ipathr�FileNotFoundErrorr3�stat�st_size)rr\r]�primary_datapath�raw_paths     r>�get_processed_or_fallback_pathzBget_config_paths_from_args.<locals>.get_processed_or_fallback_path�s���"!�?�?�+;�<�B���
�'�
(�	$��7�7�+�,�4�4� �?�?�+@�A�G�R���7�7�8�$�,�,�#�		$�	$�	$�
 ��	$�
 ��s�AB�B�trust)�fetch_existing_datasourcez=Using default instance-data/user-data paths for non-root userNzEdatasource not detected, using default instance-data/user-data paths.rrH�instance_data_sensitivezNUnable to read system userdata or vendordata as non-root user. Try using sudo.Tr��cloud_config�userdata_raw�vendor_cloud_config�vendordata_raw�vendor2_cloud_config�vendordata2_rawr r�zConfig file z does not existz	Error: {}��fmtr�)rr8rr?r@�errnorrr2rrrHr3�getuidrQrUrirUrXrYr^rcr�rgrrdrer_rjrNr7)rWrerr�r��config_filesri�instancedata_type�
userdata_file�supplemental_config_files�	data_parts           r>�get_config_paths_from_argsrx�s��� �� �� � #� �

�	 �2
���A�����!�/�/��	�����	�"�.�.��?��"�.�.�/H�I��+-�L�������$�T�%5�%5�6�K�$�1�1�K��*�3�3�3� 0� ?� ?�� 0� 9� 9������.��T�=M�=M�N�	
��9�9�;�!���)��
�
7��>�>�
�
�	���� �)�)��'�'��
�	
�
� �+�+��'�'�.��0�2B��
�
� �,�,��'�'�.��1�3D��
�
� �/�/��)�)���� 0�1�7�R�
�=
�!�*3�	/�I��$�$������	�8M�8M�)N��#�#�I�.�	/��7�7�>�>�,�q�/�5�5�6�
��<��?�6�6�7��G���	
�
�|�+�+��a
�W����7�7�f���I�I�O�
�#�$�E��
��'�
�� �����
.�	
�
�s�J:�:L2�	4L�+L2�1L2c
���t|�t�}|jrtt	|j��yt|�\}}d}t
t|�dkD�}|r&tddjd�|D��z�d}g}t|d�D]�\}}	d}
|r)td	|�d
|	j�d|	j�d��|	jtjk(rt|	j�}n|}	t|	j||	j|j |�}
|
s��|j"r
|	j}n|	j}t|�d
|�����|r%t'djd�|D��dd��yy#t$$rr}
|j s@t|�d|	j�d|	j���t't)|
�|dz��|j+|	j�Yd}
~
��nd}
~
wt,$rY}
t|�d|	j���t't)|
�|dz��|j+|	j�Yd}
~
���d}
~
wwxYw)z@Handle provided schema args and perform the appropriate actions.Nr�rKz!Found cloud-config data types: %sroc3�FK�|]}t|j����y�wrD)r8rh)r��cfg_parts  r>r�z%handle_schema_args.<locals>.<genexpr>Us����O�h��H�0�0�1�O�s�!r�Fr/r�z at �:z
Valid schema zInvalid r�z
Error: {}
)rpc3�2K�|]}t|����y�wrD)r8)r�r�s  r>r�z%handle_schema_args.<locals>.<genexpr>�s����D�*�c�*�o�D�r�zError: Invalid schema: {}
Tro)rZrPr,r;r3rxr�r�rxr�rhrjrirUrYr�r�rUr}rr8r�r�)r.rWrBr�rs�nested_output_prefix�multi_config_output�error_types�idxr{�performed_schema_validation�
cfg_schema�cfgr�s              r>�handle_schema_argsr�Gsj���4� ��,�K��y�y�
�h�t�y�y�!�"��'A�$�'G�$������s�<�0�1�4�5���
�/��i�i�O�,�O�O�
P�	
� $���K�"�<��3�'E�
��X�&+�#����S�E��H�0�0�1��h�6J�6J�5K�1�M�
����:�#<�#<�<�#�H�$8�$8�9�J�$�J�	E�*C��$�$���$�$��
�
�"�+�'�.+��#�#�"�.�.�C�"�.�.�C��-�.�m�C�7�C�D�O'E�P�
��I�I�D��D�D�-��	
���-%�
	5��=�=��+�,�-� �,�,�-�Q�x�/C�/C�.D�F�����F�,�}�<��
���x�3�3�4�4���	5��)�*�(�8�3G�3G�2J�K�L��#�a�&�2�]�B�C����x�3�3�4�4��	5�s&�-F�	I1�A'H�I1�AI,�,I1c�L�t�}td|j��y)zDTool to validate schema of a cloud-config file or print schema docs.rDr)rSr��
parse_argsrRs r>�mainr��s ��
�\�F��+�V�->�->�-@�A�r=�__main__)FN)T)FFTrD)r�)�rWrNr8r=�loggingr3rQr8�sysr�collectionsr�collections.abcr�
contextlibr�copyrr�rrqr�	functoolsr	�	itertoolsr
r:rrr
rrrrrrr��	cloudinitrrrr�cloudinit.cmd.develr�cloudinit.handlersrr�cloudinit.helpersr�cloudinit.sourcesr�cloudinit.temp_utilsr�cloudinit.utilrrr r!r"r�r#r��	Exception�	getLoggerr5r�VERSIONED_USERDATA_SCHEMA_FILE�USERDATA_SCHEMA_FILE�NETWORK_CONFIG_V1_SCHEMA_FILE�NETWORK_CONFIG_V2_SCHEMA_FILEr�rr�r�rr�rr��typing_extensionsr)r*r,r;r@rMr�rUrXrYrZr[r<r^rgrlr8r{rr}r�r�r�r�r�r�rrr�r�rrrlr#rDr\r^r�r<r�r�r�r�r�r�r�r�r�r�r�r�rrrr$r�r3r6r)rPrSrZrxr�r��exit)�ts0r>�<module>r�s���L�����	�	�
�
��#�$�������
�
�
��=�=�.�I�#�9�(��� �*�
�g����!��"E��5�� ?�� ?���'��8�	���<O������ �(�#�(�(�*�:�1�a��d�c�k�Q�:�����8�8�Y�8��J�$�_�$�.�J�.��m�$��,��,�"����&������/� �� � ��/�#�� � ��/�#�
�� 
�t�
��z���J��!��		�#�	�
�S�M�	��		�
	�	�&(�J�&(�RI�)>�I�(�.2� =�� =�� =�F�D��4I��N#9�
I��I�
�	I�
�I��Y��
I�( �
�|�D���Z�I�>��#9�@ �
�Y��@ �P#9�'$�
�Y��'$�TI/�X 
�t� 
�F)�4�)�H�S�M�)����	^��^��^��^��	^�

�^�F"�(�5�5��#��"�L��L��T�N�L��L�
�	L�
�L��
L��L�
�L�^h,�h,�`/3�48�
�������
�N�+��"�.�1�
��3��:���0�
��	�-���B)-�BB��BB�
�BB�!��
�BB�#�	BB�P)�5�5��(,�K��K��K��K��	K�
!��
�K�
�
K�\

��*�D�*�S�*�T�#�Y�*�")(�d�)(�$�)(�3�)(�X�s��,/��/�T�/�4
#�4�
#�'�4�'�C�'�TC#�d�C#�$�C#��C#�L�
��s��.;�:�;�#�;�G�z�G�8�D�>�G�S�G�T-�T�-�
�����DO��O����*4�)@�)@��J��T��*A�H
�(z,�
�3��%�&�&�'�z,�z@
�F
��z���C�H�H�T�V����:� ��O� ��z;s�,N�/
N,�=N,�N)�(N)

Zerion Mini Shell 1.0