ó .Åt_c@s|dZddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z m Z m Z dd lmZmZmZd dlmZmZmZd dlmZmZd dlmZd dlZd dlZd dlZd dlZd dlZd dlZe ƒZ!d„Z"d„Z#d„Z$dee%fd„ƒYZ&de'fd„ƒYZ(de(fd„ƒYZ)de(fd„ƒYZ*de(fd„ƒYZ+de(fd „ƒYZ,d!e(fd"„ƒYZ-d#e(fd$„ƒYZ.d%e(fd&„ƒYZ/d'e(fd(„ƒYZ0d)e(fd*„ƒYZ1d+e(fd,„ƒYZ2d-e(fd.„ƒYZ3d/e(fd0„ƒYZ4d1e(fd2„ƒYZ5d3e(fd4„ƒYZ6d5e(fd6„ƒYZ7d7e7fd8„ƒYZ8d9e7fd:„ƒYZ9d;e7fd<„ƒYZ:d=e7fd>„ƒYZ;ej<d?ƒZ=d@„Z>dA„Z?e?e@ƒdS(Bs VDOOperation - an object representing a vdo script command $Id: //eng/vdo-releases/magnesium/src/python/vdo/vdomgmnt/VDOOperation.py#9 $ i(t ArgumentError(t CommandLock(t Configuration(t Constants(tDefaults(t MgmntLogger(t MgmntUtils(tService(tVDOKernelModuleService(t VDOServicetVDOServiceErrort VDOServicePreviousOperationError(t ExitStatustSystemExitStatustUserExitStatusiÿÿÿÿ(tCommandt CommandErrort runCommand(t Transactiont transactional(tpartialNcOs†|d}tjj|jƒ}tjj|ƒ}|jddƒd}tjjtj|ƒ}t ||ƒ|||ŽSWdQXdS(Nit/t_s.lock( tostpathtabspathtconfFiletrealpathtreplacetjoinRtLOCK_DIRR(t isExclusivetfunctargstkwargst commandArgsRt lockFileBasetlockFile((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytlock0s cs‡fd†}|S(sDDecorator that locks the configuration for exclusive (write) access.csttˆ||ŽS(N(R&tFalse(R!R"(R (s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytwrap?s((R R(((R s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt exclusivelock=scs‡fd†}|S(s@Decorator that locks the configuration for shared (read) access.csttˆ||ŽS(N(R&R'(R!R"(R (s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR(Es((R R(((R s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt sharedlockCstOperationErrorcBs eZdZd„Zd„ZRS(s=Exception raised to indicate an error executing an operation.cOs&tt|ƒj||Ž||_dS(N(tsuperR+t__init__t_msg(tselftmsgR!R"((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-XscCs|jS(N(R.(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt__str__\s(t__name__t __module__t__doc__R-R1(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR+Js t VDOOperationcBsMeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(sŽEvery instance of this class runs one of the subcommands requested when 'vdo [] ' is called via the execute() method.cCsUg}|jr+|j|jƒjƒƒn&|j|ƒ|j|j|jƒƒ|S(sïReturn a list of VDOService objects to be operated on depending on the settings of the --name and --all options. Arguments: args: The arguments passed into vdo. conf: The config file Raises: ArgumentError (talltextendt getAllVdostvaluest _checkForNametappendtgetVdotname(R/R!tconftservices((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytgetVdoServiceshs   cKsÇd}d}|jdtƒr3t|j|}ntj|jƒ}xG|j||ƒD]3}y|||ƒWqXtk rŠ}|}qXXqXW|jdtƒs®|jƒn|dk rÃ|‚ndS(sàApply a method to all specified VDOs. An exception applying the method to some VDO will not prevent it from being applied to any other VDO, however any exception will result in applyToVDOs raising an exception. If the 'readonly' keyword argument is False, the configuration will be persisted after the method has been applied to all the VDOs (whether or not it succeeded for any of them). Arguments: args (dict): The command line arguments method (callable): The method to call on each VDO; will be called as method(args, vdo) kwargs: Keyword args controlling what gets returned and to use when making the Configuration treadonlyN( tNonetgettTrueRRtmodifiableSingletonR@t Exceptiontpersist(R/R!tmethodR"t exceptionR>tvdotex((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt applyToVDOszs  cCs,|jjtdƒj|jƒƒt‚dS(s!Execute this operation. This method should be overridden by operation classes, and is intended only to be called from within the run() method below. Arguments: unused_args (dict): The command line arguments (used by subclasses) Raises: NotImplementedError s{0} unimplementedN(tlogterrorRtformatR=tNotImplementedError(R/t unused_args((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytexecutežs "cCsí|jrHtjƒdkrHtdƒj|jƒ}t|dtƒ‚n|jr§xSdddgD]?}t j |ƒsatdƒj|ƒ}t|dt ƒ‚qaqaWn|j rét jƒrétdƒj|jƒ}t|dtƒ‚nd S( s°Perform checks prior to actually executing the command. Arguments: args (dict): The command line arguments (used by subclasses) Raises: OperationError is)You must be root to use the "{0}" commandt exitStatust vdodumpconfigtvdoforcerebuildt vdoformats#executable '{0}' not found in $PATHs&{0} command not available with --noRunN(t requiresRootRtgetuidRROR=R+Rt checkBinariesRtwhichR trequiresRunModeRt noRunMode(R/R!R0t executable((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt preflight¬s  cCsNtj|_y|j|_Wntk r/nX|j|ƒ|j|ƒdS(s–Run this operation. This is the external entry point for users of VDOOperation. Arguments: args (dict): The command line arguments N(RRtKeyErrorR^RR(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytrunÅs   cKs¢tjddt|ƒjƒ}|djƒ|d|_tjtjdƒ|_ |j dt ƒ|_ |j dt ƒ|_|j dt ƒ|_|t|jtargsDictR=RJRw((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRR3s   (R2R3R4R-R^R)RRR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRss   tDeactivateOperationcBs/eZdZd„Zed„ƒZd„ZRS(s"Implements the deactivate command.cCstt|ƒjƒdS(N(R,R~R-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-MscCs|j||jdtƒdS(NRA(RLt _deactivateR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRQscCs|jƒdS(N(t deactivate(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRXs(R2R3R4R-R)RRR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR~Gs tGrowLogicalOperationcBs&eZdZd„Zed„ƒZRS(s#Implements the growLogical command.cCstt|ƒjƒdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-bscCsOtj|jƒ}|j|ƒ|j|jƒ}|j|jƒ|jƒdS(N( RRERR:R<R=t growLogicaltvdoLogicalSizeRG(R/R!R>RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRfs  (R2R3R4R-R)RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR\s tGrowPhysicalOperationcBs&eZdZd„Zed„ƒZRS(s$Implements the growPhysical command.cCstt|ƒjƒdS(N(R,R„R-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-vscCsItj|jƒ}|j|ƒ|j|jƒ}|jƒ|jƒdS(N(RRERR:R<R=t growPhysicalRG(R/R!R>RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRzs   (R2R3R4R-R)RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR„ps t ListOperationcBs eZdZd„Zd„ZRS(sImplements the list command.cCstt|ƒjƒdS(N(R,R†R-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-ŠscCsÌtƒ}x^tddgdtƒjƒD]>}tjdtj|ƒ}|r(|j|j dƒƒq(q(W|j r¡t |j ƒ}|t|j ƒjƒƒO}nt|ƒ}|jƒtjj|ƒGHdS(NtdmsetuptstatustnoThrows(.+?): \d \d+ i(tsetRRDt splitlinesRbtmatchRt vdoTargetNametaddtgroupR6RRR8tkeystlisttsortRtlinesepR(R/R!tvdostlinetmR>((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRŽs %   (R2R3R4R-RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR†„s tModifyOperationcBs8eZdZd„Zed„ƒZd„Zd„ZRS(sImplements the modify command.cCstt|ƒjƒdS(N(R,R—R-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-§scCs|j||jdtƒdS(NRA(RLt _modifyVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRR«scCs'tt|ƒj|ƒtj|ƒdS(N(R,R—R^R tvalidateModifiableOptions(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR^°scCs|j|ƒdS(N(tsetModifiableOptions(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR˜¹s(R2R3R4R-R)RRR^R˜(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR—¡s   tPrintConfigFileOperationcBs&eZdZd„Zed„ƒZRS(s'Implements the printConfigFile command.cCs#tt|ƒjdtdtƒdS(NRWR[(R,R›R-R'RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-ÃscCs$t|jdtƒ}|jƒGHdS(Nt mustExist(RRRDt asYAMLForUser(R/R!R>((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRÈs(R2R3R4R-R*RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR›½s tRemoveOperationcBs/eZdZd„Zed„ƒZd„ZRS(sImplements the remove command.cCstt|ƒjƒdS(N(R,RžR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-ÕscCs|j||jdtƒdS(sImplements the remove command.RAN(RLt _removeVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRÙscCsmg}y|j|jd|ƒWnFtk rhtdƒGHtdƒGHtdƒGHtjj|ƒGH‚nXdS(Nt removeStepssA previous operation failed.s;Recovery from the failure either failed or was interrupted.s;Add '--force' to 'remove' to perform the following cleanup.(R{RyR RRR“R(R/R!RJR ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRŸás    (R2R3R4R-R)RRRŸ(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRžÏs tStartOperationcBs5eZdZd„Zed„ƒZed„ƒZRS(sImplements the start command.cCstt|ƒjdtƒdS(NRY(R,R¡R-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-óscCs|j||jdtƒdS(NRA(RLt _startVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRR÷scCs!|j|jƒ|jtƒdS(N(tstartt forceRebuildR|R'(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR¢þs(R2R3R4R-R)RRRR¢(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR¡ís tStatusOperationcBs&eZdZd„Zed„ƒZRS(sImplements the status command.cCs)tt|ƒjdtdtdtƒdS(NRWRYR[(R,R¥R-R'RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR- sc Cs0t|jdtƒ}|js*t|_nyÓi}i|tdƒ6}tddgdtdtƒ|tdƒR9t vdoStatust kernelStatust confStatusR”t perVdoStatusRJRK((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRs<  ( (R2R3R4R-R)RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR¥s t StopOperationcBs/eZdZd„Zed„ƒZd„ZRS(sImplements the stop command.cCstt|ƒjƒdS(N(R,R¾R-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-EscCs|j||jdtƒdS(NRA(RLt_stopVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRIscCs|j|jƒdS(N(tstopRy(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR¿Ps(R2R3R4R-R)RRR¿(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR¾?s tVersionOperationcBs eZdZd„Zd„ZRS(sImplements the version command.cCstt|ƒjƒdS(N(R,RÁR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-ZscCs"tƒ}|jƒ|jƒGHdS(N(RR£tversion(R/RQtkms((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRR^s  (R2R3R4R-RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRÁTs t OptionTogglecBs2eZdZed„Zed„ƒZd„ZRS(sCBase class for operations which either enable or disable an option.cCs/tt|ƒjd|ƒ||_||_dS(NRY(R,RÄR-t_enablet _optionName(R/tenablet optionNameRY((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-js cCs|j||jdtƒdS(NRA(RLt _configureR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRpscCs,|jjtdƒj|jƒƒt‚dS(slActually update the configuration for this operation. This method must be overridden by derived classes.s{0} unimplementedN(RMRNRROR=RP(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRÉws"(R2R3R4R'R-R)RRRÉ(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRÄds tDisableCompressionOperationcBs eZdZd„Zd„ZRS(s*Implements the disableCompression command.cCstt|ƒjtdƒdS(Nt compression(R,RÊR-R'(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-„scCs|jtƒdS(N(tsetCompressionR'(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRɈs(R2R3R4R-RÉ(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRÊ~s tDisableDeduplicationOperationcBs eZdZd„Zd„ZRS(s-Implements the disable deduplication command.cCstt|ƒjtdƒdS(Nt deduplication(R,RÍR-R'(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-’scCs|jtƒdS(N(tsetDeduplicationR'(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRÉ–s(R2R3R4R-RÉ(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRÍŒs tEnableCompressionOperationcBs eZdZd„Zd„ZRS(s)Implements the enableCompression command.cCstt|ƒjtdƒdS(NRË(R,RÐR-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR- scCs|jtƒdS(N(RÌRD(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRɤs(R2R3R4R-RÉ(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRКs tEnableDeduplicationOperationcBs eZdZd„Zd„ZRS(s+Implements the enableDeduplication command.cCs#tt|ƒjtddtƒdS(NRÎRY(R,RÑR-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-®scCs|jtƒdS(N(RÏRD(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRɳs(R2R3R4R-RÉ(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRѨs s^[A-Z].*Operation$cCs.tj|ƒo-|jdko-tj|jƒS(NR5(tinspecttisclassR2t operationRERŒ(tmember((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt _isOperationºscCs3x,tjtj|tƒD]}|dƒqWdS(Ni(RÒt getmembersR´tmodulesRÖ(t moduleNamet operation((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytmakeOperations¿s (AR4RaRRRRRRRRRR R R R R RtutilsRRRRRt functoolsRRÒt__main__tmainRRbR´R±tdictRhR&R)R*RFR+tobjectR5RjRmRsR~RR„R†R—R›RžR¡R¥R¾RÁRÄRÊRÍRÐRÑtcompileRÔRÖRÛR2(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytsb         ’(;