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    
python3-dmapi / usr / lib / python3.6 / site-packages / dmapi / __pycache__ / utils.cpython-36.opt-1.pyc
Size: Mime:
3

ÿn‚aWªã@sÂdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZddlZddlmZddlmZddlmZddlmZ ddl!Z"dd	l#m$Z$dd
l#m%Z%ddl#m&Z&ddl#m'Z'dd
l#m(Z(ddl#m)Z)ddl*Z*ddl+m,Z,ddl-Z.ddl.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4ddl.m5Z5e&j6dƒZ7e.j8j9Z9e j:e;ƒZ<dZ=ej>dƒZ?dZ@dZAdŽZBdZCiaDeEed"ƒrÊejFZGnejGZGd#d$„ZHGd%d&„d&eIƒZJGd'd(„d(eJƒZKd)d*„ZLd+d,„ZMd-d.„ZNdd0d1„ZOd‘d2d3„ZPd4d5„ZQd6d7„ZRd8d9„ZSd:d;„ZTd<d=„ZUd>d?„ZVd@dA„ZWd’dBdC„ZXejYdDdE„ƒZZejYd“dFdG„ƒZ[ejYdHdI„ƒZ\d”dJdK„Z]GdLdM„dMeIƒZ^d•dOdP„Z_d–dQdR„Z`dSdT„ZadUdV„ZbdWdX„ZcdYdZ„ZdGd[d\„d\eIƒZed—d]d^„Zfd˜d_d`„Zgdadb„Zhdcdd„Zidedf„Zjdgdh„Zkdidj„Zld™dkdl„Zmdmdn„Zndšdodp„Zodqdr„Zpdsdt„Zqdudv„Zrdwdx„Zsdydz„Ztd›d{d|„Zud}d~„Zvdœdd€„Zwdd‚„Zxddƒd„„Zyd…d†„Zzd‡dˆ„Z{d‰dŠ„Z|d‹dŒ„Z}dS)žzUtilities and helper functions.éN)Ú
exceptions)Úloading)Ú	lockutils)Úprocessutils)Úcontext)Úlog)Úencodeutils)Úexcutils)Úimportutils)Ústrutils)Ú	timeutils)Úunits)Úrange)Ú	exception)Ú_Ú_LEÚ_LIÚ_LW)Ú
safe_utilszosprofiler.profilerzdmapi-Zimage_Úmin_ramÚmin_diskÚdisk_formatÚcontainer_formatÚmappingsÚblock_device_mappingÚimg_mappingsÚimg_block_device_mappingÚimage_idÚ
image_nameÚsizeÚchecksumÚgetfullargspeccCstjjrd}n
dtj}|S)NÚsudozsudo dmapi-rootwrap %s)ÚCONFZworkaroundsZdisable_rootwrapÚrootwrap_config)Úcmd©r&ú/usr/lib/python3.6/utils.pyÚget_root_helperUs
r(c@seZdZdd„Zdd„ZdS)ÚRootwrapProcessHelpercOstƒ|d<tj||ŽS)NÚroot_helper)r(rÚtrycmd)Úselfr%Úkwargsr&r&r'r+^s
zRootwrapProcessHelper.trycmdcOstƒ|d<tj||ŽS)Nr*)r(rÚexecute)r,r%r-r&r&r'r.bs
zRootwrapProcessHelper.executeN)Ú__name__Ú
__module__Ú__qualname__r+r.r&r&r&r'r)]sr)c@s8eZdZiZedƒdd„ƒZdd„Zdd„Zdd	„Zd
S)ÚRootwrapDaemonHelperzdaemon-client-lockcCsJy
|j|Stk
rDddlm}|jdd|gƒ}||j|<|SXdS)Nr)Úclientr"zdmapi-rootwrap-daemon)Ú_clientsÚKeyErrorZ
oslo_rootwrapr3ZClient)Úclsr$r3Z
new_clientr&r&r'Ú_get_clientjs

