-P`c@sddlZddlZddlZddlZddlZddlZyddlmZWn!ek rddl mZnXddl Z y*ddl m Z m Z ddlmZWn7ek rddlm Z m Z ddlmZnXddlZddlZddlZddlZddlZeddZdZdefdYZd ZeZid d 6dRd6dSd6dTd6dUd6dVd6dWd6dXd6dYd6dZd6d[d6d\d6d]d6d^d 6d_d"6d`d#6dad$6dbd&6dcd(6ddd)6ded*6dfd,6dgd.6dhd/6did06Zd,d&d dddgZe d1Z!d2Z"d3Z#ddd4Z$d5Z%d6Z&d7Z'd8Z(d9Z)d:Z*d;Z+d<e,fd=YZ-ed>d?d@edAd?dBedCd?dDdEe,fdFYZ.dddGZ/dHZ0dIefdJYZ1dKefdLYZ2dMZ3dNZ4dOej5fdPYZ6e7dQkrej8ndS(jiN(tSequence(tURLErrort HTTPError(turlparsecs_dfd}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_settdocRR R((RR Rs//usr/lib/python2.7/site-packages/lsm/_common.pytdefault_property0s  !cCst|tr*ttjt|nt|trt|}d|krd|krrttjdnd|krttjdqnt dt j ttj |nyAt jrt|t jrttj dt|qnWntk rnXtjrGt|trGttjt|nt|tj rtttjt|nt j }t d|ttjd tt||dS( Ns urlopen errors Errno 111sConnection refuseds Errno 113s Host is downsUnexpected network error: sSSL Certificate error (%s)sUnexpected exception: sUnexpected exception (TYPE= %s)(t isinstanceRtLsmErrort ErrorNumbertPLUGIN_AUTH_FAILEDtstrRtNETWORK_CONNREFUSEDtNETWORK_HOSTDOWNterrort tracebackt format_exct NETWORK_ERRORtssltCertificateErrortAttributeErrortsixtPY3tConnectionErrortsockett PLUGIN_BUGttype(texptdesct stack_trace((s//usr/lib/python2.7/site-packages/lsm/_common.pytcommon_urllib2_error_handlerHs:            tProxycBs,eZdZddZdZdZRS(sQ Used to provide an unambiguous error when a feature is not implemented. cCs ||_dS(s< Constructor which takes an object to wrap. N(t proxied_obj(Rtobj((s//usr/lib/python2.7/site-packages/lsm/_common.pyt__init__{scCs;t|j|r%tj|j|SttjddS(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.pyR4sN(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(tTiBi tTBtTtti2tPiBitPBtPtpi<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.pytshs  cCs t|tS(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_humanscCstjdtj}|j|}d}|r|jd}|jd}|s^t|S|j}|jdd}|tkrt|t |}qnt|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_humant regex_matcht size_bytestnumberR[((s//usr/lib/python2.7/site-packages/lsm/_common.pytsize_human_2_size_bytess    cCsiy3i}t|}|jr.|j|d|jdD]-}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(Rtlentsyslog(tleveltprgtmsgtl((s//usr/lib/python2.7/site-packages/lsm/_common.pytpost_msgzs cGs0ttjtjjtjdt|dS(Ni( RRtLOG_ERRtosRtbasenametsystargvR(R((s//usr/lib/python2.7/site-packages/lsm/_common.pyRscGs9tr5ttjtjjtjdt |ndS(Ni( t LOG_VERBOSERRtLOG_INFORRRRRR(R((s//usr/lib/python2.7/site-packages/lsm/_common.pytinfost 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.pyRstcodeRs Error codeRs Error messagetdatasOptional error dataRcBseZddZdZRS(cOs2tj|||||_||_||_dS(s, Class represents an error. N(t ExceptionR0t_codet_msgt_data(RRtmessageRR8R9((s//usr/lib/python2.7/site-packages/lsm/_common.pyR0s  cCsVtj|j}|jdk rA|jrAd||j|jfSd||jfSdS(Ns%s: %s Data: %ss%s: %s (Rterror_number_to_strRRRR(Rt error_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.pyRs cCs'i|d6|d6|d6|d6|d6S(sC Used for gathering additional information about an error. tdomainRt exceptiontdebugt debug_data((RRRRR((s//usr/lib/python2.7/site-packages/lsm/_common.pytaddl_error_datascCs|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.iit__main__(RRRt __import__R(t class_nametpartstmoduleREtcomp((s//usr/lib/python2.7/site-packages/lsm/_common.pyt get_classs   RcBs"eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd 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(,iiiii i i i2i4iei}iiiiiiiiiiiiiiiiiiii,i-i3i7i^iiiiiiiicCsIx>ttjjD]'}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.pyRs(1R:R;tOKtLIB_BUGR't JOB_STARTEDtTIMEOUTtDAEMON_NOT_RUNNINGtPERMISSION_DENIEDt NAME_CONFLICTtEXISTS_INITIATORRxtNO_STATE_CHANGERRRt NO_MEMORYR5t IS_MASKEDtHAS_CHILD_DEPENDENCYtNOT_FOUND_ACCESS_GROUPt NOT_FOUND_FSt NOT_FOUND_JOBtNOT_FOUND_POOLtNOT_FOUND_FS_SStNOT_FOUND_VOLUMEtNOT_FOUND_NFS_EXPORTtNOT_FOUND_SYSTEMtNOT_FOUND_DISKt NOT_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_FREEtlocalsRt staticmethodR(((s//usr/lib/python2.7/site-packages/lsm/_common.pyRsZ t JobStatuscBseZdZdZdZRS(iii(R:R;t INPROGRESStCOMPLETEtERROR(((s//usr/lib/python2.7/site-packages/lsm/_common.pyRsc CsQt|trt|tsCtd|tt|fnt|dkr}xU|D]}t||d|q\WqMxt||D]\}}t|||qWn|t|krM|dk rMt|t j rt|t j rdSt j | st t|| rMtd|t|tt|fqMndS(Ns6%s call is returning a %s, but is expecting a sequenceiis%s call expected: %s got: %s (RRt TypeErrorRR(Rt type_comparetzipRR#t string_typestinspecttisclasst issubclass(t method_nametexp_typetact_valtavR)tact((s//usr/lib/python2.7/site-packages/lsm/_common.pyR s$  csfd}|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%tjfd}|S(Ncs||}tdkrzt|tkrdtdjtt|fntj|n,tdkrtjd|n|S(Nis.%s call expected %d return values, actual = %di(RRR:R(R8R9R(tfuncttypes(s//usr/lib/python2.7/site-packages/lsm/_common.pytinnerHs%(R2twraps(RR(R(Rs//usr/lib/python2.7/site-packages/lsm/_common.pytouterGs!((RR((Rs//usr/lib/python2.7/site-packages/lsm/_common.pytreturn_requires>s t TestCommoncBs#eZdZdZdZRS(cCsdS(N((R((s//usr/lib/python2.7/site-packages/lsm/_common.pytsetUp`sc Cs y tWn)tk r8}|jt|tnXytdddWnGtk r}|j|jdko|jdko|jdknXtddddd}|j|ddko|ddko|ddko|ddko|ddkdS( Ni tMessagetDataRRRRR(Rt assertTrueRRRRRR(RRUted((s//usr/lib/python2.7/site-packages/lsm/_common.pyt test_simplecs $ &cCsdS(N((R((s//usr/lib/python2.7/site-packages/lsm/_common.pyttearDownws(R:R;RRR(((s//usr/lib/python2.7/site-packages/lsm/_common.pyR_s  Riiiiii@Biii@iʚ;i@i@IIIIIIƤ~IIIId II(9RRtunittestRbRRtcollections.abcRt ImportErrort collectionsRt urllib.errorRRt urllib.parseRturllib2R2RR#R R&R^RRR,tobjectR-tUDS_PATHRRWRVtFalseR]R_RoRRwRRRRRRRRRRRRRRRtTestCaseRR:tmain(((s//usr/lib/python2.7/site-packages/lsm/_common.pyts               +)    (1     Q  !