ó i'dWc@sdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZmZmZmZmZmZmZmZdd lmZmZmZm Z d efd „ƒYZ!dS(su instantiation.py - target instantiation checkpoint. Parses the Data Object Cache for physical and logical targets. iÿÿÿÿN(tcopy(tV_ROOT(t DKIOCSETWCE(tApplicationData(t InstallEngine(tAbstractCheckpoint(tTarget(tBEtDatasetOptionst FilesystemtOptionst PoolOptionstVdevtZvoltZpool(tDiskt GPTPartitiont PartitiontSlicetTargetInstantiationcBsƒeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z dd d „Z d „Z d „Zed „ZRS(s" class to instantiate targets cCs\tt|ƒj|ƒtƒ|_tƒ|_tƒ|_tƒ|_t|_ d|_ dS(Ns/system/volatile( tsuperRt__init__tlistt logical_listt physical_listt swap_listt dump_listtFalset live_installtwork_dir(tselftname((sinstantiation.pyR4s     cCsdS(sZ Returns an estimate of the time this checkpoint will take in seconds i((R((sinstantiation.pytget_progress_estimate?scCs5tjƒj|_|jjdtjdtdtƒd|_|jjdt ƒ|_ |jjdt ƒ|_ t ƒ|_t ƒ|_|jjdtƒ}|røxU|D]J}|jdkrÏ|jj|ƒn|jdkr§|jj|ƒq§q§Wn|jjjdtƒ}|r1|j|_|j|_ndS(s^ method for parsing data object cache (DOC) objects for use by the checkpoint Rt class_typetnot_found_is_erritswaptdumpN(Rt get_instancetdata_object_cachetdoctget_descendantsRtDESIREDtTruettargetRRRRRRRR tusetappendt persistenttget_first_childRRR(Rt zvol_listtzvoltapp_data((sinstantiation.pyt parse_docEs(     csx|jD]}|jrq n|jrátj|jtjtjBƒ}z†yF|jj d|j ƒt j dƒ}t j|tt j|ƒƒWn9tk rË}|jj dƒ|jj t|ƒƒnXWdtj|ƒXn|jdtƒ}|jdtƒ}|jdtƒ}t}t} |rÓt|ƒ} x›| D]} | jdkrntddt| ƒƒ‚n| jdkr†t} q<| jd kr´|j|j | ƒƒt} q<| jd kr<t}q<q<Wnt} |r…t|ƒ} x—| D]Œ}|jdkr td t|ƒƒ‚n|jdkr8t} qò|jd krf|j|j |ƒƒt} qò|jdkròt}qòqòWnt}t!ƒ}|ryt|ƒ}x…|D]}}|jdkrËt}nF|jd krù|j|j |ƒƒt}n|jdkrt}n|j"r­|j#|ƒq­q­Wt$d„|j%Dƒdƒ‰x,t&‡fd†|ƒD]}t'|_(qcWn| r•|j)||j*ƒn|j+dkr½|r½|j,|j*ƒn| rÙ|j-||j*ƒn|rõ|j.||j*ƒn|r |j/||j*ƒq q WdS(sg method used to parse the list of disks and create the desired physical configuration. senabling write-cache on %sisunable to enable write-cache:NR!sInvalid name for GPT s Partition: tcreatetdeletetpreservesInvalid name for Partition: tuse_existing_solaris2t use_existingcss!|]}|jr|jVqdS(N(tis_rootR(t.0trp((sinstantiation.pys Ðstrpoolcs |jˆkS(N(tin_zpool(tslc(trpn(sinstantiation.pytÒstVTOC(R6R7(R6R8(0Rt whole_diskt write_cachetostopentopathtO_RDWRtO_NDELAYtloggertdebugtctdtCtc_inttfcntltioctlRt addressoft ExceptiontstrtcloseR(RRRR*RRRtNonet RuntimeErrortactiontpoptindexRtis_swapR-tnextRtfilterRttagt_update_partition_tabletdry_runtlabelt _label_diskt_update_gptpartition_tablet_update_slicest_create_ufs_swap(Rtdisktfdtnumberterrtgptpartition_listtpartition_listt slice_listt label_disktupdate_gptpartition_tabletdup_gptpartition_listt gptpartitiontupdate_partition_tabletdup_partition_listt partitiont update_vtoctswap_slice_listtdup_slice_listR>((R?sinstantiation.pytsetup_physicalesš                        cCsb|jr^xR|jD]D}|jdkr|j|jƒ|jsW|j|jƒqWqqWndS(se method used to parse the dump (zvol) targets and create the objects marked 'create' R4N(RRVR4R^Rt add_to_system(RR$((sinstantiation.pyt create_dumpçs   cCsR|jrNxB|jD]4}|jdkr|jrG|j|jƒqGqqWndS(sf method used to parse the dump (zvol) targets and destroy the objects marked 'delete' R5R4N(sdeletescreate(RRVtexiststdestroyR^(RR$((sinstantiation.pyt destroy_dumpòs   cCsb|jr^xR|jD]D}|jdkr|j|jƒ|jsW|j|jƒqWqqWndS(se method used to parse the swap (zvol) targets and create the objects marked 'create' R4N(RRVR4R^RRv(RR#((sinstantiation.pyt create_swapüs   cCsR|jrNxB|jD]4}|jdkr|jrG|j|jƒqGqqWndS(s¶ method used to parse the swap (zvol) targets and destroy the objects marked 'delete' or 'create' (since 'create' has an implicit destroy associated with it) R5R4N(sdeletescreate(RRVRxRyR^(RR#((sinstantiation.pyt destroy_swaps   R=c Cs¦tƒ}xtttttgD]`}|jjd|ƒ}xBg|D]}|j|krA|^qAD]}|dks|dkr`|j|kr`t |tƒr¯|j |j ƒqxt |tƒrß|j |j j d|j ƒqxt |tƒr|j |j j d|j ƒqxt |tƒrxt |j tƒrT|j |j j j d|j ƒqu|j |j j d|j ƒqxq`q`WqW|dkr¢| r¢tdƒ‚n|S(sp method to extract all of the physical device names for a given zpool or vdev name from the DOC R!R=tin_vdevss%ssp%ss-in_vdev attribute requires in_zpool attribute(RRRRRR+R(R=R}t isinstanceR-RKtparentRRU( Rt zpool_namet vdev_nametin_typet vdev_listR!tdev_listtdtdev((sinstantiation.pytget_vdev_namess( / !!,cCsÖxÏ|jD]Ä}|jdkr2|j|jƒq |jdtƒ}|r€x3|D](}|jdkrQ|j|jƒqQqQWn|jdtƒ}|r x3|D](}|jdkrŸ|j|jƒqŸqŸWq q WdS(sº method used to parse the logical targets and destroy the objects with action of 'delete' or 'create' (since 'create' has an implicit destroy associated with it) R5R4R!N(sdeletescreate(sdeletescreate(sdeletescreate(RRVRyR^t get_childrenR R (Rtzpooltfs_listtfsR0R1((sinstantiation.pytdestroy_logicals5s  cCs®x§|jD]œ}|jr6|jjd|jƒq n|jdtƒ}|jdtƒ}tƒ}|r¦tƒ}x!|D]}|j |j ƒƒqyW|j |ƒn|rétƒ}x!|D]}|j |j ƒƒq¼W|j |ƒn|jdt ƒ}tƒ} |r–x›|D]~} | j j ƒdkrj| j j ƒdkrW| j ddgƒqj| j| j ƒn| j |j|j| jddƒƒqWn|j|jƒ} | |_d} |jrÞtjj|j|jƒ} n|jd kr |j|j|d | ƒn7|jd kr@|js@|j|j|d | ƒq@n|jdtƒ} x†g| D]!} | jjƒd kr\| ^q\D]V}|jd kr©|j|jƒq|jd kr|js×|j|jƒq×qqW|jdtƒ}|jdtƒ}tƒ}tƒ}tƒ}tƒ}x>|D]6}|jd ksX|jd kr*|j r*|rú|j dt!ƒ}|j"r±|r’|j"|j#d s   :"