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-el9 / usr / lib / python3.9 / site-packages / dmapi / __pycache__ / utils.cpython-39.pyc
Size: Mime:
a

[r`eWªã@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& 6d¡Z7e.j8j9Z9e  :e;¡Z<dZ=e >d¡Z?dZ@dZAdZBdZCiaDeEedƒrÊejFZGnejGZGdd„ZHGdd„deIƒZJGdd„deJƒZKd d!„ZLd"d#„ZMd$d%„ZNd„d'd(„ZOd…d)d*„ZPd+d,„ZQd-d.„ZRd/d0„ZSd1d2„ZTd3d4„ZUd5d6„ZVd7d8„ZWd†d9d:„ZXejYd;d<„ƒZZejYd‡d=d>„ƒZ[ejYd?d@„ƒZ\dˆdAdB„Z]GdCdD„dDeIƒZ^d‰dFdG„Z_dŠdHdI„Z`dJdK„ZadLdM„ZbdNdO„ZcdPdQ„ZdGdRdS„dSeIƒZed‹dTdU„ZfdŒdVdW„ZgdXdY„ZhdZd[„Zid\d]„Zjd^d_„Zkd`da„Zlddbdc„Zmddde„ZndŽdfdg„Zodhdi„Zpdjdk„Zqdldm„Zrdndo„Zsdpdq„Ztddrds„Zudtdu„Zvddvdw„Zwdxdy„Zxd‘dzd{„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)ZmappingsZblock_device_mappingZimg_mappingsZimg_block_device_mapping)Zimage_idZ
image_nameÚsizeZchecksumrrrrÚgetfullargspeccCstjjrd}n
dtj}|S)NÚsudozsudo dmapi-rootwrap %s)ÚCONFZworkaroundsZdisable_rootwrapÚrootwrap_config)Úcmd©rú//usr/lib/python3.9/site-packages/dmapi/utils.pyÚget_root_helperUs
r!c@seZdZdd„Zdd„ZdS)ÚRootwrapProcessHelpercOstƒ|d<tj|i|¤ŽS©NZroot_helper)r!rÚtrycmd©ÚselfrÚkwargsrrr r$^s
zRootwrapProcessHelper.trycmdcOstƒ|d<tj|i|¤ŽSr#)r!rÚexecuter%rrr r(bs
zRootwrapProcessHelper.executeN)Ú__name__Ú
__module__Ú__qualname__r$r(rrrr r"]sr"c@s8eZdZiZedƒdd„ƒZdd„Zdd„Zdd	„Zd
S)ÚRootwrapDaemonHelperzdaemon-client-lockcCsNz|j|WStyHddlm}| dd|g¡}||j|<|YS0dS)Nr)Úclientrzdmapi-rootwrap-daemon)Ú_clientsÚKeyErrorZ
oslo_rootwrapr-ZClient)Úclsrr-Z
new_clientrrr Ú_get_clientjsÿ
z RootwrapDaemonHelper._get_clientcCs| |¡|_dS©N)r1r-)r&rrrr Ú__init__uszRootwrapDaemonHelper.__init__c
Os|| dd¡}z|j|i|¤Ž\}}d}Wn:tjyb}z dt |¡}}d}WYd}~n
d}~00|st|rt|rtd}||fS)NÚdiscard_warningsFÚT)Úpopr(rÚProcessExecutionErrorÚsixÚ	text_type)r&Úargsr'r4ÚoutÚerrZfailedZexnrrr r$xszRootwrapDaemonHelper.trycmdc
Osdd„|Dƒ}| dtj¡}| dd¡}| dd¡}| dd¡}| dd	¡}| d
dg¡}d}	t|tƒrv|}	dg}nt|tƒr†|g}t d
 |¡¡}
t	 
tdƒ|
|dœ¡|dkr|d	8}zt ¡}t	 
|tdƒ|
¡|j ||¡\}}
}t ¡|}t	 
|d|
||dœ¡|	sF||vrFt |
¡}
t |¡}tj||
||
d‚|
|fWStjy}z¤|tjks€|tjkr¬|s¬tdƒ}t	 
|||j|j|j|j|jdœ¡|sÈt	 
|tdƒ|
¡‚n2t	 
|tdƒ|
¡|rút t ¡ dd¡d¡WYd}~q¬d}~00q¬dS)NcSsg|]}t|ƒ‘qSr)Ústr)Ú.0Úcrrr Ú
<listcomp>Šóz0RootwrapDaemonHelper.execute.<locals>.<listcomp>ÚloglevelÚ
log_errorsÚ
process_inputÚdelay_on_retryTÚattemptséÚcheck_exit_coderFú zHExecuting RootwrapDaemonHelper.execute cmd=[%(cmd)r] kwargs=[%(kwargs)r]©rr'zRunning cmd (subprocess): %szECMD "%(sanitized_cmd)s" returned: %(return_code)s in %(end_time)0.3fs)Ú
sanitized_cmdZreturn_codeÚend_time)Ú	exit_codeÚstdoutÚstderrrzS%(desc)r
command: %(cmd)r
exit code: %(code)r
stdout: %(stdout)r
stderr: %(stderr)r)ZdescrÚcoderNrOz%r failed. Not Retrying.z%r failed. Retrying.ééÈgY@)r6ÚloggingÚDEBUGÚ
isinstanceÚboolÚintrZ
mask_passwordÚjoinÚLOGÚinforÚtimerrr-r(rr7ZLOG_ALL_ERRORSZLOG_FINAL_ERRORÚdescriptionrrMrNrOÚsleepÚrandomÚSystemRandomZrandint)r&rr'rBrCrDrErFrHZignore_exit_coderKZ
start_timeÚ
returncoder;r<rLÚformatrrr r(…sŒ


þ
ÿÿ
þý

ü
ÿþüÿÿÿzRootwrapDaemonHelper.executeN)	r)r*r+r.Úsynchronizedr1r3r$r(rrrr r,gs


r,cOsPd|vr@| d¡r@tjr.ttjƒj|i|¤ŽStƒj|i|¤ŽStj|i|¤ŽS)z3Convenience wrapper around oslo's execute() method.Úrun_as_root)ÚgetrÚuse_rootwrap_daemonr,rr(r"rrJrrr r(Ós
ÿÿr(cOs*gd¢}| |¡| |¡t|i|¤ŽS)z+Convenience wrapper to execute ssh command.)Zsshz-oz
BatchMode=yes)ÚappendÚextendr()Údestrr'Zssh_cmdrrr Ússh_executeÞs

ricOsJ| dd¡r:tjr(ttjƒj|i|¤ŽStƒj|i|¤ŽStj|i|¤ŽS)z2Convenience wrapper around oslo's trycmd() method.rcF)rdrrer,rr$r"r©r:r'rrr r$æs
ÿÿr$écs,d‰‡fdd„t|ƒDƒ}d|d |¡fS)NZ%01234567890abcdefghijklmnopqrstuvwxyzcsg|]}t ¡ ˆ¡‘qSr)r^r_Úchoice)r>Z_x©Z
charactersrr r@órAz generate_uid.<locals>.<listcomp>z%s-%sr5)rrX)ZtopicrÚchoicesrrmr Úgenerate_uidñsrocCs&|s
tj}d}d|vr.| dd¡\}}t|ƒ}|dur<|}nt ¡}|dvrXttdƒƒ‚|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|d
krŒ|dkr*d}tjd||j
d}||krttjd||j
dd}tjd||j
dd}ntjd||j
dd}n’|dk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ú@rGN)ÚmonthÚdayÚyearÚhourz,Time period must be hour, day, month or yearrq)rrrqrsérsérr)rtrrrqrs)Zdaysrt)ZminuteÚsecondZmicrosecond)Zhours)rZinstance_usage_audit_periodÚsplitrWrÚutcnowÚ
ValueErrorrÚdatetimerqrsrrZ	timedeltaÚreplace)ZunitÚbeforeÚoffsetZrightnowÚendrsrqZbeginrrr Úlast_completed_audit_period÷s„
þ

þ




þþþ
ý


r€cCs8|dust|tjƒr|St|tjƒs.t |¡}| d¡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

    Núutf-8)rUr8Zbinary_typer9Úencode)Úvaluerrr Úutf8Ts

r„c	Cs¤ztt |¡r|dfWS| d¡dkrF| ddd¡ d¡\}}||fWS| d¡dkr^|dfWS| d¡\}}||fWSttjfyžt t	dƒ|¡YdS0d	S)
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.
    r5z]:éÿÿÿÿú[rGú:zInvalid server_string: %s)r5r5N)
ÚnetaddrZ
valid_ipv6Úfindr|rxrzÚAddrFormatErrorrYÚerrorr)Z
server_strÚaddressÚportrrr Úparse_server_stringds




rŽcCstj|dd}t| ¡ƒS©Né)Úversion)rˆÚ	IPAddressr=Zipv6)rŒZaddrrrr Úget_shortened_ipv6sr“cCstj|dd}t|jƒSr)rˆZ	IPNetworkr=Zcidr)rŒZnetrrr Úget_shortened_ipv6_cidr†sr”c	Cs<zt |¡jdkrd|WSWnttjfy6Yn0|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Š)Ziprrr Úsafe_ip_format‹sr–cCs|dur|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Úpathrrr Úformat_remote_pathšsr™cCstjs
dSt d¡tjr"tj}ndd„}tjD]Ò}| 	d¡\}}t
 |¡}t|ƒt
 |¡}t| ¡ƒD]–\}}t|t
jƒrÂt
 d||f¡}t ||¡D]$\}	}
t||	|d|||	f|
ƒƒqœt|t
jƒrjt
 d||f¡}
ttj|||d||f|
ƒƒqjq0dS)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.cSst |¡pt |¡Sr2)ÚinspectÚismethodZ
isfunction)Úobjrrr Ú	is_methodÀszmonkey_patch.<locals>.is_methodr‡z%s.%sz%s.%s.%s)rÚmonkey_patchrYÚwarningr8ÚPY2ršr›Zmonkey_patch_modulesrxr
Zimport_classÚ
__import__ÚpyclbrZ
readmodule_exÚlistÚitemsrUZClassZ
getmembersÚsetattrZFunctionÚsysÚmodules)rZmodule_and_decoratorÚmoduleZdecorator_nameÚ	decoratorZmodule_dataÚkeyrƒZclzÚmethodÚfuncrrr rž©s.



ÿÿržcCs‚dd„}t|tjƒr0| dd¡}tjr0| d¡}||ƒ}t dd|¡}t dd|¡}| ¡}| 	d	¡}|dkr~|d
ur~||ƒ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*t tdƒ||dd…dœ¡|dd…S)Né?zJHostname %(hostname)s is longer than 63, truncate it to %(truncated_name)s)ÚhostnameZtruncated_name)ÚlenrYrŸr)Únamerrr Útruncate_hostnameès

þz,sanitize_hostname.<locals>.truncate_hostnamezlatin-1Úignorez[ _]ú-z[^\w.-]+r5z.-N)
rUr8r9r‚ÚPY3ÚdecodeÚreÚsubÚlowerÚstrip)r®Zdefault_namer±rrr Úsanitize_hostnameÙs

rºc
+sædd„‰‡fdd„}‡fdd„}‡fdd„}tƒ}i}t| ¡ƒD]$\}}||||ƒ||<||||ƒqBz@d	VWt| ¡ƒD](\}}	|	|urš|||ƒq~||||	ƒq~n8t| ¡ƒD](\}}	|	|urÒ|||ƒq¶||||	ƒq¶0d	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)ÚhasattrrUÚdict)Úthingrrr Úis_dict_likesz(temporary_mutation.<locals>.is_dict_likecs$ˆ|ƒr| ||¡St|||ƒSdSr2)rdÚgetattr)r½ÚattrÚdefault©r¾rr rdsztemporary_mutation.<locals>.getcs"ˆ|ƒr|||<nt|||ƒdSr2)r¥)r½rÀÚvalrÂrr Ú	set_values
z%temporary_mutation.<locals>.set_valuecsˆ|ƒr||=n
t||ƒdSr2)Údelattr)r½rÀrÂrr Údeletesz"temporary_mutation.<locals>.deleteN)Úobjectr£r¤)
rœr'rdrÄrÆZNOT_PRESENTZ
old_valuesrÀÚ	new_valueÚ	old_valuerrÂr Útemporary_mutations&ürÊc
cs||durt ¡}t |¡j}||kr6tjjj||dz$dVW||krxtjjj||dn||krvtjjj||d0dS)zgTemporarily chown a path.

    :param owner_uid: UID of temporary owner (defaults to current user)
    N)Úuid)ÚosÚgetuidÚstatÚst_uidÚdmapiZprivsepr˜Úchown)r˜Z	owner_uidZorig_uidrrr Útemporary_chown6sÿrÒcksÄ| ¡}d|vrtj|d<tjfi|¤Ž}zN|VWzt |¡WqÀtyv}zt 	t
dƒ|¡WYd}~qÀd}~00nFzt |¡Wn4ty¼}zt 	t
dƒ|¡WYd}~n
d}~000dS)NÚdirzCould not remove tmpdir: %s)ÚcopyrÚtempdirÚtempfileZmkdtempÚshutilÚrmtreeÚOSErrorrYr‹r)r'ZargdictZtmpdirÚerrr rÕJs
(ýrÕccsH|sg}| ¡D]2}||vr| |¡t||ƒD]
}|Vq0|VqdS)z:Walk class hierarchy, yielding most derived classes first.N)Ú__subclasses__rfÚwalk_class_hierarchy)ZclazzZencounteredÚsubclassZsubsubclassrrr 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|_dSr2)Ú
undo_stack)r&rrr r3jszUndoManager.__init__cCs|j |¡dSr2)rßrf©r&Z	undo_funcrrr Ú	undo_withmszUndoManager.undo_withcCst|jƒD]
}|ƒq
dSr2)Úreversedrßràrrr Ú	_rollbackpszUndoManager._rollbackNcKsJt ¡.|r tj|fi|¤Ž| ¡Wdƒn1s<0YdS)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_exceptionrYrrã)r&Úmsgr'rrr Úrollback_and_reraisets
z UndoManager.rollback_and_reraise)N)r)r*r+Ú__doc__r3rárãrærrrr rÞfs
rÞFcCsn|dkrdg}n
dd|g}|dvr.| dg¡|rR|dvr@d}nd	}| ||g¡| |¡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)Zext3Zext4Zntfsz-F)ZmsdosZvfatz-nz-LrcN)rgrfr()Zfsr˜Zlabelrcr:Z	label_optrrr rès

rècCs2i}|D]$}|s| d¡rq|d||d<q|S)NZdeletedrƒrª©rd)ÚmetadataÚinclude_deletedÚresultÚitemrrr Úmetadata_to_dictšsrîcCs0g}t| ¡ƒD]\}}| t||d¡q|S)N)rªrƒ)r£r¤rfr¼)rêrìrªrƒrrr Údict_to_metadata£srïcCs&t|dtƒr|dSt|dƒSdS)Nrê)rUr¼rî©Úinstancerrr Ú
instance_metaªsròcCs8| d¡siSt|dtƒr$|dSt|dddSdS)NZsystem_metadataT©rë)rdrUr¼rîrðrrr Úinstance_sys_meta±s
ÿrôcs‡fdd„}|S)Ncst ˆ¡‡‡fdd„ƒ}|S)NcsVt |¡}t |¡\}}}}|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_fÚ	arg_namesÚaÚkwZ_default)r:Údecrr Ú
_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:rrrÿr Úexpects_func_args»src@s eZdZdZdd„Zdd„ZdS)ÚExceptionHelperzrClass to wrap another and translate the ClientExceptions raised by its
    function calls to the actual ones.
    cCs
||_dSr2)Ú_target)r&Útargetrrr r3ÕszExceptionHelper.__init__cs&t|j|ƒ‰t ˆ¡‡fdd„ƒ}|S)Nc
sHzˆ|i|¤ŽWStjyB}ztj|jŽWYd}~n
d}~00dSr2)Ú	messagingZExpectedExceptionr8ZreraiseÚexc_info)r:r'rÚ©r¬rr ÚwrapperÛsz,ExceptionHelper.__getattr__.<locals>.wrapper)r¿rrýrþ)r&r°rrrr Ú__getattr__ØszExceptionHelper.__getattr__N)r)r*r+rçr3r	rrrr rÐsrcCsžt|tjƒs6|durtdƒ}ntdƒ|}tj|d‚|durB|}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)rUr8Ústring_typesrrÚInvalidInputr¯)rƒr°rrrårrr Úcheck_string_lengthäs"
ÿÿrc
CsNzt ||||¡WStyH}ztjt |¡d‚WYd}~n
d}~00dS)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_integerrzrrr8r9)rƒr°Z	min_valueZ	max_valuerÚrrr rs
rcCs2tsdSt ¡}d}|r.|j| ¡| ¡dœ}|S)N)Úhmac_keyZbase_idZ	parent_id)ÚprofilerrdrZget_base_idZget_id)ZprofZ
trace_inforrr Ú_serialize_profile_infosýrcs@t ¡‰tƒ‰t ˆ¡‡‡‡fdd„ƒ}tj|g|¢Ri|¤Ž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.
    cs6ˆdurˆ ¡ˆr(tr(tjfiˆ¤Žˆ|i|¤ŽSr2©Zupdate_storerÚinitrj©Z_contextr¬Z
profiler_inforr Úcontext_wrapper-s
zspawn.<locals>.context_wrapper)Úcommon_contextÚget_currentrrýrþÚeventletÚspawn©r¬r:r'rrrr r s

	rcsDt ¡‰tƒ‰t ˆ¡‡‡‡fdd„ƒ}tj|g|¢Ri|¤Ž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.
    cs:ˆdurˆ ¡ˆr(tr(tjfiˆ¤Žˆ|i|¤ŽdSr2rrjrrr rGs
z spawn_n.<locals>.context_wrapperN)rrrrýrþrÚspawn_nrrrr r:s

	rcCst|tjƒsdS| ¡dkS)z/Check if a string represents a None value.
    FZnone)rUr8r
r¸)rÃrrr Úis_none_stringTsrcCs(d}|dur$| ¡ ¡}|dkr$d}|S)NFZdisabledT)r¹r¸)Zauto_disk_config_rawZauto_disk_config_disabledZadc_loweredrrr Úis_auto_disk_config_disabled]sr cCs|durt|ƒ}| d¡S)NZimage_auto_disk_config)rôrd)rñZsys_metarrr Ú"get_auto_disk_config_from_instancefsr!cCs
| d¡S)NZauto_disk_configré)Zimage_propertiesrrr Ú%get_auto_disk_config_from_image_propslsr"cCs´i}td}t| di¡ ¡ƒD].\}}|tvr2q tt |¡dƒ}||||<q tD]Z}| |¡}|dkr˜|r˜| d¡dkr†|d}nt	|pŽd|dƒ}|dur¢qT||||<qT|S)	Nz%sÚ
propertieséÿrrZvhdZroot_gbr)
ÚSM_IMAGE_PROP_PREFIXr£rdr¤ÚSM_SKIP_KEYSÚ
safe_truncater8r9ÚSM_INHERITABLE_KEYSÚmax)Ú
image_metaZflavorÚsystem_metaZ
prefix_formatrªrƒrÈrrr Úget_system_metadata_from_imageps"

r,cCsˆi}i}t|tƒst|dd}t| ¡ƒD]P\}}|dur<q*| t¡rV|ttƒd…}|tvr`q*|t	vrr|||<q*|||<q*||d<|S)NTrór#)
rUr¼rîr£r¤Ú
startswithr%r¯r&r()r+r*r#rªrƒrrr Úget_image_from_system_metadataŒs 



