�
-�P`c@s�ddlZddlZddlZddlZddlZddlZyddlmZWn!ek
rddl mZnXddl
Z
y*ddlmZm
Z
ddlmZWn7ek
r�ddlmZm
Z
ddlmZnXddlZddlZddlZddlZddlZedd�Zd�Zdefd��YZd ZeZid
d6dRd6dSd6dTd6dUd6dVd6dWd6dXd6dYd6dZd6d[d6d\d6d]d6d^d 6d_d"6d`d#6dad$6dbd&6dcd(6ddd)6ded*6dfd,6dgd.6dhd/6did06Zd,d&d dddgZe d1�Z!d2�Z"d3�Z#ddd4�Z$d5�Z%d6�Z&d7�Z'd8�Z(d9�Z)d:�Z*d;�Z+d<e,fd=��YZ-ed>d?d@�edAd?dB�edCd?dD�dEe,fdF��Y���Z.dddG�Z/dH�Z0dIefdJ��YZ1dKefdL��YZ2dM�Z3dN�Z4dOej5fdP��YZ6e7dQkr�ej8�ndS(ji����N(tSequence(tURLErrort HTTPError(turlparsecs_d���fd�}�fd�}t||r:|ndd|����fd�}|S(s�
Creates the get/set properties for the given name. It assumes that the
actual attribute is '_' + name
TODO: Expand this with domain validation to ensure the values are correct.
t_cs
t|��S(N(tgetattr(tself(tattribute_name(s//usr/lib/python2.7/site-packages/lsm/_common.pytgetter9scst|�|�dS(N(tsetattr(Rtvalue(R(s//usr/lib/python2.7/site-packages/lsm/_common.pytsetter<scst|���|S(N(R (tcls(tnametprop(s//usr/lib/python2.7/site-packages/lsm/_common.pyt decoratorAsN(tpropertytNone(R
t allow_settdocRRR((RR
Rs//usr/lib/python2.7/site-packages/lsm/_common.pytdefault_property0s
!cCs�t|t�r*ttjt|���nt|t�r�t|�}d|kr�d|krrttjd��nd|kr�ttjd��q�nt dt
j��ttj|��nyAt
jr�t|t
j�r�ttjdt|���q�nWntk
rnXtjrGt|t�rGttjt|���nt|tj �rtttjt|���nt
j�}t d|�ttjd tt|��|��dS(
Ns
urlopen errors Errno 111sConnection refuseds Errno 113sHost is downsUnexpected network error:
sSSL Certificate error (%s)sUnexpected exception:
sUnexpected exception (TYPE= %s)(t
isinstanceRtLsmErrortErrorNumbertPLUGIN_AUTH_FAILEDtstrRtNETWORK_CONNREFUSEDtNETWORK_HOSTDOWNterrort tracebackt
format_exct
NETWORK_ERRORtssltCertificateErrortAttributeErrortsixtPY3tConnectionErrortsockett
PLUGIN_BUGttype(texptdesctstack_trace((s//usr/lib/python2.7/site-packages/lsm/_common.pytcommon_urllib2_error_handlerHs:
tProxycBs,eZdZdd�Zd�Zd�ZRS(sQ
Used to provide an unambiguous error when a feature is not implemented.
cCs
||_dS(s<
Constructor which takes an object to wrap.
N(tproxied_obj(Rtobj((s//usr/lib/python2.7/site-packages/lsm/_common.pyt__init__{scCs;t|j|�r%tj|j|�Sttjd��dS(sJ
Called each time an attribute is requested of the object
sUnsupported operationN(thasattrR.t functoolstpartialt_presentRRt
NO_SUPPORT(RR
((s//usr/lib/python2.7/site-packages/lsm/_common.pyt__getattr__�s cOst|j|�||�S(sQ
Method which is called to invoke the actual method of interest.
(RR.(Rt_proxy_method_nametargstkwargs((s//usr/lib/python2.7/site-packages/lsm/_common.pyR4�sN(t__name__t
__module__t__doc__RR0R6R4(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR-ss
s/var/run/lsm/ipcitBii
tKiBitKBtKtkitMiBitMBtMtmitGiBi tGBtGtgi(tTiBitTBtTtti2tPiBitPBtPtpi<tEiBitEBtEtecCspd}|rhx<tD]4}|t|kr|tt|�:}|}PqqW|sZd}nd||fS|SdS(s
Convert size in bytes to human readable size
The return string will follow IEC binary prefixes, e.g. '1.9 KiB'
For size less than 1024, we do nothing but return the int we get.
TODO: Need a expect to handle when size is not a int. int() might do.
R=s%.2f %sN(RtSIZE_CONS_CHK_LSTt SIZE_CONStfloat(tsizethumantunitstkey_name((s//usr/lib/python2.7/site-packages/lsm/_common.pytsh�s
cCs
t|t�S(s
Convert integer size in bytes to human readable size.
We are following rules of IEC binary prefixes on size:
http://en.wikipedia.org/wiki/Gibibyte
The biggest of unit this function supported is PiB.
The precision is 2 which means you will get '1.99 KiB'
(R]tTrue(RY((s//usr/lib/python2.7/site-packages/lsm/_common.pytsize_bytes_2_size_human�scCs�tjdtj�}|j|�}d}|r�|jd�}|jd�}|s^t|�S|j�}|jdd�}|tkr�t|t |�}q�nt|�S(s�
Convert human readable size string into integer size in bytes.
Following rules of IEC binary prefixes on size:
http://en.wikipedia.org/wiki/Gibibyte
Supported input size_human in these formats:
'1.9KiB' # int(1024*1.9)
'1 KiB' # 2**10
'1B' # 1
'2K' # 2*(2**10), treated as '2KiB'
'2k' # 2*(2**10), treated as '2KiB'
'2KB' # 2*(10**3)
s�
^
([0-9\.]+) # 1: number
[ \t]* # might have space between number and unit
([a-zA-Z]*) # 2: units
$
iiitIBtiB(
tretcompiletXtmatchtgrouptinttuppertreplaceRWRX(t
size_humantregex_size_humantregex_matcht
size_bytestnumberR[((s//usr/lib/python2.7/site-packages/lsm/_common.pytsize_human_2_size_bytes�s
cCsiy3i}t|�}|jr.|j|d<n|jrG|j|d<n|jr`|j|d<n|jry|j|d<n|jr�|j|d<n
d
|d<t|�|d<|r�x6|D]+}||kr�tt j
d|��q�q�Wn|r.x:|D]/}||dkr�tt j
d|��q�q�Wn|SWn/tk
rd}tt j
d t|���nXd
S(sq
Common uri parse method that optionally can check for what is needed
before returning successfully.
tschemetnetloctportthosttusernamet
parameterss&uri missing "%s" or is in invalid formsuri missing query parameter %ssuri invalid: reason: %sN(
RRpRqRrthostnameRtRturi_parametersRRtINVALID_ARGUMENTt
ValueErrorR(turitrequirestrequired_paramstrctutrtve((s//usr/lib/python2.7/site-packages/lsm/_common.pyt uri_parses:
cCsy|jr|j}n'|jr8td|d�j}niS|rqtg|jd�D]}|jd�^qU�SiSdS(Nshttp:it&t=(tquerytpathRtdicttsplit(RzR�tpart((s//usr/lib/python2.7/site-packages/lsm/_common.pyRwDs /cCs,tj�}|j|jd��|j�S(Nsutf-8(thashlibtmd5tupdatetencodet hexdigest(RMth((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�[scCstjr||S||SdS(N(R#R$(tatb((s//usr/lib/python2.7/site-packages/lsm/_common.pytint_divas cGs&djg|D]}t|�^q
�S(Nt(tjoinR(R8RU((s//usr/lib/python2.7/site-packages/lsm/_common.pytparams_to_stringmscCsEx>|jd�D]-}t|�rtj||d|�qqWdS(s�
If a message includes new lines we will create multiple syslog
entries so that the message is readable. Otherwise it isn't very readable.
Hopefully we won't be logging much :-)
s
s: N(R�tlentsyslog(tleveltprgtmsgtl((s//usr/lib/python2.7/site-packages/lsm/_common.pytpost_msgzscGs0ttjtjjtjd�t|��dS(Ni( R�R�tLOG_ERRtosR�tbasenametsystargvR�(R�((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�scGs9tr5ttjtjjtjd�t |��ndS(Ni(
tLOG_VERBOSER�R�tLOG_INFOR�R�R�R�R�R�(R�((s//usr/lib/python2.7/site-packages/lsm/_common.pytinfo�st SocketEOFcBseZdZRS(sL
Exception class to indicate when we read zero bytes from a socket.
(R:R;R<(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR��stcodeRs
Error codeR�s
Error messagetdatasOptional error dataRcBseZdd�Zd�ZRS(cOs2tj|||�||_||_||_dS(s,
Class represents an error.
N(t ExceptionR0t_codet_msgt_data(RR�tmessageR�R8R9((s//usr/lib/python2.7/site-packages/lsm/_common.pyR0�s cCsVtj|j�}|jdk rA|jrAd||j|jfSd||jfSdS(Ns%s: %s Data: %ss%s: %s (Rterror_number_to_strR�R�RR�(Rterror_no_str((s//usr/lib/python2.7/site-packages/lsm/_common.pyt__str__�s
N(R:R;RR0R�(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�s cCs'i|d6|d6|d6|d6|d6S(sC
Used for gathering additional information about an error.
tdomainR�t exceptiontdebugt
debug_data((R�R�R�R�R�((s//usr/lib/python2.7/site-packages/lsm/_common.pytaddl_error_data�scCs�|jd�}dj|d �}t|�rat|�}x?|dD]}t||�}qEWntd�}t||�}|S(sn
Given a class name it returns the class, caller will then
need to run the constructor to create.
t.i����it__main__(R�R�R�t
__import__R(t
class_nametpartstmoduleREtcomp((s//usr/lib/python2.7/site-packages/lsm/_common.pyt get_class�sRcBs"eZdZdZdZdZdZdZdZdZ dZ
d Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d)Z+d*Z,e-�Z.e/d+��Z0RS(,iiiiiii
i2i4iei}i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i,i-i3i7i^i�i�i�i�i�i�iicCsIx>ttjj��D]'}tj||krd||fSqWd|S(Ns%s(%d)sUNKNOWN_ERROR_NUMBER(%d)(tlistRt_LOCALStkeys(terror_not error_str((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�s(1R:R;tOKtLIB_BUGR'tJOB_STARTEDtTIMEOUTtDAEMON_NOT_RUNNINGtPERMISSION_DENIEDt
NAME_CONFLICTtEXISTS_INITIATORRxtNO_STATE_CHANGERRRt NO_MEMORYR5t IS_MASKEDtHAS_CHILD_DEPENDENCYtNOT_FOUND_ACCESS_GROUPtNOT_FOUND_FSt
NOT_FOUND_JOBtNOT_FOUND_POOLtNOT_FOUND_FS_SStNOT_FOUND_VOLUMEtNOT_FOUND_NFS_EXPORTtNOT_FOUND_SYSTEMtNOT_FOUND_DISKtNOT_LICENSEDtNO_SUPPORT_ONLINE_CHANGEtNO_SUPPORT_OFFLINE_CHANGERtPLUGIN_IPC_FAILtPLUGIN_SOCKET_PERMISSIONtPLUGIN_NOT_EXISTtNOT_ENOUGH_SPACEtTRANSPORT_COMMUNICATIONtTRANSPORT_SERIALIZATIONtTRANSPORT_INVALID_ARGtLAST_INIT_IN_ACCESS_GROUPtUNSUPPORTED_SEARCH_KEYtEMPTY_ACCESS_GROUPtPOOL_NOT_READYt
DISK_NOT_FREEtlocalsR�tstaticmethodR�(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�sZ t JobStatuscBseZdZdZdZRS(iii(R:R;t
INPROGRESStCOMPLETEtERROR(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�sc
CsQt|t�r�t|t�sCtd|tt|��f��nt|�dkr}xU|D]}t||d|�q\WqMx�t||�D]\}}t|||�q�Wn�|t|�krM|dk rMt|t j
�r�t|t j
�r�dStj|�st
t|�|�rMtd|t|�tt|��f��qMndS(Ns6%s call is returning a %s, but is expecting a sequenceiis%s call expected: %s got: %s (RRt TypeErrorRR(R�ttype_comparetzipRR#tstring_typestinspecttisclasst
issubclass(tmethod_nametexp_typetact_valtavR)tact((s//usr/lib/python2.7/site-packages/lsm/_common.pyR� s$
cs�fd�}|S(s4
Decorator function that allows us to ensure that we are getting the
correct types back from a function/method call.
Note: This is normally frowned upon by the python community, but this API
needs to be language agnostic, so making sure we have the correct types
is quite important.
cs%tj����fd��}|S(Ncs��||�}t��dkrzt|�t��krdtd�jt��t|�f��nt�j�|�n,t��dkr�t�j�d|�n|S(Nis.%s call expected %d return values, actual = %di(R�R�R:R�(R8R9R(tfuncttypes(s//usr/lib/python2.7/site-packages/lsm/_common.pytinnerHs%(R2twraps(R�R�(R�(R�s//usr/lib/python2.7/site-packages/lsm/_common.pytouterGs!((R�R�((R�s//usr/lib/python2.7/site-packages/lsm/_common.pytreturn_requires>s t
TestCommoncBs#eZd�Zd�Zd�ZRS(cCsdS(N((R((s//usr/lib/python2.7/site-packages/lsm/_common.pytsetUp`sc Csy
t��Wn)tk
r8}|jt|t��nXytddd��WnGtk
r�}|j|jdko�|jdko�|jdk�nXtddddd�}|j|ddko|ddko|ddko|ddko|ddk�dS( Ni
tMessagetDataR�R�R�R�R�(R�t
assertTrueRRR�R�R�R�(RRUted((s//usr/lib/python2.7/site-packages/lsm/_common.pyttest_simplecs
$ &cCsdS(N((R((s//usr/lib/python2.7/site-packages/lsm/_common.pyttearDownws(R:R;R�RR(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR�_s R�ii�iiii@Biii@iʚ;i@i@II���IIII�Ƥ~�IIIId����
II(9R�R�tunittestRbR�R�tcollections.abcRtImportErrortcollectionsR�turllib.errorRRturllib.parseRturllib2R2RR#R R&R^RRR,tobjectR-tUDS_PATHR�RWRVtFalseR]R_RoR�RwR�R�R�R�RR�R�R�RR�R�RR�R�R�tTestCaseR�R:tmain(((s//usr/lib/python2.7/site-packages/lsm/_common.pyt<module>s�
+)
(1
Q ! |