z RootwrapDaemonHelper._get_clientcCs|j|ƒ|_dS)N)r7r3)r,r$r&r&r'Ú__init__uszRootwrapDaemonHelper.__init__cOsx|jddƒ}y|j||Ž\}}d}Wn8tjk
r\}zdtj|ƒ}}d}WYdd}~XnX|rp|rp|rpd}||fS)NÚdiscard_warningsFÚT)Úpopr.rÚProcessExecutionErrorÚsixÚ	text_type)r,Úargsr-r9ÚoutÚerrZfailedZexnr&r&r'r+xszRootwrapDaemonHelper.trycmdcOsdd„|Dƒ}|jdtjƒ}|jddƒ}|jddƒ}|jddƒ}|jdd	ƒ}|jd
dgƒ}d}	t|tƒrv|}	dg}nt|tƒr†|g}tjd
j|ƒƒ}
t	j
tdƒ|
|dœƒxh|dkr|d	8}ytjƒ}t	j
|tdƒ|
ƒ|jj||ƒ\}}
}tjƒ|}t	j
|d|
||dœƒ|	rL||krLtj|
ƒ}
tj|ƒ}tj||
||
d‚|
|fStjk
r}z |tjksˆ|tjkr´|r´tdƒ}t	j
|||j|j|j|j|jdœƒ|sÐt	j
|tdƒ|
ƒ‚n2t	j
|tdƒ|
ƒ|rtjtjƒjddƒdƒWYdd}~Xq°Xq°WdS)NcSsg|]}t|ƒ‘qSr&)Ústr)Ú.0Úcr&r&r'ú
<listcomp>Šsz0RootwrapDaemonHelper.execute.<locals>.<listcomp>ÚloglevelÚ
log_errorsÚ
process_inputÚdelay_on_retryTÚattemptséÚcheck_exit_coderFú zHExecuting RootwrapDaemonHelper.execute cmd=[%(cmd)r] kwargs=[%(kwargs)r])r%r-zRunning cmd (subprocess): %szECMD "%(sanitized_cmd)s" returned: %(return_code)s in %(end_time)0.3fs)Ú
sanitized_cmdZreturn_codeÚend_time)Ú	exit_codeÚstdoutÚstderrr%zS%(desc)r
command: %(cmd)r
exit code: %(code)r
stdout: %(stdout)r
stderr: %(stderr)r)Zdescr%ÚcoderQrRz%r failed. Not Retrying.z%r failed. Retrying.ééÈgY@)r;ÚloggingÚDEBUGÚ
isinstanceÚboolÚintrZ
mask_passwordÚjoinÚLOGÚinforÚtimerrr3r.rr<ZLOG_ALL_ERRORSZLOG_FINAL_ERRORÚdescriptionr%rPrQrRZsleepÚrandomÚSystemRandomZrandint)r,r%r-rFrGrHrIrJrLZignore_exit_coderNZ
start_timeÚ
returncoder@rArOÚformatr&r&r'r.…st





zRootwrapDaemonHelper.executeN)	r/r0r1r4Úsynchronizedr7r8r+r.r&r&r&r'r2gs

r2cOsDd|kr8|jdƒr8tjr*ttjƒj||ŽStƒj||ŽStj||ŽS)z3Convenience wrapper around oslo's execute() method.Úrun_as_root)Úgetr#Úuse_rootwrap_daemonr2r$r.r)r)r%r-r&r&r'r.Ós
r.cOs(dddg}|j|ƒ|j|ƒt||ŽS)z+Convenience wrapper to execute ssh command.Zsshz-oz
BatchMode=yes)ÚappendÚextendr.)Údestr%r-Zssh_cmdr&r&r'Ússh_executeÞs


