Current File : //usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyo
�
��Xc@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlZddlZddlZddlmZmZmZmZddlmZddlmZddlmZddlmZdd	lm Z dd
l!m"Z"ddl#m$Z$dd
dZ%de&fd��YZ'de&fd��YZ(de&fd��YZ)d�Z*d�Z+dS(i����N(tArgtMutuallyExclusiveArgList(t
ArgumentError(tb64encoded_file_contentstdelimited_listtfilesizetmanifest_block_device_mappings(tDescribeServiceCertificates(tCheckBucket(tCreateBucket(t	GetObject(t
PostObject(t	PutObject(tAWSErrori
iitBundleCreatingMixincBsreZedddddedd�edddd	�ed
ddddd
�edddeddOdd�edddddd�edddddd�eddddd�ed d!dd"dd#�ed$dd%dd&�ed'dd%dd(�ed)d*dPdd+�ed,d*dPdej�ed-d*dPdej�ed.d/dd0d1edd2�ed3dd4d1ed5�d6gdd7�ed8ddQd6d9dej�ed<d1e	dd=�ed>d1e	d6d?dej�ed@d1dA�dej�edBd1dC�dej�edDdEdFdej�gZ
dG�ZdH�ZdI�Z
dJ�ZdK�ZdL�ZedM�ZedN�ZRS(Rs-is--imagetmetavartFILEtrequiredthelps.file containing the image to bundle (required)s-ps--prefixs�the file name prefix to give the
                bundle's files (required when bundling stdin; otherwise
                defaults to the image's file name)s-ds
--destinationtDIRs�location to place
                the bundle's files (default:  dir named by TMPDIR, TEMP, or TMP
                environment variables, or otherwise /var/tmp)s-rs--archtchoicesti386tx86_64tarmhftppctppc64tppc64les#the image's architecture (required)s-ks--privatekeys�file containing
                your private key to sign the bundle's manifest with.  If one
                is not available the bundle will not be signed.s-cs--certs�file containing
                your X.509 certificate.  If one is not available it
                will not be possible to unbundle the bundle without
                cloud administrator assistance.s	--ec2certs�file containing the
                cloud's X.509 certificate.  If one is not available
                locally it must be available from the bootstrap
                service.s-us--usertACCOUNTsyour account IDs--kerneltIMAGEsKID of the kernel image to
                associate with this machine images	--ramdisksLID of the ramdisk image
                to associate with this machine images--bootstrap-urltroute_tos|[Eucalyptus
                only] bootstrap service endpoint URL (used for obtaining
                --ec2cert automaticallys--bootstrap-services--bootstrap-auths-Bs--block-device-mappingss%VIRTUAL1=DEVICE1,VIRTUAL2=DEVICE2,...ttypes`block device mapping scheme with which to launch
                instances of this machine images--productcodessCODE1,CODE2,...t,tdefaults3comma-separated list of product codes for the images--image-typetmachinetkerneltramdisks--image-sizes?the image's size
                (required when bundling stdin)s--part-sizei�s	--enc-keycCs
t|d�S(Ni(tint(ts((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt<lambda>wss--enc-ivcCs
t|d�S(Ni(R$(R%((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR&yss--batchtactiont
store_truecCsD|jjd�s�|jjd�}dtjkr\|jjd�tjd�|jd<q�|r�|jjd�||jd<q�n|jjd�r�|jdj	dd�|jd<n|jjd�s�t
d��n|jjd	|jd�|jjd
�s�|jjd�}dtjkrQ|jjd
�tjd�|jd
<q�dtjkr�|jjd
�tjd�|jd
<q�|r�|jjd�||jd
<q�n|jjd
�rtjjtjj
|jd
��|jd
<t|jd
d�n|jjd|jjd
��|jjd�s�|jjd�}dtjkr�|jjd�tjd�|jd<ndtjkr�|jjd�tjd�|jd<q�|r�|jjd�||jd<q�n|jjd�r8tjjtjj
|jd��|jd<t|jdd�n|jjd|jjd��|jjd�s�|jjd�}dtjkr�|jjd�tjd�|jd<q�|r�|jjd�||jd<q�|jjd�r�|jjd�r�y$|j|jd|jd�}Wn`tk
r�}|jjd d!t�|jjd"krdd#}nd$}tjt
|�|�nX|r�|jjd%�||jd<q�q�n|jjd�rtjjtjj
|jd��|jd<t|jdd&�n|jjd�s&t
d'��n|jjd(|jd�dS()Ntusers
account-idtEC2_USER_IDs!using account ID from environments#using account ID from configurationt-ts1missing account ID; please supply one with --usersaccount ID: %stcerttcertificatetEC2_CERTs"using certificate from environmentt	EUCA_CERTs$using certificate from configurationsuser certificatescertificate: %st
privatekeysprivate-keytEC2_PRIVATE_KEYs"using private key from environmenttEUCA_PRIVATE_KEYs$using private key from configurationsprivate keysprivate key: %stec2certtEUCALYPTUS_CERTs(using cloud certificate from environments*using cloud certificate from configurationtbootstrap_servicetbootstrap_authsfailed to fetch ec2certtexc_infoi�s�permission error retrieving cloud certificate; please supply one with --ec2cert or obtain an IAM policy that allows "euserv:DescribeServiceCertificates"sDerror retrieving cloud certificate; please supply one with --ec2certs.using cloud certificate from bootstrap servicescloud certificates}missing cloud certificate; please supply one with --ec2cert or use --bootstrap-url and access keys to fetch one automaticallyscloud certificate: %s(targstgettconfigtget_user_optiontostenvirontlogtdebugtgetenvtreplaceRtpatht
expandusert
expandvarst_assert_is_filetget_region_optiont,_BundleCreatingMixin__get_bundle_certificateR
tTruetresponsetstatus_codetsixt
raise_from(tselft
config_valtfetched_certterrtmsg((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytconfigure_bundle_creds�s�#
	cCs�|jjd�rdtjj|jd�rdtjj|jd�rdtdj|jd���n|jddkr�tjtj	t
jj���|jd<|jjd�s�td��n|jjd�s�td��q�n�t
|jdtj�r�|jjd�s2tjj|jd�|jd<n|jjd�sgtjj|jd�|jd<nt|jd�|jd<nB|jjd�s�td	��n|jjd�s�td
��n|jdtkr�|jjd|jdt�ndS(Ntdestinations3argument -d/--destination: '{0}' is not a directorytimageR+tprefixs1argument --prefix is required when bundling stdint
image_sizes5argument --image-size is required when bundling stdins9argument --prefix is required when bundling a file objects=argument --image-size is required when bundling a file objects8image is incompatible with EC2 due to its size (%i > %i)(R9R:R=RCtexiststisdirRtformattfdopentduptsyststdintfilenot
isinstanceRLtstring_typestbasenamet	euca2oolstutiltget_filesizetopentEC2_BUNDLE_SIZE_LIMITR?twarn(RN((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytconfigure_bundle_output�s8	(#		cCsl|jjd�dkr(d|jd<n|jjd�dkrPd|jd<n|jddkr�|jjd�r�|jddkr�td��n|jjd�r�td��n|jjd�r�td��q�n|jddkrh|jjd�rtd	��n|jjd�rD|jddkrDtd
��n|jjd�rhtd��qhndS(NR"ttruet
image_typeR#s:argument --kernel: not compatible with image type 'kernel's;argument --ramdisk: not compatible with image type 'kernel'tblock_device_mappingssLargument -B/--block-device-mappings: not compatible with image type 'kernel's;argument --kernel: not compatible with image type 'ramdisk's<argument --ramdisk: not compatible with image type 'ramdisk'sMargument -B/--block-device-mappings: not compatible with image type 'ramdisk'(R9R:R(RN((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytconfigure_bundle_propertiess$%%cCs�tj�}|jjd�r>|jjd�|jd}n|jd�}|jjd�r|jjd�|jd}n|jd�}dj|�|jd<dj|�|jd<dS(Ntenc_keys using preexisting encryption keyi�tenc_ivsusing preexisting encryption IVs	{0:0>32x}(trandomtSystemRandomR9R:R?tinfotgetrandbitsRZ(RNtsrandt	enc_key_itenc_iv_i((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytgenerate_encryption_keyssc
Cs�|jjd�td|jd|jjd|d|dddd	�}|j�}x�|jd
�pggD]�}|jd�dkrh|jd
�dkrhtjdt	�}|j
|d�|jj�|j
|jd<tjtj|j
�|j
SqhWdS(Ns=attempting to obtain cloud certificate from bootstrap serviceR;tlogleveltservicetauthtFormattpemtFingerprintDigestsSHA-256tserviceCertificatestcertificateUsagesimage-bundlingtserviceTypetcomputetdeleteR.R4(R?RrRR;tleveltmainR:ttempfiletNamedTemporaryFiletFalsetwritetfiletflushtnameR9tatexittregisterR=tremove(RNR6R7treqRJR-t	cert_file((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt__get_bundle_certificate.s
cCsQtjjjd|jj�}|jd|_|jjd�|_	|jjd�|_
|jjd�r�|jj|jd�n|jjd�r�|j
j|jd�n|jd|_|jd|_|jd	|_||_d
|_|jd|_td�|D��|_|jd
|_|jd|_d|_||_|S(NRxtarchR"R#RltproductcodesRVR)RktSHA1RWcss|]}|jVqdS(N(tsize(t.0tpart((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pys	<genexpr>SsRnRosAES-128-CBC(RctbundletmanifesttBundleManifestR?R�R9t
image_archR:t	kernel_idt
ramdisk_idRltupdatet
product_codestextendt
image_namet
account_idRktimage_digesttimage_digest_algorithmRWtsumtbundled_image_sizeRnRot
enc_algorithmtimage_parts(RNtdigesttpartinfoR�((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytbuild_manifestBs,					c	Cs8t|d��#}|j|j|d|��WdQXdS(Ntwtpretty_print(RfR�tdump_manifest_to_str(RNR�tfilenameR�t
manifest_file((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytdump_manifest_to_fileZscCs.|j|jd|jd|jdd|�S(NR1R-R4R�(tdump_to_strR9(RNR�R�((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR�_s
(RRRRRRN(smachineskernelsramdisk(t__name__t
__module__RRItNonetargparsetSUPPRESSRRRtARGSRSRiRmRwRHR�R�R�R�(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR9sd
				b	"				tBundleUploadingMixincBseZedddddedd�eddd	d
d)dd
�eeddddddejdd�eddddddedd��eddddd�eddd�edddddd d!dd"dd#�gZd$�Z	d%�Z
d&�Zed'�Z
d*d*d(�ZRS(+s-bs--bucketRsBUCKET[/PREFIX]RRs)bucket to upload the bundle to (required)s--aclR s
aws-exec-readRspublic-readsec2-bundle-readsQcanned ACL policy to apply to the bundle (default:
                aws-exec-read)s--upload-policytdestt
upload_policytPOLICYRs&upload policy to use for authorizations--upload-policy-fileRsMfile containing an upload policy to use for
                    authorizations--upload-policy-signaturet	SIGNATUREsYsignature for the upload policy (required when an
                'upload policy is used)s
--locations�location constraint of the destination
                bucket (default: inferred from s3-location-constraint in
                configuration, or otherwise none)s--retrytretriesR'tstore_consttconstiis"retry failed uploads up to 5 timescCsm|jjd�ri|jjd�s3td��n|jjd�sTtd��nd|_d|_ndS(NR�tkey_ids:-I/--access-key-id is required when using an upload policytupload_policy_signaturesA--upload-policy-signature is required when using an upload policy(R9R:RR�Rzt
AUTH_CLASS(RN((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytconfigure_bundle_upload_auth}s	cCsN|jdjd�\}}}|rB|jd�rB|d7}n|d|S(Ntbuckett/(R9t	partitiontendswith(RNR�t_RV((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytget_bundle_key_prefix�s
cCs�|jjd�r&|jjd�dS|jdjdd�d}y#tj|d|�}|j�Wnltk
r�}|j	dkr�|jjd|�t
j|d|d	|jjd	��}|j�q��nXdS(
NR�s6using an upload policy; not verifying bucket existenceR�R�iii�screating bucket '%s'tlocation(R9R:R?RrtsplitRt
from_otherR�R
RKR	(RNR�R�RQ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytensure_dest_bucket_exists�s!
cKs"|jjd�r�|r$|GdGHn|jjd�rMi|jdd6}ni}|j|�tj|d|d|d|jjd�p�dd	|jdd
|jdd|jd
|�}nTtj|d|d|d|jjd�p�dd|jjd�pdd||�}|j�dS(NR�suploading...tsecurity_tokensx-amz-security-tokentsourceR�tacls
aws-exec-readtPolicyt	SignatureR�tAWSAccessKeyIdR�R�it
show_progress(R9R:R�RR�RR�(RNR�R�R�t
putobj_kwargstpostobj_kwargsR�((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytupload_bundle_file�s&


cKs�z�y�xztr�|j�}|tjj|j�}|j|j||�|dk	rc|j�n|dk	r	|j	|�q	q	WWnt
k
r�dSXWd|j�|dk	r�|j�nXdS(N(RItrecvR=RCRbR�R�R�treleasetsendtEOFErrortclose(RNtpartinfo_in_mpconnt
key_prefixtpartinfo_out_mpconntpart_write_semR�R�R�((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytupload_bundle_parts�s	

	
(spublic-reads
aws-exec-readsec2-bundle-readN(R�R�RRIRtbase64t	b64encodeRR�R�R�R�R�R�R�R�(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR�es.						tBundleDownloadingMixincBs�eZedddddedddd�eedd	d
ddddd�ed
dd
ddddd�dd�edd
ddddddd��j�gZdd�Zd�Z	d�Z
d�Zd�Zd�Z
RS(s-bs--bucketRsBUCKET[/PREFIX]RRRs\the bucket that contains the bundle,
                with an optional path prefix (required)s-ms
--manifestR�R�slthe manifest's complete file name, not including
                    any path that may be specified using -bs-ps--prefixRcCs|dS(Ns
.manifest.xml((tx((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR&�ssYthe portion of the manifest's file name that
                    precedes ".manifest.xml"s--local-manifesttlocal_manifestRsSuse a manifest on disk and ignore
                    any that appear on the servercCs9|jjd�rIt|jdd�tjjjj|jdd|�S|j�}t	j
���}|jjd|�t
j|d|d|d|�}y|j�WnStk
r�}|jdkr�|jjd	d
t�tdj|���n�nX|j�|jd�tjjjj|d|�SWdQXdS(
NR�R�tprivkey_filenamesreading manifest from %sRyR�R�i�sfailed to fetch manifestR8s+manifest '{0}' does not exist on the serveri(R9R:RFRcR�R�R�tread_from_filetget_manifest_s3pathR�t
TemporaryFileR?RrR
R�R�R
RKR@RIt
ValueErrorRZR�tseektread_from_fileobj(RNt
s3_serviceR�tmanifest_s3pathtmanifest_tempfileR�RQ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytfetch_manifest�s,		

cCs;|jjd�r3dj|jd|jdf�SdSdS(NR�R�R�(R9R:tjoinR�(RN((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR�s!c
CsL|j|�}x�|D]�\}}tjj|tjj|��|_|jjd||j�tj	|d|d|d|jd|j
jdt��}|j
�}|j|||�qW|j�}	|	rHtjj|tjj|	��}
|jjd|	|
�tj	|d|d|	d|
d|j
jdt��}|j
�|
SdS(Nsdownloading part %s to %sRyR�R�R�sdownloading manifest %s to %s(tmap_bundle_parts_to_s3pathsR=RCR�RbR�R?RrR
R�R9R:R�R�t(_BundleDownloadingMixin__check_part_sha1R�R�(RNR�tdest_dirR�tpartsR�tpart_s3pathR�RJR�t
manifest_dest((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytdownload_bundle_to_dirs2
	

c	
Cs�|j|�}x||D]t\}}|jjd|�tj|d|d|d|d|jjdt��}|j�}|j	|||�qWdS(Nsdownloading part %sRyR�R�R�(
R�R?RrR
R�R9R:R�R�R�(	RNR�tfileobjR�R�R�R�R�RJ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytdownload_bundle_to_fileobj/scCsJg}x=|jD]2}|j|dj|jd|jf�f�qW|S(NR�R�(R�tappendR�R9R�(RNR�R�R�((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR�<s
	'cCsb||d|jkr^|jjd|j||d�tdj|j||d���ndS(Ntsha1sKrejecting download due to manifest SHA1 mismatch (expected: %s, actual: %s)sJdownloaded file {0} appears to be corrupt (expected SHA1: {0}, actual: {1}(t	hexdigestR?terrortRuntimeErrorRZ(RNR�R�RJ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt__check_part_sha1Cs	N(R�R�RRIR�RRR�R�R�R�R�R�R�(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR��s$
				
	cCs^tjj|�s-tdj||���ntjj|�sZtdj||���ndS(Ns{0} file '{1}' does not exists{0} file '{1}' is not a file(R=RCRXRRZtisfile(R�tfiletype((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyRFNs		cCs8tjddtjdtj�}|j|�dj�S(	Ntopenssltx509s-fingerprints-nooutR^tstdouti(RRs-fingerprints-noout(t
subprocesstPopentPIPEtcommunicatetstrip(tcert_contenttpopen((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt_get_cert_fingerprintWs(,R�R�R�tos.pathR=RpRR]R�trequestbuilderRRtrequestbuilder.exceptionsRRLteuca2ools.bundle.manifestRcteuca2ools.bundle.utilteuca2ools.commands.argtypesRRRRt8euca2ools.commands.bootstrap.describeservicecertificatesRt!euca2ools.commands.s3.checkbucketRt"euca2ools.commands.s3.createbucketR	teuca2ools.commands.s3.getobjectR
t euca2ools.commands.s3.postobjectRteuca2ools.commands.s3.putobjectRteuca2ools.exceptionsR
RgtobjectRR�R�RFR(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt<module>s6"�-rw