%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/docker/translate/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyc

�
���^c@@s(dZddlmZmZmZddlZddlZddlZddl	m
Z
ddlmZddl
mZmZe�Zddd	�Zd
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed�Z dd�Z!d�Z"dS(u\
Functions to translate input in the docker CLI format to the format desired by
by the API.
i(tabsolute_importtprint_functiontunicode_literalsN(tSaltInvocationError(tsix(trangetzipu,i����cC@s)g|j||�D]}|j�^qS(N(tsplittstrip(titemtseptmaxsplittx((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyRsutcpcC@s�y|jd�\}}}Wntk
r/nX|r?|}ny&|j�dkrdt|�dfSWntk
rxnXt|�S(u`
    Given a port number and protocol, returns the port definition expected by
    docker-py. For TCP ports this is simply an integer, for UDP ports this is
    (port_num, 'udp').

    port_num can also be a string in the format 'port_num/udp'. If so, the
    "proto" argument will be ignored. The reason we need to be able to pass in
    the protocol separately is because this function is sometimes invoked on
    data derived from a port range (e.g. '2222-2223/udp'). In these cases the
    protocol has already been stripped off and the port range resolved into the
    start and end of the range, and get_port_def() is invoked once for each
    port number in that range. So, rather than munge udp ports back into
    strings before passing them to this function, the function will see if it
    has a string and use the protocol from it if present.

    This function does not catch the TypeError or ValueError which would be
    raised if the port number is non-numeric. This function either needs to be
    run on known good input, or should be run within a try/except that catches
    these two exceptions.
    u/uudp(t	partitiontAttributeErrortlowertint(tport_numtprotot_tport_num_proto((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pytget_port_defs
	
cC@s�t|tj�r||fSyvgt|d�D]}t|�^q/}t|�dkrj|d}}n|\}}||kr�td��nWn[ttfk
r�}|j�dkr�dj	||�}ndj	|�}t|��nX||fSdS(u�
    Given a port number or range, return a start and end to that range. Port
    ranges are defined as a string containing two numbers separated by a dash
    (e.g. '4505-4506').

    A ValueError will be raised if bad input is provided.
    u-iiustart > enduHStart of port range ({0}) cannot be greater than end of port range ({1})u-'{0}' is non-numeric or an invalid port rangeN(
t
isinstanceRt
integer_typesRRtlent
ValueErrort	TypeErrort__str__tformat(tport_defRtcompstrange_startt	range_endtexctmsg((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pytget_port_range>s"
(	c
O@s@|jdt�}t|�}t|�}xt|�D]\}}t|t�s7g|jd�D]}|j�^qb}t|�}	|	|kr�|tkr�t	dj
||	|���n|j|g||	�nE|	|krt	dj
||	|tkr|ndj
|����ntt||��||<q7q7W|S(u�
    Many arguments come in as a list of VAL1:VAL2 pairs, but map to a list
    of dicts in the format {NAME1: VAL1, NAME2: VAL2}. This function
    provides common code to handle these instances.
    ufillu:u*'{0}' contains {1} value(s) (expected {2})u	up to {0}(
tpoptNOTSETRttranslate_stringlistt	enumerateRtdictRRRRtextendR(
tvaltnamest
extra_optstfilltexpected_num_elementstidxR	Rtelementstnum_elements((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pytmap_vals`s,( cC@sIy1tjjj|�s0tdj|���nWntk
rDnXdS(Nu'{0}' is not a valid IP address(tsalttutilstnetworktis_ipRRtRuntimeError(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pytvalidate_ip�s
cC@sIy1tjjj|�s0tdj|���nWntk
rDnXdS(Nu'{0}' is not a valid subnet(R3R4R5t	is_subnetRRR7(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pytvalidate_subnet�s
cC@s#t|tj�stj|�S|S(N(RRtstring_typest	text_type(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyt
translate_str�scC@sXt|tj�sTyt|�}WqTttfk
rPtdj|���qTXn|S(Nu'{0}' is not an integer(RRRRRRRR(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyt
translate_int�scC@st|t�st|�S|S(N(Rtbool(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_bool�scC@s+t|t�s'tdj|���n|S(uN
    Not really translating, just raising an exception if it's not a dict
    u'{0}' is not a dictionary(RR(RR(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_dict�scC@s�t|tj�r|St|t�rux\tt|��D]6}t||tj�s8tj||�||<q8q8Wntj|�}|S(u�
    Input should either be a single string, or a list of strings. This is used
    for the two args that deal with commands ("command" and "entrypoint").
    (RRR;tlistRRR<(R*R/((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_command�s!cC@sRyt|�}Wn;ttfk
rMt|tj�sNtj|�}qNnX|S(uz
    These values can be expressed as an integer number of bytes, or a string
    expression (i.e. 100mb, 1gb, etc.).
    (RRRRRR;R<(R*((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_bytes�scC@s�t|t�sKyt|�}WqKtk
rGttj|��}qKXnxJtt|��D]6}t||tj�s^tj||�||<q^q^W|S(uj
    On the CLI, these are passed as multiple instances of a given CLI option.
    In Salt, we accept these as a comma-delimited list but the API expects a
    Python list. This function accepts input and returns it back as a Python
    list of strings. If the input is a string which is a comma-separated list
    of items, split that string and return it.
    (	RRBRRRR<RRR;(R*R/((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyR&�s
cC@st|dd�}xtt|��D]�}ytjj||d�}Wntk
rbt}nX|s�tdj	||���ny t
||d�||d<Wnttfk
r�nX|r%y t
||d�||d<Wqtk
rtdj	||���qXq%q%W|S(u�
    CLI input is a list of PATH:RATE pairs, but the API expects a list of
    dictionaries in the format [{'Path': path, 'Rate': rate}]
    uPathuRateuPath '{Path}' is not absoluteu.Rate '{Rate}' for path '{Path}' is non-numeric(
R2RRtostpathtisabsRtFalseRRRRR(R*tnumeric_rateR/tis_abs((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_device_rates�s*

  
u=cC@s�t|t�r|St|�}i}xi|D]a}yt||d�\}}Wn2tttfk
r�tdj||���nX|||<q,W|S(um
    CLI input is a list of key/val pairs, but the API expects a dictionary in
    the format {key: val}
    iu'{0}' is not a key{1}value pair(	RR(R&RRRRRR(R*t	delimitertnew_valR	tlvaluetrvalue((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_key_vals
cC@s.t|t�s*t|t�s-t|�}ni}x�|D]�}t|t�r�t|�dkrptd��ntt|��}||}n<yt|dd�\}}Wntk
r�|}d}nXt|t	j
�s�t	j|�}nt|t	j
�st	j|�}n|||<q:W|}n|S(u�
    Can either be a list of label names, or a list of name=value pairs. The API
    can accept either a list of label names or a dictionary mapping names to
    values, so the value we translate will be different depending on the input.
    iuInvalid label(s)u=u(RR(RBRRRtnexttiterRRR;R<(R*RMR	tkey((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyttranslate_labelss,



	(#t__doc__t
__future__RRRREtsalt.utils.dataR3tsalt.utils.networktsalt.exceptionsRtsalt.extRtsalt.ext.six.movesRRtobjectR%RRR#R2R8R:R=R>R@RARCRDR&tTrueRKRPRT(((sG/usr/lib/python2.7/site-packages/salt/utils/docker/translate/helpers.pyt<module>s0	$	"	"	
	
								
	#

Zerion Mini Shell 1.0