rkcOs>|jddƒr2tjr$ttjƒj||ŽStƒj||ŽStj||ŽS)z2Convenience wrapper around oslo's trycmd() method.reF)rfr#rgr2r$r+r)r)r?r-r&r&r'r+æs
r+écs,d‰‡fdd„t|ƒDƒ}d|dj|ƒfS)NZ%01234567890abcdefghijklmnopqrstuvwxyzcsg|]}tjƒjˆƒ‘qSr&)r`raZchoice)rCZ_x)Ú
charactersr&r'rEósz generate_uid.<locals>.<listcomp>z%s-%sr:)rr[)ZtopicrÚchoicesr&)rmr'Úgenerate_uidñsrocCs&|s
tj}d}d|kr.|jddƒ\}}t|ƒ}|dk	r<|}ntjƒ}|dkrXttd	ƒƒ‚|dkr|dkrnd}tj||j	|j
d
}||krÌ|j
}d|j	kr²|d8}d|j	d}n
|j	d}tj|||d
}|j
}d|j	krô|d8}d|j	d}n
|j	d}tj|||d
}n|dkrŒ|dkr*d}tjd||j
d
}||krttjd||j
dd
}tjd||j
dd
}ntjd||j
dd
}n’|dkrÚtj||j|j	|j
d
}||krÈ|tjdd}|tjdd}nD|dkr|j
|ddd}||kr|tjdd}|tjdd}||fS)a§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.
    rú@rKNÚmonthÚdayÚyearÚhourz,Time period must be hour, day, month or year)rrrqrséé)rtrrrqrs)Zdays)ZminuteÚsecondZmicrosecond)Zhours)rqrrrsrt)r#Zinstance_usage_audit_periodÚsplitrZrÚutcnowÚ
ValueErrorrÚdatetimerqrsrrZ	timedeltaÚreplace)ZunitZbeforeÚoffsetZrightnowÚendrsrqZbeginr&r&r'Úlast_completed_audit_period÷sx













rcCs8|dkst|tjƒr|St|tjƒs.tj|ƒ}|jdƒS)z³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

    Nzutf-8)rXr=Zbinary_typer>Úencode)Úvaluer&r&r'Úutf8Ts

r‚cCsœyltj|ƒr|dfS|jdƒdkrB|jdddƒjdƒ\}}||fS|jdƒd	krX|dfS|jdƒ\}}||fSttjfk
r–tjt	dƒ|ƒd
SXdS)zô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:z]:rKú[ú:zInvalid server_string: %sNéÿÿÿÿr…)r:r:)
ÚnetaddrZ
valid_ipv6Úfindr|rxrzÚAddrFormatErrorr\Úerrorr)Z
server_strÚaddressZportr&r&r'Úparse_server_stringds
r‹cCstj|dd}t|jƒƒS)Né)Úversion)r†Ú	IPAddressrBZipv6)rŠZaddrr&r&r'Úget_shortened_ipv6srcCstj|dd}t|jƒS)NrŒ)r)r†Z	IPNetworkrBZcidr)rŠZnetr&r&r'Úget_shortened_ipv6_cidr†srcCs<ytj|ƒjdkrd|SWnttjfk
r6YnX|S)zŽTransform ip string to "safe" format.

    Will return ipv4 addresses unchanged, but will nest ipv6 addresses
    inside square brackets.
    rŒz[%s])r†rŽrÚ	TypeErrorrˆ)Zipr&r&r'Úsafe_ip_format‹sr’cCs|dkr|Sdt|ƒ|fS)zÌ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.
    Nz%s:%s)r’)ÚhostÚpathr&r&r'Úformat_remote_pathšsr•cCstjs
dStjdƒtjr"tj}ndd„}xätjD]Ú}|j	dƒ\}}t
j|ƒ}t|ƒt
j|ƒ}xªt|jƒƒD]š\}}t|t
jƒrÊt
jd||fƒ}x4tj||ƒD]$\}	}
t||	|d|||	f|
ƒƒq¢Wt|t
jƒrnt
jd||fƒ}
ttj|||d||f|
ƒƒqnWq2WdS)aÿDEPRECATED: 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:
    'dmapi.api.ec2.cloud:dmapi.notifications.notify_decorator'

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

    name - name of the function
    function - object of the function
    Nz0Monkey patching dmapi is deprecated for removal.cSstj|ƒptj|ƒS)N)ÚinspectÚismethodZ
isfunction)Úobjr&r&r'Ú	is_methodÀszmonkey_patch.<locals>.is_methodr„z%s.%sz%s.%s.%s)r#Úmonkey_patchr\Úwarningr=ÚPY2r–r—Zmonkey_patch_modulesrxr
Zimport_classÚ
__import__ÚpyclbrZ
readmodule_exÚlistÚitemsrXZClassZ
getmembersÚsetattrZFunctionÚsysÚmodules)r™Zmodule_and_decoratorÚmoduleZdecorator_nameZ	decoratorZmodule_dataÚkeyrZclzÚmethodÚfuncr&r&r'rš©s*


ršcCs‚dd„}t|tjƒr0|jddƒ}tjr0|jdƒ}||ƒ}tjdd|ƒ}tjdd|ƒ}|jƒ}|j	d	ƒ}|dkr~|d
k	r~||ƒS|S)asReturn 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 dmapi-network will leverage dnsmasq to set hostname, so we chose
       63.

       cSs6t|ƒdkr*tjtdƒ||dd…dœƒ|dd…S)Né?zJHostname %(hostname)s is longer than 63, truncate it to %(truncated_name)s)ÚhostnameZtruncated_name)Úlenr\r›r)Únamer&r&r'Útruncate_hostnameès
z,sanitize_hostname.<locals>.truncate_hostnamezlatin-1Úignorez[ _]ú-z[^\w.-]+r:z.-N)
rXr=r>r€ÚPY3ÚdecodeÚreÚsubÚlowerÚstrip)r©Zdefault_namer¬r&r&r'Úsanitize_hostnameÙs

rµc
+s¸dd„‰‡fdd„}‡fdd„}‡fdd„}tƒ}i}x4t|jƒƒD]$\}}||||ƒ||<||||ƒqDWz
d	VWd	x8t|jƒƒD](\}}	|	|kr¢|||ƒq†||||	ƒq†WXd	S)
a4Temporarily 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()
    cSst|dƒpt|tƒS)NZhas_key)ÚhasattrrXÚdict)Úthingr&r&r'Úis_dict_likesz(temporary_mutation.<locals>.is_dict_likecs$ˆ|ƒr|j||ƒSt|||ƒSdS)N)rfÚgetattr)r¸ÚattrÚdefault)r¹r&r'rfsztemporary_mutation.<locals>.getcs"ˆ|ƒr|||<nt|||ƒdS)N)r¡)r¸r»Úval)r¹r&r'Ú	set_values
z%temporary_mutation.<locals>.set_valuecsˆ|ƒr||=n
t||ƒdS)N)Údelattr)r¸r»)r¹r&r'Údeletesz"temporary_mutation.<locals>.deleteN)ÚobjectrŸr )
r˜r-rfr¾rÀZNOT_PRESENTZ
old_valuesr»Ú	new_valueZ	old_valuer&)r¹r'Útemporary_mutations
rÃc
csb|dkrtjƒ}tj|ƒj}||kr6tjjj||dz
dVWd||kr\tjjj||dXdS)zgTemporarily chown a path.

    :param owner_uid: UID of temporary owner (defaults to current user)
    N)Zuid)ÚosÚgetuidÚstatÚst_uidÚdmapiZprivsepr”Úchown)r”Z	owner_uidZorig_uidr&r&r'Útemporary_chown6s
rÊcksz|jƒ}d|krtj|d<tjf|Ž}z
|VWdytj|ƒWn2tk
rr}ztj	t
dƒ|ƒWYdd}~XnXXdS)NÚdirzCould not remove tmpdir: %s)Úcopyr#ÚtempdirÚtempfileZmkdtempÚshutilZrmtreeÚOSErrorr\r‰r)r-ZargdictZtmpdirÚer&r&r'rÍJs

rÍccsP|sg}xB|jƒD]6}||kr|j|ƒxt||ƒD]
}|Vq4W|VqWdS)z:Walk class hierarchy, yielding most derived classes first.N)Ú__subclasses__rhÚwalk_class_hierarchy)ZclazzZencounteredÚsubclassZsubsubclassr&r&r'rÓYs

rÓc@s2eZdZdZdd„Zdd„Zdd„Zdd	d
„ZdS)ÚUndoManagerziProvides a mechanism to facilitate rolling back a series of actions
    when an exception is raised.
    cCs
g|_dS)N)Ú
undo_stack)r,r&r&r'r8jszUndoManager.__init__cCs|jj|ƒdS)N)rÖrh)r,Ú	undo_funcr&r&r'Ú	undo_withmszUndoManager.undo_withcCsxt|jƒD]
}|ƒqWdS)N)ÚreversedrÖ)r,r×r&r&r'Ú	_rollbackpszUndoManager._rollbackNc
Ks2tjƒ |rtj|f|Ž|jƒWdQRXdS)z¦Rollback a series of actions then re-raise the exception.

        .. note:: (sirp) This should only be called within an
                  exception handler.
        N)r	Úsave_and_reraise_exceptionr\rrÚ)r,Úmsgr-r&r&r'Úrollback_and_reraisets
z UndoManager.rollback_and_reraise)N)r/r0r1Ú__doc__r8rØrÚrÝr&r&r&r'rÕfs
rÕFcCsn|dkrdg}n
dd|g}|dkr.|jdgƒ|rR|dkr@d}nd}|j||gƒ|j|ƒt|d
|iŽdS)zç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
    ZswapZmkswapÚmkfsz-tÚext3Úext4Úntfsz-FÚmsdosÚvfatz-nz-LreN)ràrárâ)rãrä)rirhr.)Zfsr”Zlabelrer?Z	label_optr&r&r'r߁s

rßcCs8i}x.|D]&}|r |jdƒr q
|d||d<q
W|S)NZdeletedrr¥)rf)ÚmetadataÚinclude_deletedÚresultÚitemr&r&r'Úmetadata_to_dictšs
récCs4g}x*t|jƒƒD]\}}|jt||dƒqW|S)N)r¥r)rŸr rhr·)rårçr¥rr&r&r'Údict_to_metadata£srêcCs&t|dtƒr|dSt|dƒSdS)Nrå)rXr·ré)Úinstancer&r&r'Ú
instance_metaªsrìcCs8|jdƒsiSt|dtƒr$|dSt|dddSdS)NZsystem_metadataT)ræ)rfrXr·ré)rër&r&r'Úinstance_sys_meta±s
rícs‡fdd„}|S)Ncstjˆƒ‡‡fdd„ƒ}|S)NcsVtj|ƒ}tj|ƒ\}}}}|s4|s4tˆƒt|ƒkr<ˆ|ƒStd|jˆjdœƒ‚dS)Nz^Decorated function %(f_name)s does not have the arguments expected by the decorator %(d_name)s)Zf_nameZd_name)rZget_wrapped_functionr–Ú
getargspecÚsetr‘r/)ÚfZbase_fZ	arg_namesÚaÚkwZ_default)r?Údecr&r'Ú
_decorator½s
zAexpects_func_args.<locals>._decorator_checker.<locals>._decorator)Ú	functoolsÚwraps)rórô)r?)rór'Ú_decorator_checker¼sz-expects_func_args.<locals>._decorator_checkerr&)r?r÷r&)r?r'Úexpects_func_args»srøc@s eZdZdZdd„Zdd„ZdS)ÚExceptionHelperzrClass to wrap another and translate the ClientExceptions raised by its
    function calls to the actual ones.
    cCs
||_dS)N)Ú_target)r,Útargetr&r&r'r8ÕszExceptionHelper.__init__cs&t|j|ƒ‰tjˆƒ‡fdd„ƒ}|S)Ncs@y
ˆ||ŽStjk
r:}ztj|jŽWYdd}~XnXdS)N)Ú	messagingZExpectedExceptionr=ZreraiseÚexc_info)r?r-rÑ)r§r&r'ÚwrapperÛs
z,ExceptionHelper.__getattr__.<locals>.wrapper)rºrúrõrö)r,r«rþr&)r§r'Ú__getattr__ØszExceptionHelper.__getattr__N)r/r0r1rÞr8rÿr&r&r&r'rùÐsrùcCsžt|tjƒs6|dkrtdƒ}ntdƒ|}tj|d‚|dkrB|}t|ƒ|krltdƒ||dœ}tj|d‚|ršt|ƒ|krštdƒ||dœ}tj|d‚dS)	zã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
    Nz$The input is not a string or unicodez%s is not a string or unicode)Úmessagez?%(name)s has a minimum character requirement of %(min_length)s.)r«Ú
min_lengthz1%(name)s has more than %(max_length)s characters.)r«Ú
max_length)rXr=Ústring_typesrrÚInvalidInputrª)rr«rrrÜr&r&r'Úcheck_string_lengthäs
rcCsJytj||||ƒStk
rD}ztjtj|ƒd‚WYdd}~XnXdS)aAMake sure that value is a valid integer, potentially within range.

    :param value: value of the integer
    :param name: name of the integer
    :param min_value: min_value of the integer
    :param max_value: max_value of the integer
    :returns: integer
    :raise: InvalidInput If value is not a valid integer
    )ÚreasonN)rÚvalidate_integerrzrrr=r>)rr«Z	min_valueZ	max_valuerÑr&r&r'rs
rcCs2tsdStjƒ}d}|r.|j|jƒ|jƒdœ}|S)N)Úhmac_keyZbase_idZ	parent_id)ÚprofilerrfrZget_base_idZget_id)ZprofZ
trace_infor&r&r'Ú_serialize_profile_infosr
cs:tjƒ‰tƒ‰tjˆƒ‡‡‡fdd„ƒ}tj|f|ž|ŽS)amPassthrough 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ƒˆr$tr$tjfˆŽˆ||ŽS)N)Úupdate_storer	Úinit)r?r-)Ú_contextr§Ú
profiler_infor&r'Úcontext_wrapper-s
zspawn.<locals>.context_wrapper)Úcommon_contextÚget_currentr
rõröÚeventletÚspawn)r§r?r-rr&)r
r§rr'r s

rcs>tjƒ‰tƒ‰tjˆƒ‡‡‡fdd„ƒ}tj|f|ž|ŽdS)aoPassthrough 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.
    cs2ˆdk	rˆjƒˆr$tr$tjfˆŽˆ||ŽdS)N)rr	r)r?r-)r
r§rr&r'rGs
z spawn_n.<locals>.context_wrapperN)rrr
rõrörÚspawn_n)r§r?r-rr&)r
r§rr'r:s

rcCst|tjƒsdS|jƒdkS)z/Check if a string represents a None value.
    FZnone)rXr=rr³)r½r&r&r'Úis_none_stringTsrcCs(d}|dk	r$|jƒjƒ}|dkr$d}|S)NFZdisabledT)r´r³)Zauto_disk_config_rawZauto_disk_config_disabledZadc_loweredr&r&r'Úis_auto_disk_config_disabled]srcCs|dkrt|ƒ}|jdƒS)NZimage_auto_disk_config)rírf)rëZsys_metar&r&r'Ú"get_auto_disk_config_from_instancefsrcCs
|jdƒS)NZauto_disk_config)rf)Zimage_propertiesr&r&r'Ú%get_auto_disk_config_from_image_propslsrcCs¼i}td}xFt|jdiƒjƒƒD].\}}|tkr4q"ttj|ƒdƒ}||||<q"WxbtD]Z}|j|ƒ}|dkrž|rž|jdƒdkrŒ|d}nt	|p”d|dƒ}|dkr¨qZ||||<qZW|S)	Nz%sÚ
propertieséÿrrZvhdZroot_gbr)
ÚSM_IMAGE_PROP_PREFIXrŸrfr ÚSM_SKIP_KEYSÚ
safe_truncater=r>ÚSM_INHERITABLE_KEYSÚmax)Ú
image_metaZflavorÚsystem_metaZ
prefix_formatr¥rrÂr&r&r'Úget_system_metadata_from_imageps"


r"cCsŒi}i}t|tƒst|dd}x`t|jƒƒD]P\}}|dkr>q,|jtƒrX|ttƒd…}|tkrbq,|t	krt|||<q,|||<q,W||d<|S)NT)rær)
rXr·rérŸr Ú
startswithrrªrr)r!r rr¥rr&r&r'Úget_image_from_system_metadataŒs 


