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    
idna / lib / python2.7 / site-packages / nova / virt / libvirt / storage / rbd_utils.pyc
Size: Mime:
ó
±EYc@swddlmZddlmZyddlZddlZWnek
r[dZdZnXddlm	Z
ddlmZddl
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZdd
lmZe
jeƒZdefd„ƒYZdefd„ƒYZ defd„ƒYZ!defd„ƒYZ"dS(iÿÿÿÿ(ttpool(turllibN(tlog(t	jsonutils(tloopingcall(texcutils(tunits(t	exception(t_(t_LE(t_LW(tutilstRbdProxycBs eZdZd„Zd„ZRS(sáA wrapper around rbd.RBD class instance to avoid blocking of process.

    Offloads all calls to rbd.RBD class methods to native OS threads, so that
    we do not block the whole process while executing the librbd code.

    cCstjtjƒƒ|_dS(N(RtProxytrbdtRBDt_rbd(tself((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt__init__3scCst|j|ƒS(N(tgetattrR(Rtattr((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt__getattr__6s(t__name__t
__module__t__doc__RR(((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR+s	tRBDVolumeProxycBs;eZdZdded„Zd„Zd„Zd„ZRS(s$Context manager for dealing with an existing rbd volume.

    This handles connecting to rados and opening an ioctx automatically, and
    otherwise acts like a librbd Image object.

    The underlying librados client and ioctx can be accessed as the attributes
    'client' and 'ioctx'.
    c	Cs|j|ƒ\}}yR|r-|jdƒnd}tjtj||jdƒd|d|ƒƒ|_Wn“tjk
r°t	j
ƒ%tjd|ƒ|j
||ƒWdQXnMtjk
rüt	j
ƒ+tjtdƒ|ƒ|j
||ƒWdQXnX||_||_||_dS(Ntutf8tsnapshott	read_onlysrbd image %s does not existserror opening rbd image %s(t_connect_to_radostencodetNoneRR
RtImagetvolumet
ImageNotFoundRtsave_and_reraise_exceptiontLOGtdebugt_disconnect_from_radostErrorRR	tdrivertclienttioctx(	RR(tnametpoolRRR)R*t	snap_name((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRCs"

		cCs|S(N((R((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt	__enter__XscCs2z|jjƒWd|jj|j|jƒXdS(N(R!tcloseR(R&R)R*(Rttype_tvaluet	traceback((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt__exit__[scCst|j|ƒS(N(RR!(Rtattrib((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRasN(	RRRRtFalseRR.R3R(((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR:s		tRADOSClientcBs;eZdZdd„Zd„Zd„Zed„ƒZRS(sBContext manager to simplify error handling for connecting to ceph.cCs(||_|j|ƒ\|_|_dS(N(R(RtclusterR*(RR(R,((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRgs	cCs|S(N((R((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR.kscCs|jj|j|jƒdS(N(R(R&R7R*(RR0R1R2((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR3nscCsF|jjdƒ}|dks0t|ƒdkr<tj}nt|ƒS(Ntrbd_default_featuresi(R7tconf_getRtintRtRBD_FEATURE_LAYERING(Rtfeatures((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR<qsN(	RRRRRR.R3tpropertyR<(((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR6es
		t	RBDDrivercBsþeZd„Zdd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
dd„Zd	„Zd
„Z
dd„Zdd„Zddd
„Zd„Zd„Zdd„Zd„Zd„Zded„Zeded„Zd„Zdd„ZRS(cCss|jdƒ|_|r'|jdƒnd|_|rE|jdƒnd|_tdkrottdƒƒ‚ndS(NRtsrbd python libraries not found(RR,t	ceph_confRtrbd_userRtRuntimeErrorR(RR,R@RA((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR{s
cCs…tjd|jd|jƒ}y?|jƒ|p7|j}|j|jdƒƒ}||fSWn!tjk
r€|j	ƒ‚nXdS(Ntrados_idtconffilesutf-8(
tradostRadosRAR@tconnectR,t
open_ioctxRR'tshutdown(RR,R)tpool_to_openR*((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR„s

cCs|jƒ|jƒdS(N(R/RI(RR)R*((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR&‘s
cCsNg}|jr(|jd|jgƒn|jrJ|jd|jgƒn|S(s°List of command line parameters to be passed to ceph commands to
           reflect RBDDriver configuration such as RBD user name and location
           of ceph.conf.
        s--ids--conf(RAtextendR@(Rtargs((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt	ceph_args–s		cCsddddg|jƒ}tj|Œ\}}|jdƒ}|djdƒr`|d}ntjdj|ƒƒ}g|d	D]}|d
^qƒ}g}g}	x\|D]T}
|
|
jdƒ }|j	ddƒ\}}
|j
|jd
ƒƒ|	j
|
ƒq¬W||	fS(Ntcephtmontdumps
--format=jsons
isdumped monmap epochitmonstaddrt/t:s[](RMRtexecutetsplitt
startswithRtloadstjointrindextrsplittappendtstrip(RRLtoutRtlinestmonmapROtaddrsthoststportsRRt	host_portthosttport((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt
get_mon_addrs¢s
!
cCsÔd}|j|ƒs<tdƒ}tjd|d|ƒ‚nttjj|t|ƒj	dƒƒ}d|kr—tdƒ}tjd|d|ƒ‚nt|ƒdkrÐtd	ƒ}tjd|d|ƒ‚n|S(
Nsrbd://sNot stored in rbdtimage_idtreasonRSR?sBlank componentsisNot an rbd snapshot(
RWRRtImageUnacceptabletmapRtparsetunquotetlenRV(RturltprefixRitpieces((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt	parse_url³s(cCs&t|ƒ}|jjƒSWdQXdS(N(R6R7tget_fsid(RR)((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRsÁsc
Cs|d}y|j|ƒ\}}}}Wn'tjk
rR}tjd|ƒtSX|jƒ|kr€d|}	tj|	ƒtS|jdƒdkrÁdj||jdƒƒ}	tj|	ƒtSy|j	|d|d|ƒSWn7t
jk
r}tjd	td
|d|ƒƒtSXdS(NRosnot cloneable: %ss!%s is in a different ceph clustertdisk_formattrawsHrbd image clone requires image format to be 'raw' but image {0} is '{1}'R,Rs%Unable to open image %(loc)s: %(err)stlocterr(
RrRRjR$R%R5RstgettformattexistsRR'tdict(
Rtimage_locationt
image_metaRotfsidR,timageRteRi((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pytis_cloneableÅs*



	c
Cs|j|dƒ\}}}}tjdtd|d|d|d|d|ƒƒt|t|ƒƒ–}t||ƒ~}	yGtƒj|j|j	dƒ|j	dƒ|	jt|ƒd	|j
ƒWn-tjk
rðt
jtd
ƒ|ƒ‚nXWdQXWdQXdS(NRos@cloning %(pool)s/%(img)s@%(snap)s to %(dest_pool)s/%(dest_name)sR,timgtsnapt	dest_poolt	dest_namesutf-8R<s&no write permission on storage pool %s(RrR$R%R{R6tstrRtcloneR*RR<RtPermissionErrorRt	ForbiddenR(
RR|R…R„t_fsidR,RRt
src_clienttdest_client((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR‡ás"	cCs,t||dtƒ}|jƒSWdQXdS(NR(RtTruetsize(RR+tvol((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRŽõscCs<tjd||ƒt||ƒ}|j|ƒWdQXdS(s_Resize RBD volume.

        :name: Name of RBD object
        :size: New size in bytes
        sresizing rbd image %s to %dN(R$R%Rtresize(RR+RŽR((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRùscCsly8t|t|ƒd|dtƒ}|jƒSWdQXWn-tjk
rgtjtdƒ|ƒ‚nXdS(sœReturns the pool, image and snapshot name for the parent of an
        RBD volume.

        :volume: Name of RBD object
        :pool: Name of pool
        R,RNs'no usable parent snapshot for volume %s(	RR†Rtparent_infoRR"RRjR(RR!R,R((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR‘scCsQtjdtd|d|ƒƒt|t|ƒd|ƒ}|jƒWdQXdS(s²"Flattens" a snapshotted image with the parents' data,
        effectively detaching it from the parent.

        :volume: Name of RBD object
        :pool: Name of pool
        sflattening %(pool)s/%(vol)sR,RN(R$R%R{RR†tflatten(RR!R,R((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR’sc	CsLy0t||d|d|dtƒ	tSWdQXWntjk
rGtSXdS(NR,RR(RRRR"R5(RR+R,R((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRzs
c	Cs±t||jƒ™}ytƒj|j|ƒWnutjk
rltjt	dƒi|d6|jd6ƒn;tj
k
r¦tjtdƒi|d6|jd6ƒnXWdQXdS(s=Remove RBD volume

        :name: Name of RBD volume
        sDimage %(volume)s in pool %(pool)s can not be found, failed to removeR!R,sAimage %(volume)s in pool %(pool)s has snapshots, failed to removeN(
R6R,RtremoveR*RR"R$twarningR
tImageHasSnapshotsterrorR	(RR+R)((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pytremove_image'scCsId|j||g}|dg7}||jƒ7}tjdd|ŒdS(sýImport RBD volume from image file.

        Uses the command line import instead of librbd since rbd import
        command detects zeroes to preserve sparseness in the image.

        :base: Path to image file
        :name: Name of RBD volume
        s--pools--image-format=2RtimportN(R,RMRRU(RtbaseR+RL((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pytimport_image8s	
csЇfd†}idd6}tj||j||ƒ}|jddƒjƒ}|r†y||j||ƒWq†tjk
r‚q†XndS(s3Destroy an RBD volume, retrying as needed.
        csÏy)tƒj||ƒtjdtƒ‚Wnptjk
rXˆj|tj	dt
ƒnDtjtjfk
r›tj
tdƒi|d6ˆjd6ƒnX|dcd8<|ddkrËtjƒ‚ndS(	Ntretvaluet
ignore_errorss-rbd remove %(volume)s in pool %(pool)s failedR!R,tretriesii(RR“RtLoopingCallDoneR5RR•tremove_snapt
libvirt_utilstRESIZE_SNAPSHOT_NAMERt	ImageBusyR$R”R
R,(R*R!tretryctx(R(sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt_cleanup_volLs
i
RtintervaliN(RtFixedIntervalLoopingCallR*tstarttwaitRž(RR)R!R,R¤R£ttimert	timed_out((RsX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt_destroy_volumeIs
cCs^t||jƒF}tƒj|jƒ}x't||ƒD]}|j||ƒq:WWdQXdS(N(R6R,RtlistR*tfilterR«(Rt	filter_fnR)tvolumesR!((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pytcleanup_volumeshscCsbt|ƒP}|jjƒ}i|dtjd6|dtjd6|dtjd6SWdQXdS(Ntkbttotaltkb_availtfreetkb_usedtused(R6R7tget_cluster_statsRtKi(RR)tstats((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt
get_pool_infons
cCsytjdi|d6|d6ƒt|t|ƒd|ƒ:}|j|ƒ|ro|j|ƒro|j|ƒnWdQXdS(s¿Create a snapshot of an RBD volume.

        :volume: Name of RBD object
        :name: Name of snapshot
        :pool: Name of pool
        :protect: Set the snapshot to "protected"
        s1creating snapshot(%(snap)s) on rbd image(%(img)s)RƒR‚R,N(R$R%RR†tcreate_snaptis_protected_snaptprotect_snap(RR!R+R,tprotectR((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR»us	
c
Cs
t|t|ƒd|ƒé}|g|jƒD]}|jddƒ^q.krÓ|j|ƒr¥|rt|j|ƒq¥|s¥tjtdƒi|d6|d6ƒdSntj	di|d6|d6ƒ|j
|ƒn-|stjtdƒi|d6|d6ƒnWdQXdS(	sRemoves a snapshot from an RBD volume.

        :volume: Name of RBD object
        :name: Name of snapshot
        :ignore_errors: whether or not to log warnings on failures
        :pool: Name of pool
        :force: Remove snapshot even if it is protected
        R,R+R?s?snapshot(%(name)s) on rbd image(%(img)s) is protected, skippingR‚Ns1removing snapshot(%(name)s) on rbd image(%(img)s)s1no snapshot(%(name)s) found on rbd image(%(img)s)(RR†t
list_snapsRxR¼tunprotect_snapR$R”R
R%RŸ(RR!R+RœR,tforceRRƒ((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRŸ„s
1	c
Cst||ƒx}|g|jƒD]}|jddƒ^q"krqtjdi|d6|d6ƒ|j|ƒntjd|ƒ‚WdQXdS(sRevert an RBD volume to its contents at a snapshot.

        :volume: Name of RBD object
        :name: Name of snapshot
        R+R?s5rolling back rbd image(%(img)s) to snapshot(%(snap)s)RƒR‚tsnapshot_idN(RR¿RxR$R%trollback_to_snapRtSnapshotNotFound(RR!R+RRƒ((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyRás1	cCs,t||ƒ}|j||ƒWdQXdS(s0A one-shot version of cleanup_volumes()
        N(R6R«(RR!R,R)((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pytdestroy_volume¯sN(RRRRRR&RMRgRrRsRR‡RŽRR‘R’RzR—RšR«R°RºR5R»RŸRÃRÅ(((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyR>ys0		
								

					(#teventletRt	six.movesRRERtImportErrorRtoslo_logRtloggingtoslo_serializationRtoslo_serviceRt
oslo_utilsRRtnovaRt	nova.i18nRR	R
Rtnova.virt.libvirtR t	getLoggerRR$tobjectRRR6R>(((sX/home/tvault/.virtenv/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.pyt<module>s.

+