r.cCsjt | di¡¡}d|i}| dd¡tj|d<tD](}| |d¡}|dvr4t|pTdƒ||<q4d|d<|S)NZvolume_image_metadatar#rr)rrZactiveÚstatus)rÔrdr
ZGiÚVIM_IMAGE_ATTRIBUTESr6rW)Zvolumer#r*rÀrÃrrr Úget_image_metadata_from_volume©sr1cCs$t|tjƒr| d¡}t |¡ ¡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.
    r)rUr8r9r‚ÚhashlibZmd5Ú	hexdigest©Zbase_strrrr Úget_hash_strÂs
r5cCs$t|tjƒr| d¡}t |¡ ¡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.
    r)rUr8r9r‚r2Zsha256r3r4rrr Úget_sha256_strÌs
r6cCst|ƒ}tjst |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.
    r)Úreprr8r´r9)rœZobj_reprrrr Úget_obj_repr_unicodeÙsr8cs®t|tƒr|g}‡fdd„‰dd„‰‡‡fdd„}g}|D]n}ˆdkr^|durRd	}| |i¡}|D]}||||ƒ}qbt| ¡ƒD]&\}	}
| d
|	d|
dˆˆ|ƒi¡q€q:|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| d¡SdS)NrñZuuidré)Úresource)Ú
resource_typerr Ú_get_idsz4filter_and_format_resource_metadata.<locals>._get_idcs&t|tƒr|g}t‡fdd„|DƒƒS)Ncsg|]}t |ˆ¡‘qSr)r¶Úmatch)r>Úpattern©Ústringrr r@sÿzKfilter_and_format_resource_metadata.<locals>._match_any.<locals>.<listcomp>)rUr=Úany)Zpattern_listr?rr>r Ú
_match_anys