r$cCsntj|jdiƒƒ}d|i}|jddƒtj|d<x0tD](}|j|dƒ}|d	kr6t|pVdƒ||<q6Wd|d<|S)
NZvolume_image_metadatarrrrrZactiveZstatus)rr)rÌrfr
ZGiÚVIM_IMAGE_ATTRIBUTESr;rZ)Zvolumerr r»r½r&r&r'Úget_image_metadata_from_volume©s
r&cCs$t|tjƒr|jdƒ}tj|ƒjƒS)zƒReturns string that represents MD5 hash of base_str (in hex format).

    If base_str is a Unicode string, encode it to UTF-8.
    zutf-8)rXr=r>r€ÚhashlibZmd5Ú	hexdigest)Úbase_strr&r&r'Úget_hash_strÂs
r*cCs$t|tjƒr|jdƒ}tj|ƒjƒS)a@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.
    zutf-8)rXr=r>r€r'Zsha256r()r)r&r&r'Úget_sha256_strÌs
r+cCst|ƒ}tjstj|dƒ}|S)z½Returns a string representation of an object converted to unicode.

    In the case of python 3, this just returns the repr() of the object,
    else it converts the repr() to unicode.
    zutf-8)Úreprr=r¯r>)r˜Zobj_reprr&r&r'Úget_obj_repr_unicodeÙsr-c
sºt|tƒr|g}‡fdd„‰dd„‰‡‡fdd„}g}x~|D]v}ˆdkr`|dkrTd	}|j|iƒ}x|D]}||||ƒ}qfWx6t|jƒƒD]&\}	}
|jd
|	d|
dˆˆ|ƒiƒqˆWq<W|S)
amGet 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ëZuuid)rf)Úresource)Ú
resource_typer&r'Ú_get_idsz4filter_and_format_resource_metadata.<locals>._get_idcs&t|tƒr|g}t‡fdd„|DƒƒS)Ncsg|]}tj|ˆƒ‘qSr&)r±Úmatch)rCÚpattern)Ústringr&r'rEszKfilter_and_format_resource_metadata.<locals>._match_any.<locals>.<listcomp>)rXrBÚany)Zpattern_listr3r&)r3r'Ú
_match_anys
z7filter_and_format_resource_metadata.<locals>._match_anyc	s¨|jdgƒ}|jdgƒ}|jdgƒ}i}|r<ˆ|ƒ|kr<iSxft|jƒƒD]V\}}|rv|rvˆ||ƒrvˆ||ƒrvqJn"|r†ˆ||ƒsJ|r˜ˆ||ƒr˜qJ|||<qJW|S)NZresource_idr¥r)rfrŸr )	r.Zsearch_filtZinput_metadataZidsZkeys_filterZ
values_filterZoutput_metadataÚkÚv)r0r5r&r'Ú_filter_metadatas z=filter_and_format_resource_metadata.<locals>._filter_metadatarëNrår¥rz%s_id)rXr·rfrŸr rh)r/Z
resource_listZsearch_filtsZ
metadata_typer8Zformatted_metadata_listÚresråZfiltr6r7r&)r0r5r/r'Ú#filter_and_format_resource_metadataås"'


r:cCsXtj|ƒd|…}d}x<|sRytj|ƒ}d}Wqtk
rN|dd…}YqXqW|S)zpSafely truncates unicode strings such that their encoded length is
    no greater than the length provided.
    NFTrKr…)rZsafe_encodeZsafe_decodeÚUnicodeDecodeError)rZlengthZb_valueZ	decode_okZu_valuer&r&r'rGs
rc
Cs‚|rt|ƒd}tjj|ƒ}tj|iƒ}|s>||jddƒkrvtjd|ƒt	|ƒ}|j
ƒ|d<WdQRX||d<d}||dfS)z¿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.
    FÚmtimerzReloading cached file %sÚdataNT)Údelete_cached_filerÄr”ÚgetmtimeÚ_FILE_CACHEÚ
setdefaultrfr\ÚdebugÚopenÚread)ÚfilenameZforce_reloadZreloadedr<Ú
cache_infoZfapr&r&r'Úread_cached_file[s	
rGcCs|tkrt|=dS)zLDelete cached file if present.

    :param filename: filename to delete
    N)r@)rEr&r&r'r>tsr>cCsD|stjƒ}|jdƒ}|jr(|jjdƒnd}||dkr:dn|7}|S)zsCurrent time as ISO string,
    as timeutils.isotime() is deprecated

    :returns: Current time in ISO format
    z%Y-%m-%dT%H:%M:%SNÚUTCú	UTC+00:00ÚZ)rHrI)rryÚstrftimeZtzinfoZtzname)ÚatZdate_stringZtzr&r&r'Úisotimes
rMcCs
|jdƒS)Nz%Y-%m-%dT%H:%M:%S.%f)rK)rLr&r&r'ÚstrtimesrNcCs¦|jr|jS|jdkr6y
|jƒjStk
r4YnXy|jƒStjk
rTYnXt|j	ƒ}x2|D]*}||_	y|jƒStjk
rŽYqfXqfWtjd|ƒ‚dS)añGet the endpoint URL represented by a keystoneauth1 Adapter.

    This method is equivalent to what

        ksa_adapter.get_endpoint()

    should do, if it weren't for a panoply of bugs.

    :param ksa_adapter: keystoneauth1.adapter.Adapter, appropriately set up
                        with an endpoint_override; or service_type, interface
                        (list) and auth/service_catalog.
    :return: String endpoint URL.
    :raise EndpointNotFound: If endpoint discovery fails.
    ZimagezICould not find requested endpoint for any of the following interfaces: %sN)
Zendpoint_overrideZservice_typeZget_endpoint_dataZcatalog_urlÚAttributeErrorÚget_endpointÚks_excZEndpointNotFoundrŸÚ	interface)Zksa_adapterZ
interfacesrRr&r&r'rP‘s*





rPc*CsœttdƒstjdƒdStjj|dƒ}d}d}zyXtj|tjtjBtj	Bƒ}d}t
j
d|ƒ}|jd|ƒtj||ƒtjd	d
|iƒWn´tk
rö}zP|j
t
jkrÀtjd||dœƒd}n&tjƒtjd
||dœƒWdQRXWYdd}~XnJtk
r>}z,tjƒtjd
||dœƒWdQRXWYdd}~XnXWd|dk	rXtj|ƒytj|ƒWn.tk
r”}ztj|ƒWYdd}~XnXX|S)NÚO_DIRECTz/This python runtime does not support direct I/OFz.directio.testTirKóxz#Path '%(path)s' supports direct I/Or”z5Path '%(path)s' does not support direct I/O: '%(ex)s')r”Úexz7Error on '%(path)s' while checking direct I/O: '%(ex)s'r…)r¶rÄr\rBr”r[rCÚO_CREATÚO_WRONLYrSÚmmapÚwriterÐÚerrnoZEINVALr	rÛr‰Ú	ExceptionÚcloseÚunlinkr)ÚdirpathZtestfileZhasDirectIOÚfdZ
align_sizeÚmrÑrUr&r&r'Úsupports_direct_ioÆsD


&
,


racCs&tjrtj|ƒdStj|ƒdSdS)Nr)r=rœr–rîr!)r§r&r&r'Úget_func_valid_keysösrb)rrrr)rrrr)rrrr rrrr)rl)NN)N)N)N)NF)F)NrN)NN)NN)N)N)F)N)~rÞÚ
contextlibrÌr{rZrõr'r–rXrÄržr`r±rÏr¢rÎr^rZ
keystoneauth1rrQrZ
ks_loadingr†Zoslo_concurrencyrrZoslo_contextrrZoslo_logrrVZoslo_messagingrüZ
oslo_utilsrr	r
rrr
r=Z	six.movesrZ
dmapi.confrÈrZ
dmapi.i18nrrrrrZ
try_importr	Zconfr#Z	getLoggerr/r\Z_IS_NEUTRONZsynchronized_with_prefixrdrrrr%r@r¶r!rîr(rÁr)r2r.rkr+rorr‚r‹rrr’r•ršrµÚcontextmanagerrÃrÊrÍrÓrÕrßrérêrìrírørùrrr
rrrrrrr"r$r&r*r+r-r:rrGr>rMrNrPrarbr&r&r&r'Ú<module>sÒ



l

]0
(5



	


		




a

50