Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyo
�
��Xc@s(ddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlZddlm
Z
ddlmZddlmZddlmZmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlZ de
ee
fd��YZ!dS(i����N(tArg(t
ArgumentErrortServerError(tFileTransferProgressBarMixin(t
EC2Request(tDescribeConversionTasks(t
S3AccessMixin(tImportManifesttImportImagePart(tDeleteObject(t
HeadObject(t	GetObject(t	PutObject(tAWSErrortResumeImportc
Bs�eZdZeddddd�edddedd	�ed
dddd
edddd�edddd
edddej�edd
edej�eddddej�eddddej�gZd�Z	d�Z
d�Zd�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|jd<n|jddkr[td��ndS(Ntexpiresiis-argument -x/--expires: value must be positive(Rt	configuretconfigure_s3_accesstargstgetR(tself((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyRCs

c	Cs|jjd�rdS|jjdt�r>dG|jdGHntj|d|jdg�}|j�dd}|jd�r�|d}n|d	d
d}tjj|jd�}|j	||�}|j
djd
}||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_manifesttimage_partstendRtformattresolve_url_to_locationt build_progressbar_label_templatetosR/tbasenametkeytjoinR
R
tstatus_codet_ResumeImport__upload_part(Rt	desc_convR"t
vol_containert	file_sizetmanifesttfile_size_from_manifestt_tbuckettparttpbar_label_templatetpart_s3paththead_reqterr((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyR2LsB


	.cCs�|jdj|dd�\}}}dj||f�}y�tjdd��x}tj|d|jdd|jd	d
|d|dt�}|j�|j	j
d
�|jd�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?ttempfiletSpooledTemporaryFileRR1R0R2tlogtinfotseekRtread_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@


	

cCsO|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:trsplitRRTtleveltfile_formatR	R1R?tget_presigned_url2tself_destruct_urltintt
image_sizetvolume_sizet	enumeratetsixtmovestrangeRtindextstarttminR8R9R<R/R=R>R
Rthead_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_manifest�s>

 			%cCs�|jjd||j|j�|jdtjj|j�d|j	d�}t
|jd���}|j|j�t
j|d|jdd|jd	d|d
|d|j|jdd|jjd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__tDESCRIPTIONRR\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.getobjectRteuca2ools.commands.s3.putobjectRteuca2ools.exceptionsR
teuca2ools.utilR3R(((sG/usr/lib/python2.7/site-packages/euca2ools/commands/ec2/resumeimport.pyt<module>s"