i'dWc@s-dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl j j Z ddl j jZddlj jZddlj jZddlj jZddlj jZddljZddlmZddl mZmZddlmZmZm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/dd l(m0Z0dd l(m1Z1dd l(m2Z2dd l(m3Z3dd l(m4Z4ddl(m5Z5ddl(m6Z6ddl(m7Z7ddl(m8Z8ddl(m9Z9ddl(m:Z:ddl(m;Z;ddl(m<Z<ddl(m=Z=ddl(m>Z>ddl(m?Z?ddl(m@Z@ddlAmBZBdZCdZDeCe_EejFejGdejHddd e'fd!YZId"eIfd#YZJd$eIfd%YZKdS(&s:Transfer IPS checkpoint. Sub-class of the checkpoint classiN(tglobal_settings(tIMG_TYPE_ENTIREtIMG_TYPE_PARTIAL(tPKG5_API_VERSIONtPopentruntCalledProcessErrortINSTALL_SSL_DIR(t InstallEngine(tAbstractCheckpoint(tACTIONtCONTENTSt PURGE_HISTORYt APP_CALLBACKtIPS_ARGSt UPDATE_INDEXt REJECT_LIST(tArgs(tCA_Cert(tCert(t CmdOptions(tCred(t Destination(tFacet(tImage(tImType(tIPSSpec(tKey(tMirror(tOrigin(tProperty(t Publisher(tSoftware(tSource(t ProgressMonstransfer modules/etc/openssl/certsttpkgs/usr/share/localet AbstractIPScBseZdZejZdZdZdZdZ dZ dgZ dZ e jjZdZd Zd Zeed Zd Zd ZdZedZejdZdZdZdZdZ dZ!dZ"dZ#RS(s$Subclass for transfer IPS checkpoints'http://pkg.oracle.com/solaris11/releasei iit/tentirethosttcreatet use_existingtupdatec Cstt|j|d|_|j|_t|_d|_ i|_ t |_ t|_ ||_||_i|_i|_d|_d|_t|_d|_d|_t|_t|_g}|jry/tjdtj}|j|tj}Wq%tj k rtj!}q%Xn tj}t"j#|j$|}tj%d|}|j|tj&||_'d|_(g|_)g|_*g|_+g|_,g|_-g|_.g|_/i|_0i|_1t2|_3g|_4dS(Nit output_filet print_engine(5tsuperR%t__init__tNonetdsttCREATEt img_actiontFalsetindextsrct image_argsRt completenesstis_zonetzonenamet show_stdouttfacetst propertiest _credentialst distro_sizet give_progresstpmontapi_insttdry_runt _cancel_eventtprogresstFancyUNIXProgressTrackertsyststdouttappendtloggingtDEBUGtProgressTrackerExceptiontINFOt printenginetLoggingPrintEnginetloggertCommandLineProgressTrackertMultiProgressTrackert prog_trackert_publt_origint_mirrort _cmd_optionst _add_publt _add_origint _add_mirrort_add_cmd_optionst _image_argst _package_dicttlisttpublisher_listt_transfer_list( tselftnameR:R;ttrackersttrktlogleveltpe_trktlogt((sips.pyR/isX                                  cCsY|j|jd}x*|jD]}|t|jt7}q$W|j||jS(s+Compute the size of the transfer specified.i(t _parse_inputt_validate_inputR`tlentgetR t DEFAULT_SIZEtDEFAULT_PKG_NUM(Ratnum_pkgsttrans((sips.pytget_sizes   cCsQ|jdkr!|j|_ntt|j|j|j}t|_|S(sNReturns an estimate of the time this checkpoint will take. i(R?RptinttfloatRltDEFAULT_PROG_ESTtTrueR@(Ratprogress_estimate((sips.pytget_progress_estimates   cCs&t|_|jr"|jjndS(sCancel the transfer in progressN(RtRDRBtcancel(Ra((sips.pyRws  c Cs|jjd|jzhy|jr;|jjddn||_|j|j|jsn|jn|j |jsxg|j D]Y}|j t dkrx;|j t D]'}d|krtj|jt|jt|j}|jd|jdtd|j}|jjd|jdtd|j}|tjj s|tjj r_qn|tjjd}|tjjd}|j|jkr|jjd |jjd |j|jjd |jqqqWqqWn|jWntj k r#} t!|j"| nZtj#k r|} t$| sv|jjd t%j&t!d t'| j(nnXWd|j)XdS(sExecute method for the IPS checkpoint module. Will read the input parameters and perform the specified transfer. s=== Executing %s Checkpoint ===sBeginning IPS transferitinstallR't fmri_stringstlocalt info_neededsVersion mismatch: sInstaller build version: %ssTarget build version: %ssTraceback from pkg: %ssIPS operation failed: %sN(*RPtdebugRbR@treport_progressRCRhRitget_ips_api_instt _transferR`RkR R tapitImageInterfacet SYSTEM_IMAGERRSR4tSYSTEM_CLIENT_NAMEtinfotENT_PKGRtt INFO_NEEDEDRBt INFO_FOUNDtbranchtwarningtfmritcheck_cancel_eventt api_errorstCatalogRefreshExceptiont RuntimeErrortcatalog_failures_to_strt ApiExceptiontstrt tracebackt format_excttypet__name__t_cleanup( RaRCt trans_valR$tsysinsttinstaller_entire_infottarget_entire_infotinstaller_entire_pittarget_entire_pitcreterr((sips.pytexecutesp                      cCs tdS(s<This method is required to be implemented by all subclasses.N(tNotImplementedError(Ra((sips.pyRh1scCsH|jjd|jdkr.tdn|j|j|j|jfkretd|jn|jjd|j|jjd|j|j dkrt |_ |jjdn+|j dkrt |_ |jjd n|j r|jjd |j std qntd d ddg}t|jj}t||@}|rwtdt|n|jjd|j|_d}|j|jkr|jn$|j r|j r|jd}n|dkr%x;t|jD]'\}}|s|j|d}PqqWn|dk rDtd|ndS(s6Do whatever validation is necessary on the attributes.sValidating IPS inputs!IPS destination must be specifiedsThe IPS action is not valid: %ssDestination: %ssImage action: %stfullsImage Type: fulltpartialsImage Type: partialsImage Variant: zones7For images of type 'zone', a zonename must be provided.tprefixtrepo_uritoriginstmirrorssmThe following components may be specified with the source component of the manifest but are invalid as args: t progtrackisOnly the publisher being used for image creation can have its prefix auto-discovered, please specify the prefix for the publisher with the URI: %sN(RPR|R1R0t ValueErrorR3tEXISTINGR2tUPDATER8RRR9R:tsetR7tkeysR^RRkRStset_image_argsRCRTRUt enumerateRXRY(Rat not_allowedtimg_argstoverlaptinvalid_prefix_uritidxtelement((sips.pyRi6sN!        c) Cs>|j rY|jrY|jdkrYtd|j|_|jj|j|jddn|j|j krR|j rR|j rR|jj d|j jdt}|jjd|j|j jd|j r|j jd|j dt}|jj d|j |j}|j|jx|jD]}|j|q0W|jd:k rzx!|jD]}|j|q`Wn|j jd |d td tny|jrtjd |jd |j}ntjd |j}tj d|j d|}|j j!d |d td tx:|j jdtdD]}|j j"d|j#q/Wnxt$|j%D]\}}|j s|j jd| r/|jj d||j&|rtjd |j&|d |j'|}ntjd |j'|}tj d|d|}|j s |j j!d |d tq qb|jj d||j jd|dt}|j}|j'|rx7|j'|D]%}|j(|s|j|qqWn|j&|rx7|j&|D]%}|j)|s|j|qqWn|j jd |d tqbW|j sH|j jdt}t*} x|D]}|j}||j+kr|j+|} d| kr| dd|_,nd| kr| dd|_-qnt*} t*} |j.rx$|j.D]}| j/|j0qWn|j1rx$|j1D]}| j/|j0qWn| j/|j#| | fq?W| |_2n|j rd|jj dn|j3|j4r*|j r*|jj d|j j5} x|j4j6D]v}|dkr| j7d|j4|qt8|j4|t9r t:|j4||j4|r|j r|j j?dtnt}|j@rZx|j@D]}|jA}|rdd|jdg}|jB||j/|j |j r:|jj d|qStC|dd;t}qqWnxt$|j%D]\}}|jD|rjx|jD|D]}|jA}|rdd|jdg}|jB||j/||j r|jj d|q tC|dd<t}qqWqjqjW|rH tEjF|jtG|jHd:tI|_ nx|j>D]}|jJtKd!krS |j3|jJtL}|jJtMr |jjd"|j|jJtN}|r |jjd#x=|D]}|jjd$|q Wn|jj d%tOjP}|j s= |jJtQr] |j jRd&|jJtMd'||jJtQn"|j jRd&|jJtMd'||j jSr |j jTqR n|r ||j nt*}|j jU}xx|jVD]j\} }!}"}#}$|"jW r |"jX r q n| jY}%|j/|%|j jZ| |"j[d(td)tq W|r |jjd*|jjd+x!|D]}%|jjd,|%qw W|jjd-|jjd.n|j jUj\}|jj d/x'|D]\}!}&|jj d0|&q W|j j]|j j^|j jTt_j`d1qP |jj d2q n|jJtKd3kr |jj d4|j s tQ|kr |j ja|jJtM|jJtQn|j ja|jJtM|j j]|j j^|j jTq n|jJtKd5krr |jjd6|jJtM}'x!|'D]}|jjd$|q6 W|j s |j jb|'q n}|jJtKd7kr |jjd8|jJtM}(x!|(D]}|jjd$|q W|j s |j jb|(d7tq n|jJtcrR |jj d9|j s6|j j5} | jdjeq6qR qR Wd:S(=sIf an update of the image has been specified, the publishers of the existing image are examined. If a matching publisher is found, the origins and mirrors (if present) are reset to the desired entries. All other publishers in the image are removed and the new additional publishers are added. Then properties are set, if specified and the transfer specific operations of install, uninstall and purge history are performed. If creation of the image has been specified, the additional publishers are added to the image, properties are set and the transfer specific operations of install, uninstall and purge history are performed. iRPidsUpdating the publisherst duplicates#Setting post-install publishers to:Rs%Updating publisher information for %stpubtrefresh_allowedt search_firstRRt repositoryisAdding additional publisher %stkeytcrtsDry Run: publishers updatedsUpdating image propertiesspreferred-publishert:thttpstssl_keytssl_certt immediates /usr/bin/pkgs-Rs set-publishers Executing: %st check_resultiRxsInstalling packages from:s)Transfer set to reject packages matching:s %ss%Transfer reject package list is emptytpkg_listt reject_listt displayedtaccepteds<The following licenses have been accepted and not displayed.sCPlease review the licenses for the following packages post-install:s %-60ss1Package licenses may be viewed using the command:s pkg info --license sInstallation Plan:s %sR&sDry Run: Installing packagest uninstallsUninstalling packagestavoidsSetting packages to avoid:tunavoids%Removing packages from list to avoid:sPurging HistoryN(ii(ii(fR;R@R?R"RPRAt startmonitorR1R3RRTRCR|RBtget_publishersRtRtprint_repository_urist has_publishert get_publisherRt reset_originst reset_mirrorsRUt add_originRVR0t add_mirrortupdate_publisherR4t publishert RepositoryRt add_publishertremove_publisherRRRXRZRYt has_origint has_mirrorR^R>RRRRIturiRR_RR=timgRtset_highest_ranked_publishert isinstancetboolRt set_propertytsplitt update_originR`trefreshRWt get_arg_listtextendRR[RRRRStPKG_CLIENT_NAMERkR R R RtmisctEmptyIRt plan_installtplanned_nothingtodotresettdescribet get_licensest must_acceptt must_displaytget_nametset_plan_license_statustlicenset get_changestpreparet execute_plantostchdirtplan_uninstallt avoid_pkgsR thistorytpurge()Ratpub_listRRtorigintmirrortrepoRRtpub_list_for_printtcredt origin_urist mirror_urisRtpropt secure_pubt secure_repotpnamet updated_repoRRRt reget_apitoptionstarg_listtcmdRtcallbackRR$tlicensedtplantpfmrit_nonetdestt_none2t_none3Rtdest_pkgt avoid_listt unavoid_list((sips.pyRxs "                                                                               cCs|jr|jndS(sCheck to see if a cancel event of the transfer is requested. If so, cleanup changes made to the system and raise an exception. N(RDR(Ra((sips.pyRs cCs|jjd|jr>t|j_|jjd|_n|jr|jjdxK|jD]=}x4|j|D]%}|j||d}|jquWqaWndS(s/Method to perform any necessary cleanup needed.s Cleaning upsCleaning up credentialsiN( RPR|RARttdonetwaitR0R>tremove_credential(RatpublRtcred_obj((sips.pyRs     cCs!tj|j|_|j|jd<|jrP|jd k rP|j|jdt image_createR8R9RRRtparse_linked_nameR:tattach_linked_childRt exception(Ratips_errtallowtfnamet gz_api_insttlinRR((sips.pyR~sp  .  %(       cCsd}|d}x|jD]u\}}}|jj||x&|D]}|jj|d|qDWx&|D]}|jj|d|qmWqWdS(saprint_repository_uris() - simple method to print out the repository uris used it is origin: s mirror: Ns (R_RPR(Ratindenttindent2Rt origin_listt mirror_listRR((sips.pyR~s   ($Rt __module__t__doc__tabctABCMetat __metaclass__t DEF_REPO_URIRsRlRmRRRRt PackageInfot ALL_OPTIONSRR2RRR0R4R/RpRvRwRtabstractmethodRhRiRRRRR~R(((sips.pyR%Rs6   N  ^ B h    lt TransferIPScBspeZdZdZid d6dd6ZedZd dZdZdZ e d Z d Z d Z RS( sbIPS Transfer class to take input from the DOC. It implements the checkpoint interface. t,R:R4R;cCs|jd|jjd}|jd|jjd}|jdk}tt|j|d|d|g|_t|_t j j |_ |j j d|jdt|_t|jdkrtd|jndS(NR:R;RtRbt class_typeis<Only one value for Software node can be specified with name (Rkt DEFAULT_ARGt capitalizeR.RHR/R`tdictR>Rt get_instancetdata_object_cachet_doctget_descendantsRbR t soft_listRjR(RaRbtargt zonename_argtshow_stdout_arg((sips.pyR/s    c Cs|dk r|jdk rF|jdk rFtd|||fnd}|rjtjjt|}n|jd|}n|dkr|r||j kr|j |}||f||RI( RaRt cred_nametcred_extRtca_listt pub_ssl_pathtcredfilet cred_dict((sips.pyt _parse_creds    c Cs d|_g|_g|_g|_g|_g|_g|_g|_|j j d|j d}|j t jt dt}|dj tjtdtd}|jj|j|_|j tjt}|r|dj tjtdt}n t}t}xK|D]C}|j tjtdt}x|D]} | j tjtdt} | dk rt | dkr|j!| ddd|j"n| j t#jt#dt} | dk rt | dkr|j!| ddd|j"n| j t$jt$dt} | dk r9t | dkr9|j!| ddd|j"d|q9q9WqWt |rC|j j%d yx|D]} d | } | j&}t'j(|d t'j)}|j*j&d d}t+j,j-t.|d }t+j,j/|s~t+j0| |q~q~WWqCt1k r?}|j j2d|t1|qCXn|j3|_4|j5|_5|j6t7j8t7}|r|j9|_9t:|j;|_<nd|_9t|_<|j t=j>t=}x!|D]}|j?|j@|jARtmir_repot cmd_optionstentry((sips.pyt_set_publisher_infous\                cCs%|jjd|jtjt}t|dkrFtdnt|dkr|d}|jtjtdt }|j s|j d}|j |dt nxs|D]}|j |dt qWnO|j|jkr!|j s!|jg|_|jjd|jd|_q!ndS( sParse the DOC Source, filling in the local attributes for _publ, _origin, _mirror, _add_publ, _add_origin, _add_mirror. sReading the IPS sourceis*Only one IPS image source may be specifiediRaRs Origin Info: %sN(RPR|RcR!RhRjRRRiRtR9tpopRR4R3RRDRUR0RV(RaR~RR6RR((sips.pyRzs$     cCs|j}|j}t}|jd||fx7|jD],\}}|jd|jt|q<W|jr|j|jndj|S(sConvert a CatalogRefreshException into a formatted string. This is based on the IPS pkg/client.py display_catalog_failures() implementation. sAError refreshing publishers, %s/%s catalogs successfully updated:R#s (ttotalt succeededR^RItfailedRt errmessageRX(RaRRRtlinesRR((sips.pyRs      N(RR?R@tVALUE_SEPARATORR0RKR/R`RhR}R4RRzR(((sips.pyRHs   F $tTransferIPSAttrcBs eZdZdZdZRS(s5IPS Transfer class to take input from the attributes.cCsYtt|j|d|_d|_d|_t|_d|_ i|_ g|_ dS(N( R.RR/R0RqRRR4RRRR`(RaRb((sips.pyR/s      cCsd |_g|_g|_g|_g|_g|_g|_g|_t }|j j d|j r8|j d\|_|_|_}|j j d|jr|j j dt |jnx*|jD]}|j j dt |qW|jr*x-|jD]}|j j dt |qWn|ryxF|D];}t|}|j j dt ||jj|q7Wnx|j dD]}|\}} } }|r|j j d t |ng} | rxq| D]>}tjd |} | j| |j j dt |qWn(|jg} |j j dt |jg} | rxO| D]>}tjd |}| j||j j dt |qTWnd } g}|rxC|D]8}t|}|j j dt ||j|qWn|jj||jj| |jj| |jj|qWnI|j|jkr|jg|_|j j d t |jd |_n|j|t<|j|t<|j|t<|j|t<|j|t<|jst |j!t"sh         (4 =l