ó ¡ôXc@s(ddlZddlZddlZddlmZddlmZmZddl m Z ddl Z ddl m Z ddlmZddlmZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZddlZ de ee fd„ƒYZ!dS(iÿÿÿÿN(tArg(t ArgumentErrort ServerError(tFileTransferProgressBarMixin(t EC2Request(tDescribeConversionTasks(t S3AccessMixin(tImportManifesttImportImagePart(t DeleteObject(t HeadObject(t GetObject(t PutObject(tAWSErrort ResumeImportc BsþeZdZedddddƒedddedd ƒed d dd d eddddƒedddd edddejƒedd edejƒeddddejƒeddddejƒgZd„Z d„Z d„Z d„Z d„Z RS(s)Perform the upload step of an import tasktsourcetmetavartFILEthelps3file containing the disk image to import (required)s-ts--tasktrequireds.the ID of the import task to resume (required)s-xs --expirestDAYSttypetdefaultis\how long the import manifest should remain valid, in days (default: 30 days)s --part-sizetMiBi s--user-threadss--dont-verify-formattactiont store_trues --dry-runcCs_tj|ƒ|jƒ|jjdƒs9d|jddG|jdGHntj|d|jdgƒ}|jƒdd}|jdƒr|d}n|d d d}tjj|jd ƒ}|j ||ƒ}|j d j d }||krt dj |jd ||ƒƒ‚n|jdj|ddƒ\}}}tjjg|j D]} tjj| jƒ^qIƒ} x¤|j D]™} dj|| jfƒ} tj|d|jdd|jdd| ƒ} y| jƒWqwtk r} | jdkr |j| | | ƒq‚qwXqwWdS(Ntdry_runt show_progresssUploading image for taskttasktConversionTaskIdtconversionTasksit importVolumetimportInstancetvolumesRiÿÿÿÿis`file "{0}" is not the same size as the file the import started with (expected: {1}, actual: {2})t s3_servicetimagetimportManifestUrlt/tservicetauthts3_authtpathi”(RRtFalseRt from_othertmaint euca2oolstutilt get_filesizet%_ResumeImport__get_or_create_manifestt image_partstendRtformattresolve_url_to_locationt build_progressbar_label_templatetosR/tbasenametkeytjoinR R t status_codet_ResumeImport__upload_part(Rt desc_convR"t vol_containert file_sizetmanifesttfile_size_from_manifestt_tbuckettparttpbar_label_templatet part_s3paththead_reqterr((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyR2LsB     .cCsº|jdj|ddƒ\}}}dj||fƒ}ytjddƒx}tj|d|jdd|jd d |d |d tƒ}|jƒ|j j d ƒ|j dƒt j |ƒ} WdQXWnçtk rµ} | jdkr¯|j j dƒ|j||ƒ} tjƒ} tjj| tjj|ƒƒ} t| dƒ} | j| dtƒWdQXtj|d | d |d tƒ}|jƒtj| ƒtj| ƒq¶‚nX| S(NR(R)R*R+tmax_sizei R,R-R.RtdestR!s.using existing import manifest from the serverii”screating new import manifesttwt pretty_print(RR:R?ttempfiletSpooledTemporaryFileR R1R0R2tlogtinfotseekRtread_from_fileobjRR@t _ResumeImport__generate_manifesttmkdtempR<R/R=topentdump_to_fileobjtTrueR tremovetrmdir(RRCRDRGRHR>tmanifest_s3pathtmanifest_destfiletget_reqRERMttempdirtmanifest_filenamet manifest_filetput_req((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyt__get_or_create_manifestzs@        c CsO|jjdƒpd}|d}|jdj|ddƒ\}}}|jddƒd }td |jjƒ} |dd | _tj |d |jdd |jdddj ||fƒƒ} | j |ƒ| _ t |ddƒ| _t |ddƒ| _|jjdƒpdd} x)ttjjd || ƒƒD] \} } tƒ}| |_| |_t| | |ƒd|_dj|tjj|jdƒ| ƒ|_dj ||jfƒ}tj | d|ƒ}tj | d|ƒ}tj | d|ƒ} |j |ƒ|_ |j |ƒ|_!| j |ƒ|_"| j#j$|ƒq>W| S(NRii€QR(R)R*R+iitloglevelR9R,R-R.R/tsizetvolumet part_sizei iis{0}/{1}.part.{2}Ri(%RRR:trsplitRRTtlevelt file_formatR R1R?tget_presigned_url2tself_destruct_urltintt image_sizet volume_sizet enumeratetsixtmovestrangeRtindextstarttminR8R9R<R/R=R>R R thead_urltget_urlt delete_urlR7tappend(RRCRDtdaysttimeoutRGRHR>t key_prefixREt delete_reqRjRwt part_startRIt part_pathRLRa((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyt__generate_manifests>      %cCsë|jjd||j|jƒ|jdtjj|jƒd|j dƒ}t |j dƒ…}|j |jƒt j|d|j dd|j d d|d |d |j|jdd |j jd tƒd |ƒ}|jƒSWdQXdS(NsUploading part %s (bytes %i-%i)tfnameRwiRR,R(R-R.RORhR!tprogressbar_label(RTRURxR8R9R<R/R=R>RwRZRRVR R1RR0R2(RRIRKRJtpart_pbar_labelRRe((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyt __upload_part¾s % (t__name__t __module__t DESCRIPTIONRR\RptargparsetSUPPRESStARGSRR2R6RXRA(((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyR0s$   . # !("RŒtos.pathR<RRtrequestbuilderRtrequestbuilder.exceptionsRRtrequestbuilder.mixinsRRtteuca2ools.commands.ec2Rt.euca2ools.commands.ec2.describeconversiontasksRteuca2ools.commands.ec2.mixinsRt!euca2ools.commands.ec2.structuresRRt"euca2ools.commands.s3.deleteobjectR t euca2ools.commands.s3.headobjectR teuca2ools.commands.s3.getobjectR teuca2ools.commands.s3.putobjectR teuca2ools.exceptionsR teuca2ools.utilR3R(((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyts"