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


Xc@sddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlmZmZddlmZmZddlZddlZddlmZmZddlmZmZmZddlmZdd	lm Z d
ddd
ddgZ!ej"j#eddZ$ej"j#eddZ%de
eefdYZ&dZ'dZ(e)dZ*dZ+dZ,dZ-dS(iN(tArgtMutuallyExclusiveArgList(tBaseCommand(t
ArgumentErrortClientError(tFileTransferProgressBarMixintRegionConfigurableMixin(t	Euca2oolst
SYSCONFDIR(tdelimited_listtfilesizetmanifest_block_device_mappings(tBootstrapRequest(tBundleImagetbtrfstext2text3text4tjfstxfss
bundle-voltexcludestfstabtBundleVolumec#BseZeZdZdzZeddddeddd	d
ddedd
dddd{eddd	ddedddeddd	ddedddedd d	d!ded"d#dd$ed%d&d'dd(ed)d&d'dd*e	ed+d,d-d&d'dd.ed/d,d-d&d0dd1ed2d3d	d
d"d4dd5ed6d7dd|dd;ed<d	d=dd>e	ed?d	d=dd@edAd&d'ddBedCd	d=ddDedEdFd	d=ddGedHdId	d=ddJedKd	d=ddLedMdNd	dOddPedQd	dRddSedTd	dRddUedVdWd}ddXedYdWd}dejedZdWd}deje
jjed[d\d	d]dedd^ed_d	d`dedd"gddaedbded"dcdejeddddedejedfddgdejgZdhZdiZdjZd}dkZdlZdmZdnZdoZdpZdqZdrZdsZdtZduZdvZ dwZ!dxZ"dyZ#RS(~sbPrepare this machine's filesystem for use in the cloud

This command must be run as the superuser.tEUCA_DEFAULT_REGIONtAWS_DEFAULT_REGIONs-ps--prefixthelpsPthe file name prefix to give the
                bundle's files (default: image)s-ds
--destinationtmetavartDIRslocation to place
                the bundle's files (default:  dir named by TMPDIR, TEMP, or TMP
                environment variables, or otherwise /var/tmp)s-rs--archs#the image's architecture (required)tchoicesti386tx86_64tarmhftppctppc64tppc64les-es	--excludesPATH,...ttypet,s(comma-separated list of paths to excludes-is	--includes(comma-separated list of paths to includes-ss--sizetMiBtdefaulti(s0size of the image to create (default: 10240 MiB)s--no-filtertactiont
store_trues(do not filter out sensitive/system filess--allsdinclude all filesystems regardless of type
                (default: only include local filesystems)s	--inherittdesttinheritseuse the metadata service to provide metadata for
                    the bundle (this is the default)s--no-inherittstore_falsesGdo not use the metadata service for bundle
                    metadatas-vs--volumet/sSlocation
                of the volume from which to create the bundle (default: /)s-Ps--partitiontmbrtgpttnoneslthe type of partition table to create (default: attempt
                to guess based on the existing disk)s--scripttFILEslocation of a script
                to run immediately before bundling.  It will receive the
                volume's mount point as its only argument.s--fstabsOlocation of an
                    fstab(5) file to copy into the bundled images--generate-fstabsQautomatically generate an fstab(5) file for
                    the bundled images
--grub-configs{location of a GRUB 1
                configuration file to copy to /boot/grub/menu.lst on the
                bundled images-ks--privatekeysfile containing
                your private key to sign the bundle's manifest with.  This
                private key will also be required to unbundle the image in the
                future.s-cs--certs&file containing your X.509 certificates	--ec2certs=file containing the
                cloud's X.509 certificates-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,...s`block device mapping scheme with which to launch
                instances of this machine images--productcodessCODE1,CODE2,...s3comma-separated list of product codes for the images--part-sizeis	--enc-keycCs
t|dS(Ni(tint(ts((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt<lambda>ss--enc-ivcCs
t|dS(Ni(R4(R5((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyR6scCs1tjdkr!tdn|jjdsBtdn|jdddt}|jjdr}|jn|jjd	st	||jd	<|jd	s|j
jd
|tdj|n|j
j
d|jd	n|jjd
r-|jjdr-d|jd
<ndS(Nismust be superusertarchsargument -r/--arch is requireds	/dev/nullt
image_sizeiR*t	partitions?could not determine the partition table type for root device %ssdcould not determine the type of partition table to use for disk {0}; specify one with -P/--partitions"discovered partition table type %sRtgenerate_fstabs
/etc/fstab(tostgeteuidtRuntimeErrortargstgetRt#_BundleVolume__build_bundle_commandt_get_root_devicet*_BundleVolume__populate_args_from_metadatat_get_partition_table_typetlogtwarntformattinfo(tselftroot_device((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt	configures(	

&cCs|jjdr"|jd}ntjjdd}tjj||jjdpXd}tj	ddd|}|j
||jd}z0|j||}zy|j}|j
d|d|g|j|||j||j||jjd	rG|jd	|g}|jjd
t|tj|nWn7tk
r|jjdd}tj|IJnXWdtjd
|j|tj|X|j||Wd|j||X|j|}	|	j }
tj!||
S(Ntdestinationtprefixsbundle-timagestarget-tdirtsizes	--excludetscriptsrunning user script ``%s''s received ^C; skipping to cleanupsf

Cleaning up after ^C
WARNING:  pressing ^C again will result in the need for manual device cleanup

g?("R>R?t	euca2oolstutiltmkdtemp_for_large_filesR;tpathtjointtempfiletmkdtempt _BundleVolume__create_disk_imaget*_BundleVolume__create_and_mount_filesystemt+_BundleVolume__get_exclude_and_include_argstextendt!_BundleVolume__copy_to_target_dirt_BundleVolume__insert_fstabt!_BundleVolume__insert_grub_configRDRGt
_quote_cmdt
subprocesst
check_calltKeyboardInterrupttsyststderrttimetsleept!_BundleVolume__unmount_filesystemtrmdirt$_BundleVolume__update_filesystem_idst _BundleVolume__detach_disk_imageR@tmaintremove(RHtdestdirRMt
mountpointtdevicetfsinfotexclude_optstcmdtmsgt
bundle_cmdtresult((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyRksF'








cCs"x|dD]}dG|GHqWdS(NisWrote manifest((RHRutmanifest_filename((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pytprint_resultscsDd}tfd|D}tjd|d|dd|S(NRLRKR7t
privatekeytcerttec2certtusertkerneltramdisktblock_device_mappingstproductcodest	part_sizetenc_keytenc_ivt
show_progresstkey_idt
secret_keytsecurity_tokent
bootstrap_urltbootstrap_servicetbootstrap_authtregionc3s'|]}|jj|fVqdS(N(R>R?(t.0tkey(RH(sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pys	<genexpr>sRMR8t
image_typetmachine(sprefixsdestinationsarchRxRyRzR{R|R}R~RRRRRRRRRRRR(tdictR
t
from_other(RHtimage_filenameR8tbundle_argstbundle_args_dict((RHsJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__build_bundle_commands
cCsL|jjd|d|}tj|dd}|jdkrH|jSdS(Ns#reading metadata service value '%s's,http://169.254.169.254/2012-01-12/meta-data/ttimeoutii(RDtdebugtrequestsR?tstatus_codettexttNone(RHRTturltresponse((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__read_metadata_values
cCsE|j|}|rAg|jD]}|r"|jd^q"SgS(NR,(t"_BundleVolume__read_metadata_valuet
splitlinestrstrip(RHRTtvaluetline((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__read_metadata_lists,cCsfi}|jds"|d7}n|j|}x.|D]&}|r8|j||||<q8q8W|S(NR,(tendswitht!_BundleVolume__read_metadata_listR(RHRTtmetadatatkeysR((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__read_metadata_dicts

cCsy|jjdsH|jd|jd<|jjd|jdn|jjds|jd|jd<|jjd|jdn|jjds|jd|jd<|jdr|jjd	d
j|jdqn|jjdsi|jd<xL|jdpijD]/\}}|j	d
s&||jd|<q&q&Wx:|jdjD]"\}}|jjd||qmWnWn#t
jjk
rt
dnXdS(ss
        Populate missing/empty values in self.args using info obtained
        from the metadata service.
        R|s	kernel-idsinherited kernel: %sR}s
ramdisk-idsinherited ramdisk: %sRs
product-codessinherited product codes: %sR$R~sblock-device-mappingtebss%inherited block device mapping: %s=%ssRmetadata service is absent or unresponsive; use --no-inherit to proceed without itN(R>R?RRDRGRRUt!_BundleVolume__read_metadata_dicttitemst
startswithRt
exceptionstTimeoutR(RHRtval((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__populate_args_from_metadatas0

	 c	Cstjdddj|dddjt|dg|jdd	kr|d }tjdd|ddj|gns|jddkrtjddddddd|gtjdddddd|gtjdd|gn|j|}tjj	|st
|S(!Ntddsif=/dev/zerosof={0}sbs=1Mscount=1sseek={0}iR9R-sunit ss
mklabel msdossmkpart primary 64 -1ss
set 1 boot ontprinttquittparteds-ss--t R.tsgdisks--news
128:1M:+1Ms
--typecodes128:ef02s
--change-names
128:BIOS Boots--largest-new=1s1:8300s1:Images--print(sunit ss
mklabel msdossmkpart primary 64 -1ss
set 1 boot onsprintsquit(R`RaRFR4R>RUt_BundleVolume__map_disk_imageR;RTtexiststAssertionError(RHRMt
size_in_mbt
parted_scripttmapped((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__create_disk_image,s&c	Cs:|jddkr|jjd|tjdddd|gd	tj}zxb|jjD]Q}|j}|d
 ddgkr`|d
}|j	d
rdj
|Sq`q`W|jjdtdWd|j
XnS|jjd|tjdd|dgd	tj}|j
\}}|jSdS(NR9R-R.smapping partitioned image %stkpartxs-ss-vs-atstdoutitaddtmaptp1s/dev/mapper/{0}s+failed to get usable map output from kpartxsdevice mapping failedsmapping unpartitioned image %stlosetups-fs--show(smbrsgpt(R>RDRR`tPopentPIPERt	readlinestsplitRRFterrorR=tcommunicatetstrip(	RHRMRRt
line_splitRoRtloopdevt_((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__map_disk_imageFs&
cCst}t|}|jjd|||dd|dgg}xA|D]9}|j||jjdt|tj|qKW|jjd|d||tjdd|d||g|S(Ns4creating filesystem on %s using metadata from %s: %stmkfss-tR#sformatting with ``%s''smounting %s filesystem %s at %stmount(RAt_get_filesystem_infoRDRGtappendR_R`Ra(RHRoRnRIRptfs_cmdstfs_cmd((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__create_and_mount_filesystembs	




cCsG|jjd|tjdgtjdtjd|gdS(Ns
unmounting %stsyncg?tumount(RDRGR`RaReRf(RHRo((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__unmount_filesystemrs
cCs/g}|jdr/|jd|dfn|jdrX|jd|dfn|jddkr}|jdn|r+|jddkrdg|}nJ|jddkrd
g|}n%|jddkrdg|}n|j||jjd|t|tj|ndS(s
        Apply filesystem identifiers to an unmounted filesystem.  To
        avoid UUID conflicts, run this only after the filesystem no
        longer needs to be mounted on the running system.
        tlabels-Ltuuids-UR#RRRs-it0ttune2fsRt	jfs_adminRt	xfs_admins-updating device %s filesystem IDs with ``%s''N(RRR(s-iR(RRR(R?R[RRDRGR_R`Ra(RHRoRptoptionsRr((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__update_filesystem_idsxs$
cCs~tjdg|jddkrK|jjd|ddd|g}n"|jjd	|d
d|g}tj|dS(NRR9R-R.sunmapping partitioned image %sRs-ss-ds!unmapping unpartitioned device %sR(smbrsgpt(R`RaR>RDR(RHRMRoRr((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__detach_disk_imagescCs@g}x3|jjdpgD]}|jd|gqWx3|jjdpTgD]}|jd|gqUW|jjdsxgtD]Y\}}}|tkr|jjd||||jdtjj	|dgqqWn|jjdr<tjj
tr<|jjd	t|jd
tgn|S(Ntexcludes	--excludetincludes	--includetalls excluding %s filesystem %s at %ss**t	no_filtersadding path exclusions from %ss--exclude-from(R>R?R[t_get_all_mountstALLOWED_FILESYSTEM_TYPESRDRR;RTRUtisfilet
EXCLUDES_FILE(RHR>RRRoRntfstype((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__get_exclude_and_include_argss
,%c
Cs|jjdpd}|jds4|d7}n|jdsP|d7}ndg}|jjdrtjddgdtj}|j\}}|jdd	pd
jd}|dkr|j	d
q|j	dn
|j	dddg||||g}	|j
jdt|	dGHtj|	}|j
|jdkr|j
jd|jdGHdg||||g}	tj|	}|j
n|jdkr|j
jd|jtj|jdndS(NtvolumeR,s
-rHlpogDtSRtrsyncs	--versionRsversion itis3.1.0s--info=progress2s
--progresss--quiets-Xscopying files with ``%s''sCopying files...is2rsync exited with code %i; retrying without xattrss$Retrying without extended attributesisrsync exited with code %i(ii(R>R?RR`RRRR9RRRDRGR_twaitt
returncodeRtCalledProcessError(
RHR)Rqtsourcet
rsync_optsRtoutRt
rsync_versionRr((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__copy_to_target_dirs<

	#



cCstjj|dd}tjj|rW|d}|jjd|t||n|jjdr|jj	d|jdtt
|nC|jjdr|jj	d|jdt|jd|ndS(NtetcRs.baks$backing up original fstab file as %sR:sgenerating fstab file from %ssusing fstab file %s(R;RTRURRDRt_copy_with_xattrsR>R?RGtFSTAB_TEMPLATE_FILE(RHRntfstab_filenamet	fstab_bak((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__insert_fstabs
cCs|jjdrtjj|ddd}tjj|rl|d}|jjd|t||n|jj	d|jdt|jd|ndS(Ntgrub_configtboottgrubsmenu.lsts.baks+backing up original grub1 config file as %ssusing grub1 config file %s(
R>R?R;RTRURRDRRRG(RHRnt
grub_filenamet	grub_back((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt__insert_grub_configs	
(RR(RRRR R!R"(smbrsgptR/N($t__name__t
__module__RtSUITEtDESCRIPTIONt
REGION_ENVVARRR	R4RRtargparsetSUPPRESSRt
AUTH_CLASStARGSRR
RJRkRwR@RRRRBRXRRYRgRiRjRZR\R]R^(((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyR7s							0				
	!								%	c	Csi}tdF}x<|D]4}|jdd\}}}}||f||<qWWdQXg}x6|jD](\}\}}|j|||fqmW|S(Ns/proc/mountsi(topenRRRR(tfilesystems_dicttmountsRRoRnRRtfilesystems_list((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyRs	
cCstjddd|gdtj}i}xz|jD]o}|jjd\}}}|dkrq||d<q4|dkr||d	<q4|d
kr4||d<q4q4W|j|jdkrtj|jdn|S(
Ntblkids-otexportRt=tLABELRtTYPER#tUUIDRi(	R`RRRRR9RRR(RoRRpRRRR((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyRs


cCs|ddkrM|ddkr-|d }qM|ddkrM|d }qMn|r_tj}nd}tjddd|d	gd
tjd|}|j\}}xa|jD]S}|jdr|jd
}|ddkrdS|ddkrdSdSqqWdS(Nit
0123456789itdtpRs-ms-sRRRds/dev/t:itmsdosR-R.R/(R`RRRRRRR(RoRtstderr_destRRRRt	line_bits((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyRCs&
cCscd}xAtD]6\}}}|dkrtjj|r|}qqW|s_tdn|S(NR,sno / filesystem found(RRR;RTRtKeyError(RIRoRnR((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyRA4s
cCsdjd|DS(NRcss|]}tj|VqdS(N(tpipestquote(Rtarg((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pys	<genexpr>Bs(RU(Rr((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyR_AscCsHytjdd||gWn$tjk
rCtj||nXdS(s
    shutil.copy2 doesn't preserve xattrs until python 3.3, so here we
    attempt to leverage the cp command to do it for us.
    tcps-aN(R`RaRtshutiltcopy2(RR)((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyREs(.Rtos.pathR;RR"R`RcRVRetrequestbuilderRRtrequestbuilder.commandRtrequestbuilder.exceptionsRRtrequestbuilder.mixinsRRRRQteuca2ools.commandsRRteuca2ools.commands.argtypesR	R
Rteuca2ools.commands.bootstrapRt%euca2ools.commands.bundle.bundleimageR
RRTRURRRRRtFalseRCRAR_R(((sJ/usr/lib/python2.7/site-packages/euca2ools/commands/bundle/bundlevolume.pyt<module>s:				
	
Back to Directory File Manager