a '¡DgÉã @sÐdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZmZmZmZmZmZmZmZddlZdd lmZm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&m'Z'dd l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2zddl3m4Z4Wne5�yPe6Z4Yn0zddl7m8Z8m9Z9dZ:Wne5�y‚dZ:Yn0e ;e<¡Z=dZ>dZ?dZ@dZAeBdd„e& C¡DƒƒZDe�räddlZddlEmFZFmGZGGdd„deGƒZHneIZHGdd „d e4ƒZJGd!d"„d"eƒZKeeKZLGd#d$„d$eƒZMeMjNd%e>ieMjOd%e@ieMjPd%e?ieMjQd%e@iiZRGd&d'„d'eƒZSGd(d)„d)eƒZTGd*d+„d+eƒZUdd,d-œeLeeVeVeVd.œd/d0„ZWGd1d2„d2eXƒZYGd3d4„d4eYƒZZd5d6„Z[dueIeVd7œd8d9„Z\ee4d:œd;d<„Z]eJfe^eIeVee6d=œd>d?„Z_ee_dd@�Z`ee_dAd@�ZaeJfee6dBœdCdD„ZbeJfee6dBœdEdF„ZcdGdH„ZddveIdIœdJdK„ZeeIeefdLœdMdN„ZgdweIe^e^e^e^dOœdPdQ„Zhe! idR¡deMjNddddfeIeeIeMe^e^e^e^e^dSœdTdU„ƒZjGdVdW„dWƒZkdddXœeVeIeeLeeLeeVelfdYœdZd[„ZmeVeeKd\œd]d^„ZndxeVeVeeVeUd_œd`da„ZoeMjNddfeVeIeMe^eeVe^dbœdcdd„ZpeVd:œdedf„ZqeMjNfeMeIdgœdhdi„Zrdydjdk„Zsdldm„ZteeVeeTfd:œdndo„Zudpdq„Zvdrds„ZweGór&)Ú NotRequiredÚ TypedDictc@s<eZdZUeed<ejeed<eed<eeeed<dS)Ú MetaSchemaÚidZdistrosZ frequencyZactivate_by_schema_keysN)Ú__name__Ú __module__Ú __qualname__ÚstrÚ__annotations__Útypingr r(r"r"r"r%r*Qs r*cs$eZdZeedœ‡fdd„ Z‡ZS)ÚSchemaDeprecationError)ÚmessageÚversionc stƒj|fi|¤Ž||_dS©N)ÚsuperÚ__init__r4)Úselfr3r4Úkwargs©Ú __class__r"r%r7\szSchemaDeprecationError.__init__)r,r-r.r/r7Ú __classcell__r"r"r:r%r2[sýr2c@s,eZdZUeed<eed<edœdd„ZdS)Ú SchemaProblemÚpathr3©ÚreturncCs|j›d|j›�S)Nú: )r>r3©r8r"r"r%ÚformatjszSchemaProblem.formatN)r,r-r.r/r0rCr"r"r"r%r=fs r=c@s eZdZdZdZdZdZdZdS)Ú 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)r,r-r.Ú__doc__Ú CLOUD_CONFIGÚNETWORK_CONFIGÚNETWORK_CONFIG_V1ÚNETWORK_CONFIG_V2r"r"r"r%rDqs rDÚlatestc@s(eZdZdZdZdZdZdZdd„ZdS) ÚInstanceDataTypez-Types of instance data provided to cloud-initz user-datarEz vendor-dataz vendor2-datacCs|jSr5)ÚvaluerBr"r"r%Ú__str__šszInstanceDataType.__str__N) r,r-r.rFÚUSERDATArHÚ VENDORDATAÚ VENDOR2DATArNr"r"r"r%rL‘s rLc@s&eZdZUeed<eed<eed<dS)ÚInstanceDataPartÚ config_typeÚ schema_typeÚ config_pathN)r,r-r.rLr0rDr/r"r"r"r%rRžs rRc@seZdZUeed<eed<dS)ÚUserDataTypeAndDecodedContentÚ userdata_typeÚcontentN)r,r-r.r/r0r"r"r"r%rV¤s rVú, ©ÚprefixÚ separator)Úschema_problemsr[r\r@cCs(| tdd„|ƒ¡}|r$|›|›�}|S)NcSs| ¡Sr5)rC)Úpr"r"r%Ú¯r'z)_format_schema_problems..)ÚjoinÚmap)r]r[r\Ú formattedr"r"r%Ú_format_schema_problems©s rccs@eZdZdZd eeeedœ‡fdd„ Zedœdd„Z‡Z S) ÚSchemaValidationErrorz.handle_problemszCloud config schema errors: rjú"Cloud config schema deprecations: N)rfrgr6r7)r8rfrgrpr:ror%r7¸s  þþzSchemaValidationError.__init__r?cCs t|jƒSr5)ÚboolrfrBr"r"r%Ú has_errorsÚsz SchemaValidationError.has_errors)NN) r,r-r.rFr ÚSchemaProblemsr7rrrsr<r"r"r:r%rdµsýý"rdc@seZdZdZdS)Ú"SchemaValidationInvalidHeaderErrorz>Raised when no valid header is declared in the user-data file.N)r,r-r.rFr"r"r"r%ruÞsrucCs@zddlm}Wnty$YdS0|j |d¡p>t|tfƒS)zWTYPE_CHECKER override allowing bytes for string type For jsonschema v. 3.0.0+ r)ÚDraft4ValidatorFÚstring)Ú jsonschemarvÚ ImportErrorÚ TYPE_CHECKERÚis_typeÚ isinstanceÚbytes)ZcheckerÚinstancervr"r"r%Úis_schema_byte_stringâs ÿ þr)Úconfigr@csPtdœ‡‡fdd„ }|r|ngd¢}d t||ƒ¡}ˆ dd¡}|›|›� ¡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 ©Úkeycsrˆ |›¡sdSˆ |›d�d¡}ˆ |›d�d|›d�¡}| ¡›d|›d|›�}ˆrbd|›�Sd | ¡›d �S) NrhZ _descriptionÚ_versionz z in version ú. ú z *Ú*)ÚgetÚ capitalizeÚstrip)r‚Zkey_descriptionÚvÚmsg©Úannotater€r"r%Úformat_messageùs  þ z:_add_deprecated_changed_or_new_msg..format_message)r ÚchangedÚnewrhÚ description)r/r`rar‡Úrstrip)r€r�Ú filter_keyrŽZ filter_keysZchanged_new_deprecatedr‘r"rŒr%Ú"_add_deprecated_changed_or_new_msgðs ÿ r”r?cCsÜg}d}t|tƒod|v}|D]¸}|rž|d|j di¡ di¡ dg¡vrV|gSt|dƒr~|jdd…dkrœ| |¡qÖ|jrÖ|jddkrÖ| |¡qt|jƒ|kr¸| |¡qt|jƒ|krt|jƒ}|g}q|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|ÚdictÚschemar‡Úhasattrr˜Úappendr>Úlen)Úerrorsr~Z best_matchesZ path_depthr{Úerrr"r"r%Úcloud_init_deepest_matchess,ÿþ      r¡)r r›r“Ú error_typeccs,|r(t|d|gd�}||| dd¡ƒVdS)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“Zdeprecated_versionÚdevelN)r”r‡)Ú _validatorr Z _instancer›r“r¢r‹r"r"r%r¤4s ÿr¤)r“r�©r¢c#süddlm}g}g}d}t|ƒD]ª\} } t|j|| | d�ƒ} tt‡fdd„| ƒƒ} tt‡fdd„| ƒƒ} | sz| | ¡qît|tƒrÀd|vrÀd |   d d ¡vrÀd |d›�| d vrÀd }| EdH| | ¡q |sÚ||ƒVt d|f|d�V|EdHdS)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©Z schema_pathcs t|ˆƒ Sr5©r|©Úer¥r"r%r_sr'z_anyOf..cs t|ˆƒSr5r¨r©r¥r"r%r_ur'r•Z anyOf_typez$refrhZ anyOf_type_TNz.%r is not valid under any of the given schemas)Úcontext) Újsonschema.exceptionsr¦Ú enumeraterlÚdescendÚfilterÚextendr|ršr‡r)Ú validatorÚanyOfr~Ú_schemar¢r¦Ú all_errorsÚall_deprecationsZskip_best_matchÚindexÚ subschemaÚall_errsÚerrsÚ deprecationsr"r¥r%Ú_anyOfLs@ ÿÿ ÿþý   þr»c#sæt|ƒ}g}g}|D]h\}} tˆjˆ| |d�ƒ} tt‡fdd„| ƒƒ} tt‡fdd„| ƒƒ} | sr| } | | ¡qŽ| | ¡qt|ˆƒEdH‡‡fdd„|Dƒ}|rØ| | ¡d d d „|Dƒ¡}td ˆ|fƒVn |EdHdS) 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§cs t|ˆƒ Sr5r¨r©r¥r"r%r_¢r'z_oneOf..cs t|ˆƒSr5r¨r©r¥r"r%r_¤r'Ncs g|]\}}ˆ ˆ|¡r|‘qSr")Úis_valid)r#ÚiÚs)r~r±r"r%r&®r'z_oneOf..rYcss|]}t|ƒVqdSr5)Úrepr)r#r›r"r"r%Ú ±r'z_oneOf..z%r is valid under each of %s) r­rlr®r¯r°r¡r�r`r)r±ÚoneOfr~r³r¢Z subschemasr´rµr¶r·r¸r¹rºZ first_validZ more_validZreprsr")r¢r~r±r%Ú_oneOf�s2  ÿÿ    ÿrÂc CsÌddlm}m}ddlm}t|jƒ}ddi|dd<i}d|d <|j dt ¡}d |i}t |j ƒ}t |t <t|d <t|d <t|d <|f||ddœ|¤Ž}ddd„}ddd„} |} t|dƒr¾| } | |_||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)rvÚ FormatChecker)Úcreater•rwr–ÚlabelFÚadditionalPropertiesÚ type_checkerr�rÁr²Zdraft4)Ú meta_schemaÚ validatorsr4Nc[s$tdd„| ||¡ƒ}t|dƒduS)úgOverride version of `is_valid`. It does ignore instances of `SchemaDeprecationError`. cSs t|tƒ Sr5©r|r2r©r"r"r%r_ïsÿzFget_jsonschema_validator..is_valid_pre_4_0_0..N)r¯Ú iter_errorsÚnext©r8r~r³Ú__rŸr"r"r%Úis_valid_pre_4_0_0és  üz4get_jsonschema_validator..is_valid_pre_4_0_0c[s*tdd„|j|d� |¡ƒ}t|dƒduS)rÊcSs t|tƒ Sr5rËr©r"r"r%r_üsÿz.is_valid..©r›N)r¯ÚevolverÌrÍrÎr"r"r%r¼ös üz*get_jsonschema_validator..is_validrÒ)N)N)rxrvrÃZjsonschema.validatorsrÄrZ META_SCHEMArzZredefinerršZ VALIDATORSÚ_validator_deprecatedÚDEPRECATED_KEYÚ_validator_changedrÂr»rœr¼) rvrÃrÄrÈZvalidator_kwargsrÇrÉÚcloudinitValidatorrÐr¼Z is_valid_fnr"r"r%Úget_jsonschema_validator¹s<  ÿÿ ýü  r×rÑc Cs|ddlm}z| |¡Wn\|yv}zD|rVttd dd„|jDƒ¡|jƒgd�|‚t  d|¡WYd}~n d}~00dS) 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Ú.cSsg|] }t|ƒ‘qSr"©r/©r#r^r"r"r%r&'r'z3validate_cloudconfig_metaschema..©rfzGMeta-schema validation failed, attempting to validate config anyway: %sN) r¬rØZ check_schemardr=r`r>r3ÚLOGÚwarning)r±r›ÚthrowrØr r"r"r%Úvalidate_cloudconfig_metaschemas" ÿÿÿúýrà)Únetwork_configr@cCs d|vr|d d¡S| d¡S)z6Return the version of the network schema when present.Únetworkr4)r‡)rár"r"r%Únetwork_schema_version2srã)ráÚstrictr�Ú log_detailsr@c CsRtrt d¡nt d¡dStƒ}tj |d¡}t|ƒ}d|vrJd|i}t  |¡}t ||dd�t ƒ}g} z|  |¡WnJt yÄ} z2|  tdj| j| jd �d | j›�ƒ¡WYd } ~ n d } ~ 00tj |¡rÜt |¡| �rN|�r|�rt |¡\} } tt|| | d �ƒt| ƒ‚|�r6t| tjj›d �dd�} ntjj›d�} t | ¡dS)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. z*Validating network-config with netplan APIzr`rrÚdumpsrrZload_yaml_hierarchyrr�r=rCréÚcolumnr3ÚexistsÚshutilÚrmtreeÚload_with_marksÚprintÚannotated_cloudconfig_filerdrcrDrHrMrÞ)rárär�råZ parse_dirZ netplan_fileZnet_cfgZ src_contentÚparserrŸrªÚ_Úmarksr3r"r"r%Únetplan_validate_network_schema9s` ÿ  þÿ  ýÿ ú ÿ rüzValidating schema)r€r›rTräÚstrict_metaschemaråÚlog_deprecationsr@cCsFddlm}|tjkrDt|ƒ}|dkr.tj}n|dkr|jdk�r>|j|k�r>t d|j¡}|�r>|d}t|tƒ�r�|jdk�sht |jtj¡�r||  t||jƒ¡n| t||jƒ¡qê|  t||jƒ¡qê|�râ|�rÆt |dd�}t  !|¡| �rât | dd�}t  "|¡|�r| �sú| �sú|�rt#| | |ƒ‚| �rB|�r,t | |j$›d�dd�}n |j$›d�}t  %|¡dS)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åTFN)rßz5Ignoring schema validation. jsonschema is not present)Zformat_checkercSs|jSr5)r>r©r"r"r%r_çr'z-validate_cloudconfig_schema..r�rÙcSsg|] }t|ƒ‘qSr"rÚrÛr"r"r%r&ér'z/validate_cloudconfig_schema..rÆz#.*\('(?P.*)' was unexpected\)Únamer£z"Deprecated cloud-config provided: rjrërìrZrí)&Úcloudinit.net.netplanrrDrHrãrJrIÚ get_schemarür×ràryrÝrïrkrÌr`r>r±r›ÚreÚmatchr3r|r2r4rZshould_log_deprecationrZDEPRECATION_INFO_BOUNDARYr�r=rcÚinfor rdrMrÞ)r€r›rTrärýrårþÚnetplan_availableÚnetwork_versionrÖrÃr±rŸrºZinfo_deprecationsÚ schema_errorr>Z prop_matchr3Údetailsr"r"r%Úvalidate_cloudconfig_schema˜sª$   ÿ ÿ   ÿ ÿþýÿÿÿÿþ ÿþ þ  ý ÿ r c @sœeZdZeedœdd„Zeeeeedœdd„ƒZe dœdd „Z edeeeeeee ee d œd d „ƒZ eeeeeedœdd„Z e e edœdd„ZdS)Ú _Annotator)Úoriginal_contentÚ schemamarkscCs||_||_dSr5)Ú_original_contentÚ _schemamarks)r8rrr"r"r%r7)sz_Annotator.__init__)ÚtitlerXr@cCsd |¡}d|›d|›d�S)Nrìú# z: ------------- ri)r`)rrXÚbodyr"r"r%Ú _build_footer1s z_Annotator._build_footer)r]cCszttƒ}|D]h\}}t d|¡}|rD| ¡\}}|t|ƒ |¡nd}||j| |¡|dur dj|||d�}q |S)Nz&format-l(?P\d+)\.c(?P\d+).*zLine {line} column {col}: {msg})rérêr‹) rrlrrÚgroupsÚintr�rrC)r8r]Úerrors_by_liner>r‹rrérêr"r"r%Ú_build_errors_by_line6s   ÿz _Annotator._build_errors_by_linerh)rnÚlabelsÚfooterr¶Ú label_prefixr@cCsB|D]8}|›|›�}| |¡| d|›d|›�¡|d7}q|S)NrrAr)r�)rnrrr¶rZproblemrÅr"r"r%Ú _add_problemsFs    z_Annotator._add_problems)ÚlinesrÚdeprecations_by_liner@c sÂg}g}g}d}d}t|dƒD]p\} } || } || } | s>| r„g} ˆj| | ||dd�}ˆj| | ||dd�}| | dd | ¡¡q| | ¡q| t‡fdd„td d„d |fd |ffƒƒ¡|S) NrÚE)rÚDz # ú,cs ˆj|ŽSr5)r©ÚseqrBr"r%r_ur'z._Annotator._annotate_content..cSs t|dƒS)Nr)rrr$r"r"r%r_wr'ZErrorsZ Deprecations)r­rr�r`r°rar¯)r8rrr Úannotated_contentZ error_footerZdeprecation_footerZ error_indexZdeprecation_indexZ line_numberrérŸrºrr"rBr%Ú_annotate_contentUsD ÿû  þþþÿ z_Annotator._annotate_content)rfrgr@cCsF|s|s|jS|j d¡}| |¡}| |¡}| |||¡}d |¡S)Nrì)rÚsplitrr'r`)r8rfrgrrr r&r"r"r%r��s   ÿz_Annotator.annotateN)rh)r,r-r.r/ršr7Ú staticmethodr rrtrrrr'r�r"r"r"r%r(s2ý ûúû .ürre)rrrfrgr@cCst||ƒ |pg|pg¡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 )rr�)rrrfrgr"r"r%rø‘s  ÿrø)rXr@c Csbddlm}||vrgSg}t| ¡dƒD]2\}}| |¡r*| td|›d�| |d¡ƒ¡q*|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_PREFIXrzformat-lz.c1zIgnored invalid user-data: )Zcloudinit.handlers.cloud_configr*r­Ú splitlinesÚ startswithr�r=Úreplace)rXr*rŸZline_numrér"r"r%Ú)process_merged_cloud_config_part_problems¨s   þþÿ r.)rUrXÚinstance_data_pathr@c CsLddlm}m}m}m}t|ƒ}d}|dkrèz||||ƒ}Wnž|yr} ztt|dƒgƒ| ‚WYd} ~ nrd} ~ 0|y¨} z tdt | ƒdd �WYd} ~ nr`ÚdirnameÚabspathÚ__file__r"r"r"r%Úget_schema_dir˜srA)rTr@c Cs^tj tƒt|d¡}d}zt t|ƒ¡}Wn*tt fyXt   d|j |¡iYS0|S)ziReturn jsonschema for a specific type. Return empty schema when no specific schema file exists. rKNzr`rAÚSCHEMA_FILES_BY_TYPEÚjsonÚloadsrÚIOErrorÚOSErrorrÝrÞrM)rTZ schema_fileÚ full_schemar"r"r%rœsÿý rcCs’|stjddd�}|jdddd�|jdd ttjjtjjgd tj›�d �|jd d tdtƒ  d¡›�d�|jddddd�|jddddd�|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)Úprogr‘z-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•ÚchoicesrJz-iz--instance-datazbPath to instance-data.json file for variable expansion of '##template: jinja' user-data. Default: Ú instance_data)r•rJz--systemÚ store_trueFzVValidate the system instance-data provided as vendor-data user-data and network-config)ÚactionÚdefaultrJz --annotatez;Annotate existing instance-data files any discovered errors) ÚargparseÚArgumentParserÚ add_argumentr/rDrGrMrHrÚ get_runpath©rùr"r"r%Ú get_parser±sTýüþÿ÷  þû û ürUcCsF|j|jg}tdd„|Dƒƒdkr.tddd�|jrB|jrBtdƒdS) z:Error or warn on invalid exclusive parameter combinations.cSsg|] }|r|‘qSr"r")r#Úargr"r"r%r&ïr'z*_assert_exclusive_args..rz3Expected one of --config-file or --system argumentsTr4zMWARNING: The --schema-type parameter is inapplicable when --system is presentN)Ú config_fileÚsystemržrrTr÷)ÚargsZexclusive_argsr"r"r%Ú_assert_exclusive_argsìs þ ÿrZc Csøttttdœdd„}ztdd�}Wnfttfyh}z*|jtkrRt d¡tƒ}n‚WYd}~n*d}~0t yˆtƒ}t  d¡Yn0|j r˜|j }n"t   ¡d kr°| d ¡}n | d ¡}g}|j�r |jrØt|jƒ}ntj}|tjkrðtj}ntj}| t|||jƒ¡n´t   ¡d k�r&td d d�||ddƒ}| ttjtj|ƒ¡ttjtj||ddƒƒttjtj||ddƒƒttjtj| d¡�pŒdƒg} | D](} | j�r–t j | j¡�r–| | ¡�q–t j |d j¡�sðtd|d j›d�dd d�||fS)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. )ÚpathsÚprimary_path_keyÚraw_fallback_path_keyr@cSsr| |¡p d}ttƒ�Ht |¡jsP| |¡p0d}t |¡jrP|WdƒSWdƒn1sd0Y|S)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. rhN)Ú get_ipathrÚFileNotFoundErrorrðÚstatÚst_size)r[r\r]Zprimary_datapathZraw_pathr"r"r%Úget_processed_or_fallback_path s   0zBget_config_paths_from_args..get_processed_or_fallback_pathZtrust)Zfetch_existing_datasourcez=Using default instance-data/user-data paths for non-root userNzEdatasource not detected, using default instance-data/user-data paths.rrLZinstance_data_sensitivezNUnable to read system userdata or vendordata as non-root user. Try using sudo.Tr4Z cloud_configZ userdata_rawZvendor_cloud_configZvendordata_rawZvendor2_cloud_configZvendordata2_rawrárhz Config file z does not existz Error: {}©Úfmtr5)rr/rrErFÚerrnorrÝrïrrÞrLrðÚgetuidrSrWrTrDrGrHrLrOr�rRrrPrQr^rUr>ró) rYrbr[rªr/Ú config_filesrTZinstancedata_typeZ userdata_fileZsupplemental_config_filesZ data_partr"r"r%Úget_config_paths_from_argsûs ü  ÿ ÿ       ÿýÿýÿÿýÿýýñýrhc Csæt|ƒtƒ}t|ƒ\}}d}tt|ƒdkƒ}|rRtdd dd„|Dƒ¡ƒd}g}t|dƒD�]Z\}} d} |r’td |›d | j›d | j ›d �ƒ| j t j krªt| j ƒ} n|} zt | j | | j |j|ƒ} WnÂt�y2} zP|j�st|›d | j›d| j ›�ƒtt| ƒ|dd�| | j¡WYd} ~ q`d} ~ 0t�yŠ} z@t|›d | j›�ƒtt| ƒ|dd�| | j¡WYd} ~ q`d} ~ 00| r`|j�r | j } n t| jƒ} t|›d| ›�ƒq`|�râtd dd„|Dƒ¡ddd�dS)z@Handle provided schema args and perform the appropriate actions.rhrz!Found cloud-config data types: %srYcss|]}t|jƒVqdSr5)r/rS)r#Úcfg_partr"r"r%rÀƒr'z%handle_schema_args..z Frìr„z at ú:zInvalid r…z Error: {} )rdNz Valid schema css|]}t|ƒVqdSr5rÚ)r#r¢r"r"r%rÀ²r'zError: Invalid schema: {} Trc)rZrrhrrržr÷r`r­rSrUrTrDrHr=r�rdrr/r�r<rW)rrYrGr/rgZnested_output_prefixZmulti_config_outputZ error_typesÚidxriZperformed_schema_validationZ cfg_schemarªZcfgr"r"r%Úhandle_schema_argsxsv ÿÿÿ  ûÿÿÿþ " ýrlcCstƒ}td| ¡ƒdS)zDTool to validate schema of a cloud-config file or print schema docs.rHr)rUrlÚ parse_argsrTr"r"r%Úmain¸srnÚ__main__)FN)T)FFT)N)N)yrFrPrCZloggingrðrrôÚsysÚ collectionsrÚ contextlibrÚcopyrr—rrerÚ functoolsrr1rr r r r r rrr:Z cloudinitrrrrZcloudinit.cmd.develrZcloudinit.handlersrrZcloudinit.helpersrZcloudinit.log.log_utilrZcloudinit.sourcesrZcloudinit.temp_utilsrZcloudinit.utilrrrxrryÚ ExceptionZnetplanrrrîZ getLoggerr,rÝZUSERDATA_SCHEMA_FILEZNETWORK_CONFIG_V1_SCHEMA_FILEZNETWORK_CONFIG_V2_SCHEMA_FILErÔrkÚkeysr8Ztyping_extensionsr(r)r*ršr2r=rtrDrGrHrIrJrBrLrRrVr/rcÚ ValueErrorrdrurr”r¡rrr¤rÓrÕr»rÂr×ràrrãrüZtimedr rr}rør.r9r=rArrUrZrhrlrnÚexitr"r"r"r%ÚsX      (         ÿ ÿÿÿÿö üû )ÿþ #'úú   ûû Hûû *V# üû _ùømû ú þ !ýü Hûú  ;þ }@