�
.�t_c@s|dZddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd
lm
Z
ddlmZmZm
Z
ddlmZmZmZd
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(tCommandLock(t
Configuration(t Constants(tDefaults(tMgmntLogger(t
MgmntUtils(tService(tVDOKernelModuleService(t
VDOServicetVDOServiceErrort VDOServicePreviousOperationError(t
ExitStatustSystemExitStatustUserExitStatusi����(tCommandtCommandErrort
runCommand(tTransactiont
transactional(tpartialNcOs�|d}tjj|j�}tjj|�}|jdd�d}tjjtj|�}t ||��|||�SWdQXdS(Nit/t_s.lock(
tostpathtabspathtconfFiletrealpathtreplacetjoinRtLOCK_DIRR(tisExclusivetfunctargstkwargstcommandArgsRtlockFileBasetlockFile((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
tVDOOperationcBsMeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z RS(s�Every instance of this class runs one of the subcommands
requested when 'vdo [<options>] <subcommand>' 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.pytapplyToVDOszs
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/tunused_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|jr�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(trequiresRootRtgetuidRROR=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|j<dS( Ns
Operation$tiis.VDOOperationsRWRYR[(tretsubttypeR2tlowerR=Rt getLoggertmynameRMRCRDRWR'RYR[t
vdoOperations(R/R"R=((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-�s
cCs=|jdks$|jj�dkr9ttd���ndS(s|Check that the args contain a non-None name.
Arguments:
args: the args passed
Raises:
ArgumentError
Ras"Missing required argument '--name'N(R=RBtstripRR(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR:�s$(
R2R3R4R@RLRRR^R`R-R:(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR5`s $
tActivateOperationcBs/eZdZd�Zed��Zd�ZRS(s Implements the activate command.cCstt|�j�dS(N(R,RjR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-�scCs|j||jdt�dS(NRA(RLt _activateR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRR�scCs|j�dS(N(tactivate(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRks(R2R3R4R-R)RRRk(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRj�s tChangeWritePolicyOperationcBs/eZdZd�Zed��Zd�ZRS(s)Implements the changeWritePolicy command.cCstt|�j�dS(N(R,RmR-(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-
scCsBt|d�|_|jdkr%dS|j||jdt�dS(NtwritePolicyRA(tgetattrt_newWritePolicyRBRLt_changeWritePolicyR'(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRRscCs|j|j�dS(N(tsetWritePolicyRp(R/R!RJ((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRqs(R2R3R4R-R)RRRq(((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyRms
tCreateOperationcBs5eZdZd�Zd�Zeed���ZRS(sImplements the create command.cCstt|�jdt�dS(NRY(R,RsR-RD(R/((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR-%scCsVtt|�j|�|js4ttd���n|jsRttd���ndS(Ns"Missing required argument '--name's$Missing required argument '--device'(R,RsR^R=RRtdevice(R/R!((s=/usr/lib/python2.7/site-packages/vdo/vdomgmnt/VDOOperation.pyR^)s
cCs�tj|j�}t|�j�}|d}|d=t|j||�}tj�}|j |j
�|j|j�|j
�|j�dS(NR=(RRERtvarstcopyR R=RttransactiontcreatetforcetaddUndoStagetremoveRGt
announceReady(R/R!R>targsDictR=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,R�R-(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=tgrowLogicaltvdoLogicalSizeRG(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=tgrowPhysicalRG(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(NtremoveStepssA previous operation failed.s;Recovery from the failure either failed or was interrupted.s;Add '--force' to 'remove' to perform the following cleanup.(R{RyRRRR�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(tstarttforceRebuildR|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-
scCs0t|jdt�}|js*t|_ny�i}i|td�6}tddgdtdt�|td�<tdd gdtdt�|td
�<tj �dkr�tdd
�|td�<nit
�j�td�6}i|j�td�6}i}i|td�6}x`|j||�D]L} y| j�|| j
�<Wq&tk
rq}
t|
�|| j
�<q&Xq&Wtj|dt�d GHtj|dt�d GHtj|dt�d GHtj|dtdtd��d GHtjj�tjj�Wn,tk
r+}
|jjdj|
��nXdS(NRAs
VDO statustunames-nR�RitNodetdates--rfc-3339=secondstDateisNot running as root,s some status may be unavailabletNotes
Kernel moduleRtVDOstdefault_flow_stylei����twidthtinfsexception ignored: {0}(RRR'R=RDR6RRRRXRR�R@tgetNameR
tstrtyamlt safe_dumptfloattsyststdouttflushtstderrtIOErrorRMtdebugRO(R/R!R>R9t vdoStatustkernelStatust
confStatusR�tperVdoStatusRJRK((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 tOptionTogglecBs2eZdZed�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�dstDisableCompressionOperationcBs eZdZd�Zd�ZRS(s*Implements the disableCompression command.cCstt|�jtd�dS(Ntcompression(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(tinspecttisclassR2toperationRER�(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
RRR
RtutilsRRRRRt functoolsRR�t__main__tmainRRbR�R�tdictRhR&R)R*RFR+tobjectR5RjRmRsR~R�R�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.pyt<module>sb
�(; |