Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
contego / home / tvault / .virtenv / lib / python2.7 / site-packages / nova / virt / libvirt / imagecache.pyc
Size: Mime:
ó
±EYc@s%dZddlZddlZddlZddlZddlmZddlmZddlm	Z
ddlZddl
mZddl
mZddl
mZdd	lmZdd
lmZdd	lmZe
jeƒZejjZd„Zd„Zd
„Zdejfd„ƒYZdS(s€Image cache manager.

The cache manager implements the specification at
http://wiki.openstack.org/nova-image-cache-management.

iÿÿÿÿN(t	lockutils(tprocessutils(tlog(t_LE(t_LI(t_LW(tutils(t
imagecachecCstj|jdƒƒjƒS(sGReturn a filename based on the SHA1 hash of a given image ID.

    Image files stored in the _base directory that match this pattern
    are considered for cleanup by the image cache manager. The cache
    manager considers the file to be in use if it matches an instance's
    image_ref, kernel_id or ramdisk_id property.
    sutf-8(thashlibtsha1tencodet	hexdigest(timage_id((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pytget_cache_fname-scCs'tjj|ƒ}tjji|d6S(smConstruct a filename for storing additional information about a base
    image.

    Returns a filename.
    timage(tostpathtbasenametCONFtlibvirttimage_info_filename_pattern(t	base_patht	base_file((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pytget_info_filename8s	cCsUtjƒjd}tjjidi|d6d6}tj||ƒ}|rQtSt	S(s8Test if a given path matches the pattern for info files.isY([0-9a-f]{%(digest_size)d}|[0-9a-f]{%(digest_size)d}_sm|[0-9a-f]{%(digest_size)d}_[0-9]+)tdigest_sizeR(
RR	t
digestsizeRRRtretmatchtTruetFalse(RRtregexptm((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pytis_valid_info_fileDs	tImageCacheManagercBs¤eZd„Zd„Zed„Zd„Zd„Zd„Zd„Z	e
d„ƒZed„Z
d	„Zd
„Zd„Zd„Zd
„Zd„Zd„ZRS(cCs<tt|ƒjƒtjjtjdƒ|_|j	ƒdS(Ntlocks(
tsuperR!t__init__RRtjoinRtinstances_patht	lock_patht_reset_state(tself((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyR$TscCsUi|_tƒ|_tƒ|_tƒ|_g|_g|_g|_g|_dS(s)Reset state variables used for each pass.N(	tused_imagestsettinstance_namestback_swap_imagestused_swap_imagestactive_base_filest	originalstremovable_base_filestunexplained_images(R)((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyR(Ys				cCsWtjj||ƒ}tjj|ƒrS|jj|ƒ|rS|jj|ƒqSndS(s)Store a base image for later examination.N(RRR%tisfileR2tappendR0(R)tbase_dirtenttoriginaltentpath((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_store_imagegs
cCs|jdƒ}t|ƒdkr}|ddkr}t|dƒdkr}|djƒr}tjd|ƒ|jj|ƒq}ndS(s-Store base swap images for later examination.t_iitswapis"Adding %s into backend swap imagesN(tsplittlentisdigittLOGtdebugR-tadd(R)R6tnames((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_store_swap_imageos
"&cCsÌtjƒjd}x²tj|ƒD]¡}tjj||ƒ}t|ƒrMq#t|ƒ|krx|j	||dt
ƒq#t|ƒ|dkr·||dkr·|j	||dtƒq#|j|ƒq#WdS(sÓScan base images in base_dir and call _store_image or
        _store_swap_image on each as appropriate. These methods populate
        self.unexplained_images, self.originals, and self.back_swap_images.
        iR7R:N(
RR	RRtlistdirRR%R R=R9RRRC(R)R5RR6R((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_scan_base_imagesws&cCs…g}xxtjtjƒD]d}||jkrtjd|ƒtjjtj|dƒ}tjj	|ƒr}tjd|ƒyt
j|ƒ}Wn?tj
k
rÏtjj	|ƒsÉtjd|ƒqqЂnXtjdi|d6|d6ƒ|rztjjtjtj|ƒ}||kr.|j|ƒn||jkrwtjtdƒi|d6|d6ƒ|jj|ƒqwqzq}qqW|S(	s)List the backing images currently in use.s%s is a valid instance nametdisks%s has a disk files#Failed to get disk backing file: %ss.Instance %(instance)s is backed by %(backing)stinstancetbackingsdInstance %(instance)s is using a backing file %(backing)s which does not appear in the image service(RRDRR&R,R?R@RR%texistst
libvirt_utilstget_disk_backing_fileRtProcessExecutionErrortimage_cache_subdirectory_nameR4R2twarningRtremove(R)tinuse_imagesR6t	disk_pathtbacking_filetbacking_path((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_list_backing_imagesžs@
		
		
 ccsÅtjj||ƒ}tjj|ƒr8|ttfVntjj||dƒ}tjj|ƒrt|ttfVntjd|ƒ}x7|jD],}|j	|ƒ}|r‘|ttfVq‘q‘WdS(slFind the base file matching this fingerprint.

        Yields the name of the base file, a boolean which is True if the image
        is "small", and a boolean which indicates if this is a resized image.
        Note that it is possible for more than one yield to result from this
        check.

        If no base file is found, then nothing is yielded.
        t_sms
.*/%s_[0-9]+$N(
RRR%RIRRRtcompileR2R(R)R5tfingerprintRt	resize_retimgR((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_find_base_fileÉscCsXtjj|ƒs,tjd|ƒtdfStjj|ƒ}tjƒ|}t|fS(Ns#Cannot remove %s, it does not existi(	RRRIR?R@RtgetmtimettimeR(Rtmtimetage((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_get_age_of_fileäs
c	sõˆjˆƒ\}}|sdStjjˆƒd}tj|dtdˆjƒ‡‡‡fd†ƒ}|ˆkrtj	t
dƒˆƒnd|ƒ|rñy tj|dddˆjƒWqñt
k
rí}tjd	i|d
6|d6ƒqñXndS(s6Remove a single swap or base file if it is old enough.NiÿÿÿÿtexternalR'cs¿ˆjˆƒ\}}|s(|ˆkr,dStjtdƒˆƒy?tjˆƒtˆƒ}tjj|ƒr€tj|ƒnWn7t	k
rº}tj
tdƒiˆd6|d6ƒnXdS(NsRemoving base or swap file: %ss3Failed to remove %(base_file)s, error was %(error)sRterror(R_R?tinfoRRRORRRItOSErrorRaR(RIR^t	signaturete(RtmaxageR)(sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_inner_remove_old_enough_file÷s

s)Base or swap file too young to remove: %stlock_file_prefixsnova-s3Failed to remove %(lock_file)s, error was %(error)st	lock_fileRa(R_RRR<RtsynchronizedRR'R?RbRRtremove_external_lock_fileRcR@(	R)RRftremove_lockRIR^RiRgRe((RRfR)sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_remove_old_enough_fileïs$! 
	
cCs#tj}|j||dtƒdS(s3Remove a single swap base file if it is old enough.RlN(Rt*remove_unused_original_minimum_age_secondsRmR(R)RRf((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_remove_swap_file,s	cCs;tjj}||jkr'tj}n|j||ƒdS(s.Remove a single base file if it is old enough.N(RRt)remove_unused_resized_minimum_age_secondsR0RnRm(R)RRf((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_remove_base_file2scCs˜t}tjtdƒi|d6|d6ƒ||jkrL|jj|ƒn||jkr|j|\}}}|dks‰|dkrt}tjtdƒi|d6|d6|d6|d6ƒ|jj	|ƒ|stj
tdƒi|d6|d6d	j|ƒd
6ƒqqn|r”|sQtj
di|d6|d6ƒ|jj	|ƒq”tj
di|d6|d6ƒtjj|ƒr”tj|ƒq”nd
S(s*Handle the checks for a single base image.s)image %(id)s at (%(base_file)s): checkingtidRis~image %(id)s at (%(base_file)s): in use: on this node %(local)d local, %(remote)d on other nodes sharing this instance storagetlocaltremotesgimage %(id)s at (%(base_file)s): warning -- an absent base file is in use! instances: %(instance_list)st t
instance_lists4image %(id)s at (%(base_file)s): image is not in uses0image %(id)s at (%(base_file)s): image is in useN(RR?RbRR2ROR*RR/R4RNRR%R@R1RRRIRJtupdate_mtime(R)timg_idRtimage_in_useRsRtt	instances((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_handle_base_image:s@


	
	
cCs»tjdƒxp|jD]e}tjj||ƒ}||jkrctjj|ƒrctj	|ƒq|j
r|j|ƒqqW|j|j}x$|D]}tjt
dƒ|ƒq—WdS(NsVerify swap imagess>%s swap image was used by instance but no back files existing!(R?R@R-RRR%R.RIRJRwtremove_unused_base_imagesRoRNR(R)tcontextR5R6Rterror_imagesterror_image((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_age_and_verify_swap_imagesns
!	
cCsÄtjdƒx¡|jD]–}tj|ƒjƒ}tjdi|d6|d6ƒxZ|j||ƒD]F}|\}}}	|j||ƒ|rc|	rc|jj	|ƒqcqcWqW|j
ƒ}
x0|
D](}||jkrÄ|jj	|ƒqÄqÄWx7|jD],}tj
tdƒ|ƒ|jj	|ƒqúW|jrXtjtdƒdj|jƒƒn|jr³tjtdƒdj|jƒƒ|jr³x!|jD]}|j|ƒq–Wq³ntjd	ƒdS(
NsVerify base imagess2Image id %(id)s yields fingerprint %(fingerprint)sRrRWsUnknown base file: %ssActive base files: %sRusRemovable base files: %ssVerification complete(R?R@R*RR	RRZR{R0R4RTR/R2RNRR1RbRR%R|Rq(R)R}t
all_instancesR5RYRWtresultRtimage_smallt
image_resizedtinuse_backing_imagesRS((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt_age_and_verify_cached_images}s8
	

			cCsEtjjtjtjƒ}tjj|ƒsAtjd|ƒdS|S(Ns.Skipping verification, no base directory at %s(	RRR%RR&RMRIR?R@(R)R5((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt	_get_base§s	cCs|jƒ}|sdS|jƒ|j|ƒ|j||ƒ}|d|_|d|_|d|_|j|||ƒ|j||ƒdS(NR*R,R.(	R‡R(REt_list_running_instancesR*R,R.R†R€(R)R}RR5trunning((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pytupdate»s




(t__name__t
__module__R$R(RR9RCRERTRZtstaticmethodR_RRmRoRqR{R€R†R‡RŠ(((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyR!Ss 				'	+	=			4		*	(t__doc__RRRR\toslo_concurrencyRRtoslo_logRtloggingt	nova.conftnovat	nova.i18nRRRRt	nova.virtRtnova.virt.libvirtRJt	getLoggerR‹R?tconfRR
RR R!(((sQ/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/imagecache.pyt<module>s(