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    
Size: Mime:
ó
±EYc@s‘dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlmZddlZddlZddlmZddlmZddlmZddlmZddl Z!ddl"m#Z#dd	l"m$Z$dd
l"m%Z%ddl"m&Z&ddl"m'Z'dd
l"m(Z(ddl)Z)ddl*Z*ddl+m,Z,ddl-Z.ddl.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4ddl5Z.ddl.m6Z6e.j7j8Z8ej9e:ƒZ;idd6dd6dd6dd6Z<da>ej?dƒZ@dZAdtZBduZCdvZDiaEd(dd)„ZFd*„ZGd+„ZHd,eIfd-„ƒYZJd.eJfd/„ƒYZKd0„ZLd1„ZMd2„ZNd3d4„ZOdwZPdxZQddd8„ZRdePd9„ZSd:„ZTd;„ZUd<„ZVd=„ZWd>„ZXd?„ZYd@„ZZdA„Z[dB„Z\dC„Z]dD„Z^dE„Z_dF„Z`ddGdH„ZaddI„ZbejcdJ„ƒZddK„ZedL„ZfejcddM„ƒZgejcdN„ƒZhddO„ZidPeIfdQ„ƒYZjdekdR„ZldS„ZmekdT„ZndU„ZodV„ZpdW„ZqdX„ZrdYeIfdZ„ƒYZsdd[dd\„Ztddd]„Zud^„Zvd_„Zwd`„Zxda„Zydb„Zzdddc„Z{dd„Z|dde„Z}df„Z~dg„Zdh„Z€di„Zddj„Z‚dk„Zƒekdl„Z„dm„Z…ddn„Z†do„Z‡dpd[dqdr„Zˆds„Z‰dS(ysUtilities and helper functions.iÿÿÿÿN(tsaxutils(t	lockutils(tprocessutils(tcontext(tlog(tencodeutils(texcutils(timportutils(tstrutils(t	timeutils(tunits(trange(t	exception(t_t_LEt_LIt_LW(t
safe_utilsitSECONDi<tMINUTEitHOURi€QtDAYsnova-timage_tmin_ramtmin_disktdisk_formattcontainer_formattmappingstblock_device_mappingtimg_mappingstimg_block_device_mappingtimage_idt
image_nametsizetchecksumgš™™™™™©?cCs8|dkr!tjddƒ}ntjtjtjƒ}tjdd|ƒ}|j|||fƒ|j	|ƒz/y|j
dƒ}Wntjk
ržtSXWd|j
ƒXd}t|ƒtj|ƒkrtjtdƒtd	tj|ƒd
t|ƒƒƒtStj||ƒ\}}	}
|dko7|
|kS(sSends a vpn negotiation packet and returns the server session.

    Returns Boolean indicating whether the vpn_server is listening.
    Basic packet structure is below.

    Client packet (14 bytes)::

         0 1      8 9  13
        +-+--------+-----+
        |x| cli_id |?????|
        +-+--------+-----+
        x = packet identifier 0x38
        cli_id = 64 bit identifier
        ? = unknown, probably flags/padding

    Server packet (26 bytes)::

         0 1      8 9  13 14    21 2225
        +-+--------+-----+--------+----+
        |x| srv_id |?????| cli_id |????|
        +-+--------+-----+--------+----+
        x = packet identifier 0x40
        cli_id = 64 bit identifier
        ? = unknown, probably flags/padding
        bit 9 was 1 and the rest were 0 in testing

    ilÿÿÿÿs!BQxxxxxi8iNs
!BQxxxxxQxxxxs7Expected to receive %(exp)s bytes, but actually %(act)stexptacti@(tNonetrandomtrandinttsockettAF_INETt
SOCK_DGRAMtstructtpacktsendtot
settimeouttrecvttimeouttFalsetclosetlentcalcsizetLOGtwarningRtdicttunpack(taddresstportR0t
session_idtsocktdatatreceivedtfmtt
identifiertserver_sesstclient_sess((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytvpn_pinghs&
	%cCs&tjjrd}n
dtj}|S(Ntsudossudo nova-rootwrap %s(tCONFtworkaroundstdisable_rootwraptrootwrap_config(tcmd((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_root_helperœs	
cCs!tjrttjƒStƒSdS(N(REtuse_rootwrap_daemontRootwrapDaemonHelperRHtRootwrapProcessHelper(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt_get_rootwrap_helper¤s	
RMcBseZd„Zd„ZRS(cOstƒ|d<tj||ŽS(Ntroot_helper(RJRttrycmd(tselfRItkwargs((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRP¬s
cOstƒ|d<tj||ŽS(NRO(RJRtexecute(RQRIRR((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRS°s
(t__name__t
__module__RPRS(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRM«s	RLcBs>eZiZedƒd„ƒZd„Zd„Zd„ZRS(sdaemon-client-lockcCs]y|j|SWnGtk
rXddlm}|jdd|gƒ}||j|<|SXdS(Niÿÿÿÿ(tclientRDsnova-rootwrap-daemon(t_clientstKeyErrort
oslo_rootwrapRVtClient(tclsRHRVt
new_client((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt_get_client¸s

cCs|j|ƒ|_dS(N(R]RV(RQRH((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt__init__ÃscOs|jdtƒ}y"|j||Ž\}}t}Wn2tjk
rh}dtj|ƒ}}t}nX|r…|r…|r…d}n||fS(Ntdiscard_warningst(tpopR1RSRtProcessExecutionErrortsixt	text_typetTrue(RQtargsRRR_toutterrtfailedtexn((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRPÆs

	c
Osg|D]}t|ƒ^q}|jdtjƒ}|jddƒ}|jddƒ}|jdtƒ}|jddƒ}|jddgƒ}	t}
t|	tƒr¹|	}
dg}	nt|	t	ƒrÔ|	g}	nt
jd	j|ƒƒ}t
jtd
ƒi|d6|d6ƒxñ|dkr|d8}yátjƒ}t
j|td
ƒ|ƒ|jj||ƒ\}
}}tjƒ|}t
j|di|d6|
d6|d6ƒ|
rÿ|
|	krÿt
j|ƒ}t
j|ƒ}tjd|
d|d|d|ƒ‚n||fSWqtjk
rÿ}|tjksD|tjkr˜|r˜tdƒ}t
j||i|jd6|jd6|jd6|jd6|jd6ƒn|s½t
j|tdƒ|ƒ‚qt
j|tdƒ|ƒ|rtjtj ddƒdƒqqXqWdS(Ntloglevelt
log_errorst
process_inputtdelay_on_retrytattemptsitcheck_exit_codeit sHExecuting RootwrapDaemonHelper.execute cmd=[%(cmd)r] kwargs=[%(kwargs)r]RIRRsRunning cmd (subprocess): %ssECMD "%(sanitized_cmd)s" returned: %(return_code)s in %(end_time)0.3fst
sanitized_cmdtreturn_codetend_timet	exit_codetstdouttstderrsS%(desc)r
command: %(cmd)r
exit code: %(code)r
stdout: %(stdout)r
stderr: %(stderr)rtdesctcodes%r failed. Not Retrying.s%r failed. Retrying.iiÈgY@(!tstrRatloggingtDEBUGR%ReR1t
isinstancetbooltintRt
mask_passwordtjoinR5tinfoRttimeRR
RVRSRRbtLOG_ALL_ERRORStLOG_FINAL_ERRORtdescriptionRIRuRvRwtsleepR&R'(RQRIRRtcRkRlRmRnRoRptignore_exit_codeRrt
start_timet
returncodeRgRhRttformat((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRSÓsr
		
	


(RTRURWtsynchronizedR]R^RPRS(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRLµs
		
cOscd|krS|jdƒrStjr=ttjƒj||ŽStƒj||ŽSntj||ŽS(s3Convenience wrapper around oslo's execute() method.trun_as_root(tgetRERKRLRHRSRMR(RIRR((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRS s	
cOs6dddg}|j|ƒ|j|ƒt||ŽS(s+Convenience wrapper to execute ssh command.tsshs-os
BatchMode=yes(tappendtextendRS(tdestRIRRtssh_cmd((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytssh_execute+s

cOsZ|jdtƒrJtjr4ttjƒj||ŽStƒj||ŽSntj||ŽS(s2Convenience wrapper around oslo's trycmd() method.RŽ(	RR1RERKRLRHRPRMR(RfRR((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRP3s	
icCsEd}gt|ƒD]}tj|ƒ^q}d|dj|ƒfS(Nt%01234567890abcdefghijklmnopqrstuvwxyzs%s-%sR`(RR&tchoiceR(ttopicR!t
characterst_xtchoices((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytgenerate_uid>s(t23456789tABCDEFGHJKLMNPQRSTUVWXYZtabcdefghijkmnopqrstuvwxyzc	CsL|stj}nd}d|krK|jddƒ\}}t|ƒ}n|dk	r`|}ntjƒ}|dkr‡tdƒ‚n|dkr |dkr¨d}ntjd|d|j	d|j
ƒ}||kr<|j
}d|j	kr|d8}d	|j	d}n
|j	d}tjd|d|d|ƒ}n|j
}d|j	krr|d8}d	|j	d}n
|j	d}tjd|d|d|ƒ}n¢|dkrc|dkrÁd}ntjddd|d|j
ƒ}||kr;tjddd|d|j
dƒ}tjddd|d|j
d
ƒ}qBtjddd|d|j
dƒ}nß|dkrÚtjd|d|jd|j	d|j
ƒ}||krÁ|tjddƒ}n|tjddƒ}nh|dkrB|j
d|d
dddƒ}||kr)|tjddƒ}n|tjddƒ}n||fS(s§This method gives you the most recently *completed* audit period.

    arguments:
            units: string, one of 'hour', 'day', 'month', 'year'
                    Periods normally begin at the beginning (UTC) of the
                    period unit (So a 'day' period begins at midnight UTC,
                    a 'month' unit on the 1st, a 'year' on Jan, 1)
                    unit string may be appended with an optional offset
                    like so:  'day@18'  This will begin the period at 18:00
                    UTC.  'month@15' starts a monthly period on the 15th,
                    and year@3 begins a yearly one on March 1st.
            before: Give the audit period most recently completed before
                    <timestamp>. Defaults to now.


    returns:  2 tuple of datetimes (begin, end)
              The begin timestamp of this audit period is the same as the
              end of the previous.
    it@itmonthtdaytyearthours,Time period must be hour, day, month or yeariitdaystminutetsecondtmicrosecondthoursN(smonthsdaysyearshour(REtinstance_usage_audit_periodtsplitRR%R	tutcnowt
ValueErrortdatetimeR¡R£R¢t	timedeltatreplace(tunittbeforetoffsettrightnowtendR£R¡tbegin((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytlast_completed_audit_periodPsx				

	

!	!		cCsÅ|dkrtj}ntjƒ}g|D]}|j|ƒ^q+}|j|ƒ|| }|t|ƒ8}dj|ƒ}|j	gt
|ƒD]}|j|ƒ^qƒ|j|ƒdj|ƒS(sGenerate a random password from the supplied symbol groups.

    At least one symbol from each group will be included. Unpredictable
    results if length is less than the number of symbol groups.

    Believed to be reasonably secure (with a reasonable password length!)

    R`N(R%REtpassword_lengthR&tSystemRandomR—tshuffleR3RR’R(tlengthtsymbolgroupstrtstpasswordtsymbolst_i((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytgenerate_password¬s	"

/
c	Csy¿tdddddd|ƒ}d}g|djd	ƒD]}tj||ƒ^q;}g|D]!}|dk	r`|jd
ƒ^q`}|ddk	rŸ|dStdƒ|}tj|ƒ‚Wn@t	k
r}tdƒi|d
6|d6}tj|ƒ‚nXdS(Ntips-ftinet6s-otaddrtshows*\s+inet6\s+([0-9a-f:]+)/\d+\s+scope\s+linkis
is#Link Local address is not found.:%ss3Couldn't get Link Local IP of %(interface)s :%(ex)st	interfacetex(
RSR«tretsearchR%tgroupR
Rt
NovaExceptiont	Exception(	RÇtif_strt	conditiontxtlinkstwR9tmsgRÈ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_my_linklocalÐs2.	cCstj|idd6dd6ƒS(s:Escapes a string so it is valid within XML or XHTML.

    s&quot;t"s&apos;t'(Rtescape(tvalue((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytxhtml_escapeáscCsS|dkst|tjƒr"|St|tjƒsFtj|ƒ}n|jdƒS(s³Try to turn a string into utf-8 if possible.

    The original code was copied from the utf8 function in
    http://github.com/facebook/tornado/blob/master/tornado/escape.py

    sutf-8N(R%R}Rctbinary_typeRdtencode(RØ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytutf8ès
cCs3t||ƒr|Sttdƒt|ƒƒ‚dS(s<Checks that obj is of type cls, and lets PyLint infer types.sExpected object of type: %sN(R}RÍR
Rz(tobjR[((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytcheck_isinstanceøscCsÖyžtj|ƒr|dfS|jdƒdkr_|jdddƒjdƒ\}}||fS|jdƒdkr~|dfS|jdƒ\}}||fSWn1ttjfk
rÑtjt	dƒ|ƒd	SXdS(
sôParses the given server_string and returns a tuple of host and port.
    If it's not a combination of host part and port, the port element
    is an empty string. If the input is invalid expression, return a tuple of
    two empty strings.
    R`s]:iÿÿÿÿt[it:sInvalid server_string: %sN(R`R`(
tnetaddrt
valid_ipv6tfindR°R«R­tAddrFormatErrorR5terrorR(t
server_strR9R:((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytparse_server_stringÿs
$

cCs@ytj|ddƒjtSWnttjfk
r;tSXdS(Ntversioni(Rát	IPNetworktcidrRet	TypeErrorRäR1(R9((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytis_valid_ipv6_cidrs
cCs%tj|ddƒ}t|jƒƒS(NRèi(Rát	IPAddressRztipv6(R9RÅ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_shortened_ipv6$scCs"tj|ddƒ}t|jƒS(NRèi(RáRéRzRê(R9tnet((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_shortened_ipv6_cidr)scCsbytj|ƒWntjk
r(tSX|jdƒ}t|ƒdksZ|ddkr^tStS(sbCheck if address is valid

    The provided address can be a IPv6 or a IPv4
    CIDR address.
    t/iR`(RáRéRäR1R«R3Re(R9t
ip_segment((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
is_valid_cidr.scCs<tj|ƒjdkrdStj|ƒjdkr8dSdS(shReturns the IP version of a network (IPv4 or IPv6).

    Raises AddrFormatError if invalid network.
    itIPv6itIPv4N(RáRéRè(tnetwork((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_ip_versionEscCsEy$tj|ƒjdkr#d|SWnttjfk
r@nX|S(sŽTransform ip string to "safe" format.

    Will return ipv4 addresses unchanged, but will nest ipv6 addresses
    inside square brackets.
    is[%s](RáRíRèRëRä(RÃ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytsafe_ip_formatPscCs$|dkr|Sdt|ƒ|fS(sÌReturns remote path in format acceptable for scp/rsync.

    If host is IPv6 address literal, return '[host]:path', otherwise
    'host:path' is returned.

    If host is None, only path is returned.
    s%s:%sN(R%Rù(thosttpath((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytformat_remote_path_scCsltjs
dStjr"tj}n	d„}x:tjD]/}|jdƒ\}}tj	|ƒ}t
|ƒtj|ƒ}xé|j
ƒD]Û\}}t|tjƒrtj	d||fƒ}xItj||ƒD]2\}	}
t||	|d|||	f|
ƒƒqÏWnt|tjƒr…tj	d||fƒ}
ttj|||d||f|
ƒƒq…q…Wq5WdS(sðIf the CONF.monkey_patch set as True,
    this function patches a decorator
    for all functions in specified modules.
    You can set decorators for each modules
    using CONF.monkey_patch_modules.
    The format is "Module path:Decorator function".
    Example:
    'nova.api.ec2.cloud:nova.notifications.notify_decorator'

    Parameters of the decorator is as follows.
    (See nova.notifications.notify_decorator)

    name - name of the function
    function - object of the function
    NcSstj|ƒptj|ƒS(N(tinspecttismethodt
isfunction(RÝ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt	is_methodƒsRàs%s.%ss%s.%s.%s(REtmonkey_patchRctPY2RýRþtmonkey_patch_modulesR«Rtimport_classt
__import__tpyclbrt
readmodule_extitemsR}tClasst
getmemberstsetattrtFunctiontsystmodules(Rtmodule_and_decoratortmoduletdecorator_namet	decoratortmodule_datatkeyRØtclztmethodtfunc((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRms(			
	$s/devcCs2tjj||ƒ}|r.|t|ƒ7}n|S(sˆReturn a path to a particular device.

    >>> make_dev_path('xvdc')
    /dev/xvdc

    >>> make_dev_path('xvdc', 1)
    /dev/xvdc1
    (tosRûRRz(tdevt	partitiontbaseRû((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
make_dev_pathœs	cCsÂd„}t|tjƒrK|jddƒ}tjrK|jdƒ}qKn||ƒ}tjdd|ƒ}tjdd|ƒ}|jƒ}|j	dƒ}|dkr¾|d	k	r¾||ƒS|S(
srReturn a hostname which conforms to RFC-952 and RFC-1123 specs except
       the length of hostname.

       Window, Linux, and Dnsmasq has different limitation:

       Windows: 255 (net_bios limits to 15, but window will truncate it)
       Linux: 64
       Dnsmasq: 63

       Due to nova-network will leverage dnsmasq to set hostname, so we chose
       63.

       cSsEt|ƒdkr=tjtdƒi|d6|d d6ƒn|d S(Ni?sJHostname %(hostname)s is longer than 63, truncate it to %(truncated_name)sthostnamettruncated_name(R3R5R6R(tname((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyttruncate_hostnameºsslatin-1tignores[ _]t-s[^\w.-]+R`s.-N(R}RcRdRÛtPY3tdecodeRÉtsubtlowertstripR%(Rtdefault_nameR ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytsanitize_hostname«s		
c
+sâd„‰‡fd†}‡fd†}‡fd†}tƒ}i}x@|jƒD]2\}}||||ƒ||<||||ƒqRWz	dVWdxF|jƒD]8\}}	|	|krÉ|||ƒq¡||||	ƒq¡WXdS(s4Temporarily set the attr on a particular object to a given value then
    revert when finished.

    One use of this is to temporarily set the read_deleted flag on a context
    object:

        with temporary_mutation(context, read_deleted="yes"):
            do_something_that_needed_deleted_objects()
    cSs
t|dƒS(Nthas_key(thasattr(tthing((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytis_dict_likeÞscs0ˆ|ƒr|j||ƒSt|||ƒSdS(N(Rtgetattr(R,tattrtdefault(R-(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRáscs-ˆ|ƒr|||<nt|||ƒdS(N(R(R,R/tval(R-(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt	set_valueçs
cs'ˆ|ƒr||=n
t||ƒdS(N(tdelattr(R,R/(R-(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytdeleteís
N(tobjectR(
RÝRRRR2R4tNOT_PRESENTt
old_valuesR/t	new_valuet	old_value((R-s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyttemporary_mutationÓs			cCsUdddtjddƒtjddƒtjddƒg}djtd„|ƒƒS(s!Generate an Ethernet MAC address.iúii>iiÿRàcSsd|S(Ns%02x((RÐ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt<lambda>s(R&R'Rtmap(tmac((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytgenerate_mac_addresss
	cCsPy#td|dtƒ\}}|SWn&tjk
rKtjd|ƒ‚nXdS(s#Secure helper to read file as root.tcatRŽt	file_pathN(RSReRRbRtFileNotFound(R@Rgt_err((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytread_file_as_roots
c	csˆ|dkrtjƒ}ntj|ƒj}||krRtd||dtƒnz	dVWd||krƒtd||dtƒnXdS(sgTemporarily chown a path.

    :param owner_uid: UID of temporary owner (defaults to current user)
    tchownRŽN(R%Rtgetuidtstattst_uidRSRe(Rût	owner_uidtorig_uid((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyttemporary_chowns	cks…|jƒ}d|kr(tj|d<ntj|}z	|VWdytj|ƒWn)tk
r}tj	t
dƒ|ƒnXXdS(NtdirsCould not remove tmpdir: %s(tcopyREttempdirttempfiletmkdtemptshutiltrmtreetOSErrorR5RåR(RRtargdictttmpdirte((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRM0s	ccsj|sg}nxT|jƒD]F}||kr|j|ƒxt||ƒD]}|VqKW|VqqWdS(s:Walk class hierarchy, yielding most derived classes first.N(t__subclasses__R‘twalk_class_hierarchy(tclazztencounteredtsubclasstsubsubclass((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRW?s	
	tUndoManagercBs5eZdZd„Zd„Zd„Zdd„ZRS(siProvides a mechanism to facilitate rolling back a series of actions
    when an exception is raised.
    cCs
g|_dS(N(t
undo_stack(RQ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyR^PscCs|jj|ƒdS(N(R]R‘(RQt	undo_func((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt	undo_withSscCs%xt|jƒD]
}|ƒqWdS(N(treversedR](RQR^((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt	_rollbackVscKs:tjƒ(|r&tj||n|jƒWdQXdS(s¦Rollback a series of actions then re-raise the exception.

        .. note:: (sirp) This should only be called within an
                  exception handler.
        N(Rtsave_and_reraise_exceptionR5RRa(RQRÓRR((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytrollback_and_reraiseZs
N(RTRUt__doc__R^R_RaR%Rc(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyR\Ls
			cCsž|dkrdg}ndd|g}|dkrF|jdgƒn|r}|dkrad}nd}|j||gƒn|j|ƒtd
||ŒdS(sçFormat a file or block device

    :param fs: Filesystem type (examples include 'swap', 'ext3', 'ext4'
               'btrfs', etc.)
    :param path: Path to file or block device to format
    :param label: Volume label to use
    tswaptmkswaptmkfss-ttext3text4tntfss-Ftmsdostvfats-ns-LRŽN(RhRiRj(Rksvfat(R’R‘RS(tfsRûtlabelRŽRft	label_opt((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRggs	
cCsuy|j|tjƒWn>tk
rX}|jtjkrR|jdtjƒqY‚nX|jƒ}|jƒ|fS(sÆReturn num bytes from the end of the file, and remaining byte count.

    :param file_like_object: The file to read
    :param num: The number of bytes to return

    :returns (data, remaining)
    i(	tseekRtSEEK_ENDtIOErrorterrnotEINVALtSEEK_SETttelltread(tfile_like_objecttnumRUt	remaining((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
last_bytes€s	cCsIi}x<|D]4}|r/|jdƒr/q
n|d||d<q
W|S(NtdeletedRØR(R(tmetadatatinclude_deletedtresulttitem((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytmetadata_to_dict˜s
cCsFg}x9tj|ƒD](\}}|jtd|d|ƒƒqW|S(NRRØ(Rct	iteritemsR‘R7(R}RRRØ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytdict_to_metadata¡s cCs-t|dtƒr|dSt|dƒSdS(NR}(R}R7R(tinstance((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
instance_meta¨scCsF|jdƒsiSt|dtƒr.|dSt|ddtƒSdS(Ntsystem_metadataR~(RR}R7RRe(R„((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytinstance_sys_meta¯s
cs‡fd†}|S(Ncs%tjˆƒ‡‡fd†ƒ}|S(Ncs€tj|ƒ}tj|ƒ\}}}}|sN|sNtˆƒt|ƒkrXˆ|ƒStdi|jd6ˆjd6ƒ‚dS(Ns^Decorated function %(f_name)s does not have the arguments expected by the decorator %(d_name)stf_nametd_name(Rtget_wrapped_functionRýt
getargspectsetRëRT(tftbase_ft	arg_namestatkwt_default(Rftdec(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
_decorator»s$

(t	functoolstwraps(R“R”(Rf(R“s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt_decorator_checkerºs!((RfR—((Rfs?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytexpects_func_args¹stExceptionHelpercBs eZdZd„Zd„ZRS(srClass to wrap another and translate the ClientExceptions raised by its
    function calls to the actual ones.
    cCs
||_dS(N(t_target(RQttarget((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyR^Óscs4t|j|ƒ‰tjˆƒ‡fd†ƒ}|S(Ncs>yˆ||ŽSWn&tjk
r9}tj|jŒnXdS(N(t	messagingtExpectedExceptionRctreraisetexc_info(RfRRRU(R(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytwrapperÙs(R.RšR•R–(RQRR ((Rs?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt__getattr__Ös(RTRURdR^R¡(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyR™Îs	icCsût|tjƒsR|d	kr-tdƒ}ntdƒ|}tjd|ƒ‚n|d	krg|}nt|ƒ|kr¬tdƒi|d6|d6}tjd|ƒ‚n|r÷t|ƒ|kr÷tdƒi|d6|d6}tjd|ƒ‚nd	S(
sãCheck the length of specified string
    :param value: the value of the string
    :param name: the name of the string
    :param min_length: the min_length of the string
    :param max_length: the max_length of the string
    s$The input is not a string or unicodes%s is not a string or unicodetmessages?%(name)s has a minimum character requirement of %(min_length)s.Rt
min_lengths1%(name)s has more than %(max_length)s characters.t
max_lengthN(R}Rctstring_typesR%R
RtInvalidInputR3(RØRR£R¤RÓ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytcheck_string_lengthâs			cCsùytt|ƒƒ}Wn@ttfk
rXtdƒ}tjd|i|d6ƒ‚nX|dk	r§||kr§tdƒ}tjd|i|d6|d6ƒ‚q§n|dk	rõ||krõtdƒ}tjd|i|d6|d6ƒ‚qõn|S(	sBMake sure that value is a valid integer, potentially within range.s!%(value_name)s must be an integertreasont
value_names'%(value_name)s must be >= %(min_value)dt	min_values'%(value_name)s must be <= %(max_value)dt	max_valueN(RRzR­tUnicodeEncodeErrorR
RR¦R%(RØRRªR«RÓ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytvalidate_integerþs&		
	
cs@tjƒ‰tjˆƒ‡‡fd†ƒ}tj|||ŽS(smPassthrough method for eventlet.spawn.

    This utility exists so that it can be stubbed for testing without
    interfering with the service spawns.

    It will also grab the context from the threadlocal store and add it to
    the store on the new thread.  This allows for continuity in logging the
    context when using this method to spawn a new thread.
    cs&ˆdk	rˆjƒnˆ||ŽS(N(R%tupdate_store(RfRR(t_contextR(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytcontext_wrapper$s
(tcommon_contexttget_currentR•R–teventlettspawn(RRfRRR°((R¯Rs?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyR´s
!csDtjƒ‰tjˆƒ‡‡fd†ƒ}tj|||ŽdS(soPassthrough method for eventlet.spawn_n.

    This utility exists so that it can be stubbed for testing without
    interfering with the service spawns.

    It will also grab the context from the threadlocal store and add it to
    the store on the new thread.  This allows for continuity in logging the
    context when using this method to spawn a new thread.
    cs*ˆdk	rˆjƒnˆ||ŽdS(N(R%R®(RfRR(R¯R(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyR°;s
N(R±R²R•R–R³tspawn_n(RRfRRR°((R¯Rs?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRµ/s
!cCs&t|tjƒstS|jƒdkS(s/Check if a string represents a None value.
    tnone(R}RcR¥R1R&(R1((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytis_none_stringFscCs#tdk	rtStjjƒatS(N(t_IS_NEUTRONR%tnovaR÷t
is_neutron(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRºOscCs@t}|dk	r<|jƒjƒ}|dkr<t}q<n|S(Ntdisabled(R1R%R'R&Re(tauto_disk_config_rawtauto_disk_config_disabledtadc_lowered((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytis_auto_disk_config_disabledYscCs(|dkrt|ƒ}n|jdƒS(Ntimage_auto_disk_config(R%R‡R(R„tsys_meta((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt"get_auto_disk_config_from_instancebscCs
|jdƒS(Ntauto_disk_config(R(timage_properties((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt%get_auto_disk_config_from_image_propshscCsi}td}xatj|jdiƒƒD]D\}}|tkrJq,nttj|ƒdƒ}||||<q,WxtD]…}|j|ƒ}|dkrà|rà|jdƒdkrÄ|d}qàt|pÐd|dƒ}n|dkròq{n||||<q{W|S(	Ns%st
propertiesiÿRRtvhdtroot_gbi(
tSM_IMAGE_PROP_PREFIXRcR‚RtSM_SKIP_KEYSt
safe_truncateRdtSM_INHERITABLE_KEYStmaxR%(t
image_metatflavortsystem_metat
prefix_formatRRØR8((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_system_metadata_from_imagels"
(

cCsÇi}i}t|tƒs0t|dtƒ}nx†tj|ƒD]u\}}|dkr^q@n|jtƒr€|t	tƒ}n|t
kr’q@n|tkr«|||<q@|||<q@W||d<|S(NR~RÆ(R}R7RReRcR‚R%t
startswithRÉR3RÊRÌ(RÐRÎRÆRRØ((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_image_from_system_metadataˆs 

cCs›tj|jdiƒƒ}i|d6}|jddƒtj|d<xEtD]=}|j|dƒ}|d	krLt|p|dƒ||<qLqLWd|d<|S(
Ntvolume_image_metadataRÆR!iRRtactivetstatus(Rsmin_disk(RLRR
tGitVIM_IMAGE_ATTRIBUTESRaR%R(tvolumeRÆRÎR/R1((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_image_metadata_from_volume¥s


cCs7t|tjƒr$|jdƒ}ntj|ƒjƒS(sƒReturns string that represents MD5 hash of base_str (in hex format).

    If base_str is a Unicode string, encode it to UTF-8.
    sutf-8(R}RcRdRÛthashlibtmd5t	hexdigest(tbase_str((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_hash_str¾scCs7t|tjƒr$|jdƒ}ntj|ƒjƒS(s@Returns string that represents sha256 hash of base_str (in hex format).

    sha1 and md5 are known to be breakable, so sha256 is a better option
    when the hash is being used for security purposes. If hashing passwords
    or anything else that needs to be retained for a long period a salted
    hash is better.
    sutf-8(R}RcRdRÛRÜtsha256RÞ(Rß((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytget_sha256_strÈscst|tƒr|g}n‡fd†‰d„‰‡‡fd†}g}x°|D]¨}ˆdkrŽ|d	kryd}n|j|iƒ}nx |D]}||||ƒ}q•WxF|jƒD]8\}	}
|ji|	d6|
d6ˆ|ƒdˆ6ƒq¾WqRW|S(
smGet all metadata for a list of resources after filtering.

    Search_filts is a list of dictionaries, where the values in the dictionary
    can be string or regex string, or a list of strings/regex strings.

    Let's call a dict a 'filter block' and an item in the dict
    a 'filter'. A tag is returned if it matches ALL the filters in
    a filter block. If more than one values are specified for a
    filter, a tag is returned if it matches ATLEAST ONE value of the filter. If
    more than one filter blocks are specified, the tag should match ALL the
    filter blocks.

    For example:

        search_filts = [{'key': ['key1', 'key2'], 'value': 'val1'},
                        {'value': 'val2'}]

    The filter translates to 'match any tag for which':
        ((key=key1 AND value=val1) OR (key=key2 AND value=val1)) AND
            (value=val2)

    This example filter will never match a tag.

        :param resource_type: The resource type as a string, e.g. 'instance'
        :param resource_list: List of resource objects
        :param search_filts: Filters to filter metadata to be returned. Can be
            dict (e.g. {'key': 'env', 'value': 'prod'}, or a list of dicts
            (e.g. [{'key': 'env'}, {'value': 'beta'}]. Note that the values
            of the dict can be regular expressions.
        :param metadata_type: Provided to search for a specific metadata type
            (e.g. 'system_metadata')

        :returns: List of dicts where each dict is of the form {'key':
            'somekey', 'value': 'somevalue', 'instance_id':
            'some-instance-uuid-aaa'} if resource_type is 'instance'.
    csˆdkr|jdƒSdS(NR„tuuid(R(tresource(t
resource_type(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt_get_idÿscSsDt|tƒr|g}ntg|D]}tj||ƒ^q%ƒS(N(R}RztanyRÉtmatch(tpattern_listtstringtpattern((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
_match_anysc	sê|jdgƒ}|jdgƒ}|jdgƒ}i}|rXˆ|ƒ|krXiSx‹tj|ƒD]z\}}|r¦|r¦ˆ||ƒr¦ˆ||ƒr¦qhn2|r¼ˆ||ƒsh|r؈||ƒrØqhn|||<qhW|S(Ntresource_idRRØ(RRcR‚(	Rätsearch_filttinput_metadatatidstkeys_filtert
values_filtertoutput_metadatatktv(RæRì(s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt_filter_metadata	s R„R}RRØs%s_idN(R}R7R%RRR‘(Råt
resource_listtsearch_filtst
metadata_typeRötformatted_metadata_listtresR}tfiltRôRõ((RæRìRås?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt#filter_and_format_resource_metadataÕs"'	
	
cCsatj|ƒ| }t}xA|s\ytj|ƒ}t}Wqtk
rX|d }qXqW|S(spSafely truncates unicode strings such that their encoded length is
    no greater than the length provided.
    iÿÿÿÿ(Rtsafe_encodeR1tsafe_decodeRetUnicodeDecodeError(RØR»tb_valuet	decode_oktu_value((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRË7s	

cCs²|rt|ƒnt}tjj|ƒ}tj|iƒ}|s\||jddƒkr¤tj	d|ƒt
|ƒ}|jƒ|d<WdQX||d<t}n||dfS(s¿Read from a file if it has been modified.

    :param force_reload: Whether to reload the file.
    :returns: A tuple with a boolean specifying if the data is fresh
              or not.
    tmtimeisReloading cached file %sR=N(
tdelete_cached_fileR1RRûtgetmtimet_FILE_CACHEt
setdefaultRR5tdebugtopenRwRe(tfilenametforce_reloadtreloadedRt
cache_infotfap((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytread_cached_fileKs	

	cCs|tkrt|=ndS(sLDelete cached file if present.

    :param filename: filename to delete
    N(R(R((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyRdscCse|stjƒ}n|jdƒ}|jr?|jjdƒnd}||dkrZdn|7}|S(ssCurrent time as ISO string,
    as timeutils.isotime() is deprecated

    :returns: Current time in ISO format
    s%Y-%m-%dT%H:%M:%StUTCtZN(R	R¬tstrftimettzinfottznameR%(tattdate_stringttz((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytisotimeos!cCs
|jdƒS(Ns%Y-%m-%dT%H:%M:%S.%f(R(R((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pytstrtime}stPropertytValuec
CsItj||gƒ}d|_xêt|jƒƒD]Ö\}}t|tƒr^tj|ƒ}n|dkrˆt	j
tj|ƒ|ƒ}n|rôt|tjƒrôd|krô|jƒj
dƒ}|}x=|D]}	|j||	gƒd}qÎWq1|j||gƒq1Wtjr+tj|jƒƒGHntj|jƒƒjƒGHdS(sôPrint a `dict` as a table of two columns.

    :param dct: `dict` to print
    :param dict_property: name of the first column
    :param wrap: wrapping for the second column
    :param dict_value: header label for the value (second) column
    tlis\nR`N(tprettytabletPrettyTabletaligntsortedRR}R7RcRdttextwraptfillR¥R'R«tadd_rowRRRþt
get_stringR$(
tdctt
dict_propertytwrapt
dict_valuetptRôRõtlinestcol1tline((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
print_dicts"	$

	cOsœtj|ƒ}t|jpgƒ}|jt|jƒ| }tj|ƒdk	rc|jdƒng|D]}||krj|^qj}|t|ƒ}|S(séCheck that the supplied args are sufficient for calling a function.

    >>> validate_args(lambda a: None)
    Traceback (most recent call last):
        ...
    MissingArgs: Missing argument(s): a
    >>> validate_args(lambda a, b, c, d: None, 0, c=1)
    Traceback (most recent call last):
        ...
    MissingArgs: Missing argument(s): b, d

    :param fn: the function to check
    :param arg: the positional arguments supplied
    :param kwargs: the keyword arguments supplied
    iN(	RýR‹R3tdefaultsRfRctget_method_selfR%Ra(tfnRfRRtargspectnum_defaultst
required_argstargtmissing((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt
validate_args¢s%(smin_ramsmin_disksdisk_formatR(RRRR(RR ssizeschecksumRsdisk_formatsmin_ramsmin_disk(RRžRŸ(RRž(ŠRdt
contextlibRLR®RsR•RÜRýRRR&RÉRPR(R+R
RNR"Rƒtxml.saxRR³Rátoslo_concurrencyRRtoslo_contextRR±toslo_logRR{toslo_messagingRœt
oslo_utilsRRRRR	R
RRct	six.movesRt	nova.confR¹Rt	nova.i18nR
RRRtnova.networkRtconfREt	getLoggerRTR5t
TIME_UNITSR%R¸tsynchronized_with_prefixRRÉRÌRÊRÙRRCRJRNR5RMRLRSR•RPRœtDEFAULT_PASSWORD_SYMBOLStEASIER_PASSWORD_SYMBOLSR·RÂRÔRÙRÜRÞRçRìRïRñRôRøRùRüRRR)tcontextmanagerR:R>RCRJRMRWR\R1RgR{RRƒR…R‡R˜R™R§R­R´RµR·RºR¿RÂRÅRÒRÔRÛRàRâRýRËRRRRR.R7(((s?/home/tvault/.virtenv/lib/python2.7/site-packages/nova/utils.pyt<module>sú"
4		
k			\$													/(1			
					
						
						
	a			!