Viewing File: /usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyc


Xc@sddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlZddlZddlZddlmZmZmZmZddlmZddlmZddlmZddlmZdd	lm Z dd
l!m"Z"ddl#m$Z$dd
dZ%de&fdYZ'de&fdYZ(de&fdYZ)dZ*dZ+dS(iN(tArgtMutuallyExclusiveArgList(t
ArgumentError(tb64encoded_file_contentstdelimited_listtfilesizetmanifest_block_device_mappings(tDescribeServiceCertificates(tCheckBucket(tCreateBucket(t	GetObject(t
PostObject(t	PutObject(tAWSErrori
iitBundleCreatingMixincBsreZedddddeddedddd	ed
ddddd
edddeddOddeddddddeddddddeddddded d!dd"dd#ed$dd%dd&ed'dd%dd(ed)d*dPdd+ed,d*dPdejed-d*dPdejed.d/dd0d1edd2ed3dd4d1ed5d6gdd7ed8ddQd6d9dejed<d1e	dd=ed>d1e	d6d?dejed@d1dAdejedBd1dCdejedDdEdFdejgZ
dGZdHZdIZ
dJZdKZdLZedMZedNZRS(Rs-is--imagetmetavartFILEtrequiredthelps.file containing the image to bundle (required)s-ps--prefixsthe file name prefix to give the
                bundle's files (required when bundling stdin; otherwise
                defaults to the image's file name)s-ds
--destinationtDIRslocation 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--privatekeysfile containing
                your private key to sign the bundle's manifest with.  If one
                is not available the bundle will not be signed.s-cs--certsfile containing
                your X.509 certificate.  If one is not available it
                will not be possible to unbundle the bundle without
                cloud administrator assistance.s	--ec2certsfile 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-sizeis	--enc-keycCs
t|dS(Ni(tint(ts((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt<lambda>wss--enc-ivcCs
t|dS(Ni(R$(R%((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR&yss--batchtactiont
store_truecCsD|jjds|jjd}dtjkr\|jjdtjd|jd<q|r|jjd||jd<qn|jjdr|jdj	dd|jd<n|jjdst
dn|jjd	|jd|jjd
s|jjd}dtjkrQ|jjd
tjd|jd
<qdtjkr|jjd
tjd|jd
<q|r|jjd||jd
<qn|jjd
rtjjtjj
|jd
|jd
<t|jd
dn|jjd|jjd
|jjds|jjd}dtjkr|jjdtjd|jd<ndtjkr|jjdtjd|jd<q|r|jjd||jd<qn|jjdr8tjjtjj
|jd|jd<t|jddn|jjd|jjd|jjds|jjd}dtjkr|jjdtjd|jd<q|r|jjd||jd<q|jjdr|jjdry$|j|jd|jd}Wn`tk
r}|jjd d!t|jjd"krdd#}nd$}tjt
||nX|r|jjd%||jd<qqn|jjdrtjjtjj
|jd|jd<t|jdd&n|jjds&t
d'n|jjd(|jddS()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_infoispermission 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_credss#
	cCs|jjdrdtjj|jdrdtjj|jdrdtdj|jdn|jddkrtjtj	t
jj|jd<|jjdstdn|jjdstdqnt
|jdtjr|jjds2tjj|jd|jd<n|jjdsgtjj|jd|jd<nt|jd|jd<nB|jjdstd	n|jjdstd
n|jdtkr|jjd|jdtndS(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_outputs8	(#		cCsl|jjddkr(d|jd<n|jjddkrPd|jd<n|jddkr|jjdr|jddkrtdn|jjdrtdn|jjdrtdqn|jddkrh|jjdrtd	n|jjdrD|jddkrDtd
n|jjdrhtdqhndS(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$%%cCstj}|jjdr>|jjd|jd}n|jd}|jjdr|jjd|jd}n|jd}dj||jd<dj||jd<dS(Ntenc_keys using preexisting encryption keyitenc_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|jjdtd|jd|jjd|d|dddd	}|j}x|jd
pggD]}|jdd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|_
|jjdr|jj|jdn|jjdr|j
j|jdn|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?RR9t
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(RfRtdump_manifest_to_str(RNRtfilenameRt
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(RNRR((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR_s
(RRRRRRN(smachineskernelsramdisk(t__name__t
__module__RRItNonetargparsetSUPPRESSRRRtARGSRSRiRmRwRHRRRR(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR9sd
				b	"				tBundleUploadingMixincBseZedddddeddeddd	d
d)dd
eeddddddejddeddddddeddedddddedddedddddd 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
--locationslocation 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|jjdri|jjds3tdn|jjdsTtdnd|_d|_ndS(NRtkey_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:RRRzt
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(RNRt_RV((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytget_bundle_key_prefixs
cCs|jjdr&|jjddS|jdjddd}y#tj|d|}|jWnltk
r}|j	dkr|jjd|t
j|d|d	|jjd	}|jqnXdS(
NRs6using an upload policy; not verifying bucket existenceRRiiiscreating bucket '%s'tlocation(R9R:R?RrtsplitRt
from_otherRR
RKR	(RNRRRQ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytensure_dest_bucket_existss!
cKs"|jjdr|r$|GdGHn|jjdrMi|jdd6}ni}|j|tj|d|d|d|jjdpdd	|jdd
|jdd|jd
|}nTtj|d|d|d|jjdpdd|jjdpdd||}|jdS(NRsuploading...tsecurity_tokensx-amz-security-tokentsourceRtacls
aws-exec-readtPolicyt	SignatureRtAWSAccessKeyIdRRit
show_progress(R9R:RRRRR(RNRRRt
putobj_kwargstpostobj_kwargsR((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytupload_bundle_files&


cKszyxztr|j}|tjj|j}|j|j|||dk	rc|jn|dk	r	|j	|q	q	WWnt
k
rdSXWd|j|dk	r|jnXdS(N(RItrecvR=RCRbRRRtreleasetsendtEOFErrortclose(RNtpartinfo_in_mpconnt
key_prefixtpartinfo_out_mpconntpart_write_semRRR((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytupload_bundle_partss	

	
(spublic-reads
aws-exec-readsec2-bundle-readN(RRRRIRtbase64t	b64encodeRRRRRRRRR(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyRes.						tBundleDownloadingMixincBseZedddddeddddeedd	d
ddddded
dd
dddddddedd
dddddddjgZddZdZ	dZ
dZdZdZ
RS(s-bs--bucketRsBUCKET[/PREFIX]RRRs\the bucket that contains the bundle,
                with an optional path prefix (required)s-ms
--manifestRRslthe 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|jjdrIt|jddtjjjj|jdd|S|j}t	j
}|jjd|t
j|d|d|d|}y|jWnStk
r}|jdkr|jjd	d
ttdj|nnX|j|jdtjjjj|d|SWdQXdS(
NRRtprivkey_filenamesreading manifest from %sRyRRisfailed to fetch manifestR8s+manifest '{0}' does not exist on the serveri(R9R:RFRcRRRtread_from_filetget_manifest_s3pathRt
TemporaryFileR?RrR
RRR
RKR@RIt
ValueErrorRZRtseektread_from_fileobj(RNt
s3_serviceRtmanifest_s3pathtmanifest_tempfileRRQ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytfetch_manifests,		

cCs;|jjdr3dj|jd|jdfSdSdS(NRRR(R9R:tjoinR(RN((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyRs!c
CsL|j|}x|D]\}}tjj|tjj||_|jjd||jtj	|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 %sRyRRRsdownloading manifest %s to %s(tmap_bundle_parts_to_s3pathsR=RCRRbRR?RrR
RR9R:RRt(_BundleDownloadingMixin__check_part_sha1RR(RNRtdest_dirRtpartsRtpart_s3pathRRJRt
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 %sRyRRR(
RR?RrR
RR9R:RRR(	RNRtfileobjRRRRRRJ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pytdownload_bundle_to_fileobj/scCsJg}x=|jD]2}|j|dj|jd|jffqW|S(NRR(RtappendRR9R(RNRRR((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyR<s
	'cCsb||d|jkr^|jjd|j||dtdj|j||dndS(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(RNRRRJ((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt__check_part_sha1Cs	N(RRRRIRRRRRRRRRR(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyRs$
				
	cCs^tjj|s-tdj||ntjj|sZtdj||ndS(Ns{0} file '{1}' does not exists{0} file '{1}' is not a file(R=RCRXRRZtisfile(Rtfiletype((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyRFNs		cCs8tjddtjdtj}|j|djS(	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(,RRRtos.pathR=RpRR]RtrequestbuilderRRtrequestbuilder.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
RgtobjectRRRRFR(((sD/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/mixins.pyt<module>s6"-rw		
Back to Directory File Manager