ÿz7filter_and_format_resource_metadata.<locals>._match_anyc	sœ| dg¡}| dg¡}| dg¡}i}|r<ˆ|ƒ|vr<iSt| ¡ƒD]N\}}|rp|rpˆ||ƒspˆ||ƒspqHn|r~ˆ||ƒrH|rŽˆ||ƒsŽqH|||<qH|S)NZresource_idrªrƒ)rdr£r¤)	r9Zsearch_filtZinput_metadataZidsZkeys_filterZ
values_filterZoutput_metadataÚkÚv)r;rArr Ú_filter_metadatas*ÿþÿÿ
z=filter_and_format_resource_metadata.<locals>._filter_metadatarñNrêrªrƒz%s_id)rUr¼rdr£r¤rf)r:Z
resource_listZsearch_filtsZ
metadata_typerDZformatted_metadata_listÚresrêZfiltrBrCr)r;rAr:r Ú#filter_and_format_resource_metadataås$'
ÿ
rFcCsRt |¡d|…}d}|sNzt |¡}d}WqtyJ|dd…}Yq0q|S)zpSafely truncates unicode strings such that their encoded length is
    no greater than the length provided.
    NFTr…)rZsafe_encodeZsafe_decodeÚUnicodeDecodeError)rƒÚlengthZb_valueZ	decode_okZu_valuerrr r'Gs
