.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!dZ"dZ#dZ$dee%fdYZ&de'fdYZ(de(fdYZ)de(fdYZ*de(fdYZ+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(fd0YZ4d1e(fd2YZ5d3e(fd4YZ6d5e(fd6YZ7d7e7fd8YZ8d9e7fd:YZ9d;e7fd<YZ:d=e7fd>YZ;ej<d?Z=d@Z>dAZ?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|}|jddd}tjjtj|}t |||||SWdQXdS(Nit/t_s.lock( tostpathtabspathtconfFiletrealpathtreplacetjoinRtLOCK_DIRR(t isExclusivetfunctargstkwargst commandArgsRt lockFileBasetlockFile((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytlock0s csfd}|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=scsfd}|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 eZdZdZdZRS(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 VDOOperationcBsMeZdZdZdZdZdZdZdZdZ RS(sEvery instance of this class runs one of the subcommands requested when 'vdo [] ' is called via the execute() method.cCsUg}|jr+|j|jjn&|j||j|j|j|S(sReturn 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   cKsd}d}|jdtr3t|j|}ntj|j}xG|j||D]3}y|||WqXtk r}|}qXXqXW|jdts|jn|dk r|ndS(sApply 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,|jjtdj|jtdS(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.pytexecutes "cCs|jrHtjdkrHtdj|j}t|dtn|jrxSdddgD]?}t j |satdj|}t|dt qaqaWn|j rt jrtdj|j}t|dtnd S( sPerform 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 preflights  cCsNtj|_y|j|_Wntk r/nX|j||j|dS(sRun 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.pytruns   cKstjddt|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/eZdZdZedZdZRS(s"Implements the deactivate command.cCstt|jdS(N(R,R~R-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-MscCs|j||jdtdS(NRA(RLt _deactivateR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRQscCs|jdS(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&eZdZdZedZRS(s#Implements the growLogical command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-bscCsOtj|j}|j||j|j}|j|j|jdS(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&eZdZdZedZRS(s$Implements the growPhysical command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-vscCsItj|j}|j||j|j}|j|jdS(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.pyRps t ListOperationcBs eZdZdZdZRS(sImplements the list command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCst}x^tddgdtjD]>}tjdtj|}|r(|j|j dq(q(W|j rt |j }|t|j jO}nt|}|jtjj|GHdS(NtdmsetuptstatustnoThrows(.+?): \d \d+ i(tsetRRDt splitlinesRbtmatchRt vdoTargetNametaddtgroupR6RRR8tkeystlisttsortRtlinesepR(R/R!tvdostlinetmR>((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRs %   (R2R3R4R-RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs tModifyOperationcBs8eZdZdZedZdZdZRS(sImplements the modify command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|j||jdtdS(NRA(RLt _modifyVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRscCs'tt|j|tj|dS(N(R,RR^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.pyRs(R2R3R4R-R)RRR^R(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs   tPrintConfigFileOperationcBs&eZdZdZedZRS(s'Implements the printConfigFile command.cCs#tt|jdtdtdS(NRWR[(R,RR-R'RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs$t|jdt}|jGHdS(Nt mustExist(RRRDt asYAMLForUser(R/R!R>((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRs(R2R3R4R-R*RR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs tRemoveOperationcBs/eZdZdZedZdZRS(sImplements the remove command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|j||jdtdS(sImplements the remove command.RAN(RLt _removeVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRscCsmg}y|j|jd|WnFtk rhtdGHtdGHtdGHtjj|GHnXdS(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 RRRR(R/R!RJR((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs    (R2R3R4R-R)RRR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs tStartOperationcBs5eZdZdZedZedZRS(sImplements the start command.cCstt|jdtdS(NRY(R,RR-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|j||jdtdS(NRA(RLt _startVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRscCs!|j|j|jtdS(N(tstartt forceRebuildR|R'(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs(R2R3R4R-R)RRRR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs tStatusOperationcBs&eZdZdZedZRS(sImplements the status command.cCs)tt|jdtdtdtdS(NRWRYR[(R,RR-R'RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR- sc Cs0t|jdt}|js*t|_nyi}i|td6}tddgdtdt|tdR9t vdoStatust kernelStatust confStatusRt 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.pyRs t StopOperationcBs/eZdZdZedZdZRS(sImplements the stop command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-EscCs|j||jdtdS(NRA(RLt_stopVDOR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRIscCs|j|jdS(N(tstopRy(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRPs(R2R3R4R-R)RRR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR?s tVersionOperationcBs eZdZdZdZRS(sImplements the version command.cCstt|jdS(N(R,RR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-ZscCs"t}|j|jGHdS(N(RRtversion(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.pyRTs t OptionTogglecBs2eZdZedZedZdZRS(sCBase class for operations which either enable or disable an option.cCs/tt|jd|||_||_dS(NRY(R,RR-t_enablet _optionName(R/tenablet optionNameRY((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-js cCs|j||jdtdS(NRA(RLt _configureR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRpscCs,|jjtdj|jtdS(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.pyRws"(R2R3R4R'R-R)RRR(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRds tDisableCompressionOperationcBs eZdZdZdZRS(s*Implements the disableCompression command.cCstt|jtddS(Nt compression(R,RR-R'(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|jtdS(N(tsetCompressionR'(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs(R2R3R4R-R(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR~s tDisableDeduplicationOperationcBs eZdZdZdZRS(s-Implements the disable deduplication command.cCstt|jtddS(Nt deduplication(R,RR-R'(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|jtdS(N(tsetDeduplicationR'(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs(R2R3R4R-R(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs tEnableCompressionOperationcBs eZdZdZdZRS(s)Implements the enableCompression command.cCstt|jtddS(NR(R,RR-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|jtdS(N(RRD(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs(R2R3R4R-R(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs tEnableDeduplicationOperationcBs eZdZdZdZRS(s+Implements the enableDeduplication command.cCs#tt|jtddtdS(NRRY(R,RR-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-scCs|jtdS(N(RRD(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs(R2R3R4R-R(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRs s^[A-Z].*Operation$cCs.tj|o-|jdko-tj|jS(NR5(tinspecttisclassR2t operationRER(tmember((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyt _isOperationscCs3x,tjtj|tD]}|dqWdS(Ni(Rt getmembersRtmodulesR(t moduleNamet operation((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytmakeOperationss (AR4RaRRRRRRRRRR R R R R RtutilsRRRRRt functoolsRRt__main__tmainRRbRRtdictRhR&R)R*RFR+tobjectR5RjRmRsR~RRRRRRRRRRRRRRRtcompileRRRR2(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pytsb         (;