uUc@sYdZddlZddlZddlZddljZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)d Z*d!Z+d"Z,d#Z-d$Z.d%Z/d&Z0d'Z1d(Z2d)Z3d*Z4d+Z5d,Z6d-Z7d.Z8d/Z9d0Z:dZ;d1Z<d2Z=d3Z>d4Z?d5Z@d6ZAd7ZBd8ZCd9ZDd:ZEd;ZFd<ZGd=ZHd>ZId?ZJd@ZKdZLdAZMdBZNdCZOdDZPdEZQdFZRdGZSdHZTe ZUdIZVdJZWdKZXdLZYdMZZej[dNZ\dOZ]dPZ^ej_dQZ`ej_dRZaej_dSZbej_dTZcejdZeejfdUdVdWegjZhdXZidYZjdZZkd[Zld\Zmd]Znd^Zod_epfd`YZqdaepfdbYZrdcepfddYZsdS(es Utility class iN(tetree(tSYS_AI_MANIFEST_DTD(t ManifestError(tManifestParser(tminidom(tStringIOtactiontcreatetenabledtforcetin_vdevtin_zpooltis_roottis_swaptkeyt mountpointtnamet name_typetnoswaptnodumpt part_typet redundancytsetttypetusetvaltvaluetversiont whole_diskt ai_criteriatai_criteria_manifesttai_device_partitiont ai_instancet auto_installtbet destinationtdiskt disk_keywordt disk_nametdumptfacett filesystemt host_listtimagetinstancetlogicaltnet_address_listt partitiontpropertytproperty_grouptpropvaltrangetsc_embedded_manifesttservice_bundletservicetsizetslicetsoftwaret software_datatsourcetswapttargett value_nodetvdevtzpooltzvoltx86tsparctgenerics,/usr/share/auto_install/manifest/default.xmls+/usr/share/lib/xml/dtd/service_bundle.dtd.1trulestsysidcfgssc_profile.xmlsjs2ai-validationtjs2aitfiletline_numiiiitsolaris_install_js2ais/usr/share/localetfallbackcCs9tjjditjjtjdd6|d6dS(sOutput standard error messages%(prog)s: error: %(msg)s itprogtmsgN(tsyststderrtwritetostpathtbasenametargv(RM((s common.pyterrs cCs'tj||d||j|dS(sDGenerate log message at specified level. Increment error count Arguments: log_lvl - the log level report - the conversion report to add the error to message - the message to log extra_log_params - a dictionary that contains the key LOG_KEY_FILE and LOG_KEY_LINE_NUM textraN(tLOGGERtlogtgenerate_error(tlog_lvltreporttmessagetextra_log_params((s common.pyRYs cCs-|j|}t|dkr)|dSdS(shPerform a xpath search from start_node and return first node found. Returns None if none found iN(txpathtlentNone(t start_nodeRRtnodes((s common.pytfetch_xpath_nodescCs=tjdt}tj|dt}tjt||S(s'Return a copy of the passed in xml treetremove_blank_textt pretty_print(Rt XMLParsertTruettostringtparseR(ttreetparsertcopy((s common.pyt tree_copyscCstjj|ryZtjj|r7tj|n4tjj|rYtj|ntt dWqtt fk r}tt di|d6|d6qXndS(sRemove specified file or directory. If path specified is not a file or a directory an IOError is raised since files and directories are the only types of output files generated by js2ai snot a file or directorys#Failed to delete %(path)s, %(msg)s RRRMN( RQRRtexiststisdirtshutiltrmtreetisfiletremovetIOErrort_tOSError(RRRM((s common.pyRss c Cs|dk rvtjj||}tjj|s|ytj|Wqstk ro}ttd|qsXq|n|}t|d2}|dk r|j t j |dt nWdQXdS(s$Write out the xml document to a filesFailed to create directory: %s twReN( R`RQRRtjoinRntmakedirsRtRutopenRPRRhRg(txml_treetdest_dirtfilenamet output_fileRMt file_handle((s common.pytwrite_xml_datas   c Cs|t}|r%tdi|d6GHnytj|tjrtjj||}td|dtd|}tt _ |j ddtt _ nt td|Wntk rw} t}|jdd \} } | d7} tjj|| } t| jd } ytj| tjr5tj| nt| d d}|jtdi|d6|jtdx)| D]!}|j|jd|qWWdQXWnct k rttdi| d6tjjtdx"| D]}tjj|qWnX|sxtjttj}|jtjd|jtjtdi|d6|d6| d6qxnX|S(sBValidate the generated manifest/profile based on the specified dtdsValidating %(manifest)stmanifestsmanifest-parsertvalidate_from_docinfotdtd_filetdocsfile does not exist: %s t.it _validations.logs : sw+s8NOTE: The errors outputed in this file must be manually corrected before the resulting file can be used by the Solaris automated installer. For information on the generated errors see installadm(1M) man page. Once the errors have been corrected you can validate your changes via: # js2ai -V %(manifest_file)s t manifest_filesValidation Errors: s%s Ns&failed to create log file: %(logfile)stlogfilesValidation failed: RsI%(profile)s: validation of %(manifest)s failed. For details see %(logf)s tprofiletlogfs_validation.log( RgRuRQtaccesstF_OKRRRxRtFalsetloggingtraiseExceptionsRiR`RtRtrsplittstrtsplitRsRzRPtadd_validation_errorRURNROterrsvct ErrorInfot ERR_VAL_MODIDtES_ERRtset_error_datatES_DATA_FAILED_ATtES_DATA_FAILED_STR(t profile_namet manifest_pathtmanifest_filenamet dtd_filenametconversion_reporttverbosetis_validRt mani_parserterr_msgtlog_namet_endingtlog_filet err_linestf_handletlinet error_info((s common.pytvalidates^              t ProfileDatacBs_eZdZdZedZedZedZejdZdZ RS(s,Contains the contents of a jumpstart profilecCs||_i|_d|_dS(N(t_namet_dataR`t _conv_report(tselfR((s common.pyt__init__'s  cCs|jS(sName of this profile(R(R((s common.pyR,scCs|jS(sDictionary of keys & values contained in profile. May be None if the profile could not be read. The key is the line # in the file (R(R((s common.pytdata1scCs|jS(s2Report of all errors encountered during processing(R(R((s common.pyR8scCs ||_dS(sSet the conversion reportN(R(RR[((s common.pyR=scCs3dt|jdt|jdt|jS(s$Return object in print friendly formsname s, data=s , values: (RRRR(R((s common.pyt__str__Bs( t__name__t __module__t__doc__RR0RRRtsetterR(((s common.pyR$s t KeyValuescBsMeZdZdZedZedZedZdZRS(sKey/Value objectcCs||_||_||_dS(N(t_keyt_valuest _line_num(RRtvaluesRI((s common.pyRKs  cCs|jS(s'Return string, key identifer for object(R(R((s common.pyRPscCs|jS(s;Return List of string of the values associated with the key(R(R((s common.pyRUscCs|jS(s_Return the line # that this rule key value combination was in the rule file (R(R((s common.pyRIZscCs3dt|jdt|jdt|jS(s$Return object in print friendly formsline s, key=s , values: (RRIRR(R((s common.pyRas( RRRRR0RRRIR(((s common.pyRHs  tConversionReportcBs%eZdZddddddZdZdZdZdZdZdZ e d Z e d Z e d Z e d Ze d Ze jdZ e jdZ e jdZ ejdZejdZdZdZdZdZRS(s7Contains the error counts that occurred during the various phases of the conversion process. Process errors refers to errors that occur when the various entities are read in. Conversion errors refers to errors that occur when converting items from the Solaris 10 nomiclature to Solaris 11 unsupported items refers to items that can not be converted. NOTE: Conversion errors and unsupported items will have a value of None if there is a processing error that prevents the file from being read icCsl||_||_||_||_||_i|jt6|jt6|j t 6|j t 6|j t6|_dS(N(t _process_errst_conversion_errst_unsupported_itemst_validation_errst _warningstadd_process_errort LVL_PROCESStadd_unsupported_itemtLVL_UNSUPPORTEDtadd_conversion_errortLVL_CONVERSIONRtLVL_VALIDATIONt add_warningt LVL_WARNINGt_log_lvl_convert_to_method(Rt process_errstconversion_errstunsupported_itemstvalidation_errstwarnings((s common.pyRvs         cCs*||jkr |j|ntdS(sjGiven a log level, add an error to the report associated with the specified log level N(Rt ValueError(Rt log_level((s common.pyRYscCs.|jdkrd|_n|jd7_dS(s*Increments the # of processing errors by 1iN(RR`(R((s common.pyRs cCs.|jdkrd|_n|jd7_dS(s*Increments the # of conversion errors by 1iN(RR`(R((s common.pyRs cCs.|jdkrd|_n|jd7_dS(s*Increments the # of unsupported items by 1iN(RR`(R((s common.pyRs cCs.|jdkrd|_n|jd7_dS(s*Increments the # of validation errors by 1iN(RR`(R((s common.pyRs cCs.|jdkrd|_n|jd7_dS(s!Increments the # of warnings by 1iN(RR`(R((s common.pyRs cCs|jS(sReturns the # of process errors(R(R((s common.pytprocess_errorsscCs|jS(s"Returns the # of conversion errors(R(R((s common.pytconversion_errorsscCs|jS(s"Returns the # of unsupported items(R(R((s common.pyRscCs|jS(s"Returns the # of validation errors(R(R((s common.pytvalidation_errorsscCs|jS(sReturns the # of warnings(R(R((s common.pyRscCs ||_dS(s-Set the # of processing errors to error_countN(R(Rt error_count((s common.pyRscCs ||_dS(s-Set the # of conversion errors to error_countN(R(RR((s common.pyRscCs ||_dS(s-Set the # of unsupported items to unsupportedN(R(Rt unsupported((s common.pyRscCs ||_dS(s+Set the # of validation_errs to error_countN(R(RR((s common.pyRscCs ||_dS(s&Set the # of warnings to warning_countN(R(Rt warning_count((s common.pyRscCsd}|jdk r!|j}n|jdk r@||j7}n|jdk r_||j7}n|jdk r~||j7}n|S(skReturn the # of errors associated with this report. Warnings are not considered errors iN(RR`RRR(Rterrs((s common.pyRs cCs|jrtStSdS(ssReturns boolean, True if there are any process errors, conversion errors, or unsupported items N(RRgR(R((s common.pyt has_errorss cCs t|jS(s@Returns boolean, True if there are any warnings, False otherwise(tboolR(R((s common.pyt has_warningsscCsXdit|jd6t|jd6t|jd6t|jd6t|jd6S(s(A printable representation of this classsprocess errors: %(process)s, warnings: %(warnings)s, conversion errors: %(conversion)s, unsupported items: %(unsupported)s, validation errors: %(validation)stprocessRt conversionRt validation(RRRRRR(R((s common.pyRs (RRRRRYRRRRRR0RRRRRRRRRR(((s common.pyRgs.         (tRtgettextRRQtsolaris_install.errsvcRRpRNtlxmlRtsolaris_installRtsolaris_install.manifestRtsolaris_install.manifest.parserRtxml.domRRtATTRIBUTE_ACTIONtATTRIBUTE_CREATEtATTRIBUTE_ENABLEDtATTRIBUTE_FORCEtATTRIBUTE_IN_VDEVtATTRIBUTE_IN_ZPOOLtATTRIBUTE_IS_ROOTtATTRIBUTE_IS_SWAPt ATTRIBUTE_KEYtATTRIBUTE_MOUNTPOINTtATTRIBUTE_NAMEtATTRIBUTE_NAME_TYPEtATTRIBUTE_NOSWAPtATTRIBUTE_NODUMPtATTRIBUTE_PART_TYPEtATTRIBUTE_REDUNDANCYt ATTRIBUTE_SETtATTRIBUTE_TYPEt ATTRIBUTE_USEt ATTRIBUTE_VALtATTRIBUTE_VALUEtATTRIBUTE_VERSIONtATTRIBUTE_WHOLE_DISKtELEMENT_AI_CRITERIAtELEMENT_AI_CRITERIA_MANIFESTtELEMENT_AI_DEVICE_PARTITIONINGtELEMENT_AI_INSTANCEtELEMENT_AUTO_INSTALLt ELEMENT_BEtELEMENT_DESTINATIONt ELEMENT_DISKtELEMENT_DISK_KEYWORDtELEMENT_DISK_NAMEt ELEMENT_DUMPt ELEMENT_FACETtELEMENT_FILESYSTEMtELEMENT_HOST_LISTt ELEMENT_IMAGEtELEMENT_INSTANCEtELEMENT_LOGICALt ELEMENT_NAMEtELEMENT_NET_ADDRESS_LISTtELEMENT_PARTITIONtELEMENT_PROPERTYtELEMENT_PROPERTY_GROUPtELEMENT_PROPVALt ELEMENT_RANGEtELEMENT_SC_EMBEDDED_MANIFESTtELEMENT_SERVICE_BUNDLEtELEMENT_SERVICEt ELEMENT_SIZEt ELEMENT_SLICEtELEMENT_SOFTWAREtELEMENT_SOFTWARE_DATAtELEMENT_SOURCEt ELEMENT_SWAPtELEMENT_TARGETt ELEMENT_VALUEtELEMENT_VALUE_NODEt ELEMENT_VDEVt ELEMENT_ZPOOLt ELEMENT_ZVOLtARCH_X86t ARCH_SPARCt ARCH_GENERICtDEFAULT_AI_FILENAMEtDEFAULT_AI_DTD_FILENAMEtDEFAULT_SC_PROFILE_DTD_FILENAMEtRULES_FILENAMEtSYSIDCFG_FILENAMEtSC_PROFILE_FILENAMERt getLoggerRWt LOG_KEY_FILEtLOG_KEY_LINE_NUMtERRORRRRRtWARNINGRt translationRgRuRURYRcRmRsRRtobjectRRR(((s common.pyts                 F$