r'cCs”|rt|ƒd}tj |¡}t |i¡}|r<|| dd¡krˆt d|¡t	|ƒ}| 
¡|d<Wdƒn1sr0Y||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Ú
setdefaultrdrYÚdebugÚopenÚread)ÚfilenameZforce_reloadZreloadedrIÚ
cache_infoZfaprrr Úread_cached_file[s	
*rTcCs|tvrt|=dS)zLDelete cached file if present.

    :param filename: filename to delete
    N)rM)rRrrr rKtsrKcCsD|st ¡}| d¡}|jr(|j d¡nd}||dvr: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)rUz	UTC+00:00ÚZ)rryÚstrftimeZtzinfoÚtzname)ÚatZdate_stringZtzrrr Úisotimes
rZcCs
| d¡S)Nz%Y-%m-%dT%H:%M:%S.%f)rW)rYrrr Ústrtimesr[c	Cs¦|jr|jS|jdkr6z| ¡jWSty4Yn0z
| ¡WStjyTYn0t|j	ƒ}|D].}||_	z| ¡WStjyYqd0qdt d|¡‚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
interfacesr_rrr r]‘s.



ÿÿr]cCs"ttdƒst d¡dStj |d¡}d}d}z–zXt |tjtjBtj	B¡}d}t
 
d|¡}| d|¡t ||¡t d	d
|i¡Wnäty}zj|j
t
jkrÀt d||dœ¡d}n:t ¡"t d
||dœ¡Wdƒn1sð0YWYd}~njd}~0tyn}zHt ¡"t d
||dœ¡Wdƒn1sP0YWYd}~n
d}~00W|dur†t |¡zt |¡Wn0tyÄ}zt |¡WYd}~n
d}~00nV|durÜt |¡zt |¡Wn0ty}zt |¡WYd}~n
d}~000|S)NÚO_DIRECTz/This python runtime does not support direct I/OFz.directio.testTir…ó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ÌrYrOr˜rXrPÚO_CREATÚO_WRONLYr`ÚmmapÚwriterÙÚerrnoÚEINVALr	rär‹Ú	ExceptionÚcloseÚunlinkr)ÚdirpathZtestfileZhasDirectIOÚfdZ
align_sizeÚmrÚrbrrr Úsupports_direct_ioÆsZ

ÿÿ
þ6
ÿ<


ù


rocCs&tjrt |¡dSt |¡dSdS)Nr)r8r ršrõrrrrr Úget_func_valid_keysösrp)rk)NN)N)N)N)NF)F)NrN)NN)NN)N)N)F)N)~rçÚ
contextlibrÔr{rgrýr2ršrerÌr¢r^r¶r×r¦rÖr[rZ
keystoneauth1rr^rZ
ks_loadingrˆZoslo_concurrencyrrZoslo_contextrrZoslo_logrrSZoslo_messagingrZ
oslo_utilsrr	r
rrr
r8Z	six.movesrZ
dmapi.confrÐrZ
dmapi.i18nrrrrrZ
try_importrZconfrZ	getLoggerr)rYZ_IS_NEUTRONZsynchronized_with_prefixrbr%r(r&r0rMr»rrõr!rÇr"r,r(rir$ror€r„rŽr“r”r–r™ržrºÚcontextmanagerrÊrÒrÕrÜrÞrèrîrïròrôrrrrrrrrr r!r"r,r.r1r5r6r8rFr'rTrKrZr[r]rorprrrr Ú<module>sÔ



l

]0
(
4




	


		




ÿ
b

50