ó .Åt_c@sÛdZddlmZmZddlmZddlmZddlmZmZddlm Z m Z ddl Z ddl Z dd l mZddlZddlZd eefd „ƒYZd e fd „ƒYZdS(sŽ Configuration - VDO manager configuration file handling $Id: //eng/vdo-releases/magnesium/src/python/vdo/vdomgmnt/Configuration.py#7 $ i(t ArgumentErrort MgmntLogger(tStateExitStatus(t VDOServiceiÿÿÿÿ(tCommandt runCommand(tFileLockt YAMLObjectN(tST_MTIMEtBadConfigurationFileErrorcBs eZdZd„Zd„ZRS(swException raised to indicate an error in processing the configuration file, such as a parse error or missing data. cOs&tt|ƒj||Ž||_dS(N(tsuperR t__init__t_msg(tselftmsgtargstkwargs((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR /scCs|jS(N(R (R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt__str__4s(t__name__t __module__t__doc__R R(((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR 's t ConfigurationcBsSeZdZejejdƒZdgZiZdZ dZ e d„ƒZ e d„Zd„Zed„ƒZd „Zd „Zd „Zd „Zd „Zd„Zd„Ze d„ƒZed„ƒZed„ƒZd„Zed„ƒZd„Zee d„Z d„Z!d„Z"d„Z#d„Z$d„Z%d„Z&e d„ƒZ'RS(sÄConfiguration of VDO volumes and associated Albireo servers. This class is designed for use with the "with" statement. If Command.noRunMode is True, the file will still be opened and read but writes will not be performed. The Configuration is stored in a simple XML format; see vdoconfig.dtd. Attributes: _vdos: A dictionary of VDOServices, indexed by name. _filename: The name of the configuration file. _readonly: True iff this Configuration is read-only. _dirty: True iff this Configuration has been modified but the changes have not been persisted. _mustExist: If True, the file must exist (otherwise a missing file is treated as an empty configuration). s.Configurationi  s/var/lock/vdo-config-singletonsu!ConfigurationcCsed}t|jdƒG}|jj|ƒ}|dkr[t|dtƒ}||j|/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pytmodifiableSingletonTs  cCsW|jƒ|jjdj|ƒƒ| r=|j|ƒr=tS||j|/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pytaddVdogs   cCs$tji|jd6|d6dtƒS(sIReturns the configuration's YAML representation to present to users. tfilenameRtdefault_flow_style(tyamltdumpRR(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt asYAMLForUser{s cCs|jS(s0Returns the file path of the configuration file.(t _filename(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRƒscCs|jS(s#Retrieves a list of all known VDOs.(R&(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt getAllVdos‰scCsJd}y|j|}Wn,tk rEttdƒj|ƒƒ‚nX|S(sRetrieves a VDO by name.sVDO volume {0} not foundN(RR&tKeyErrorRt_R$(R R)R*((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pytgetVdoŽs  cCs ||jkS(s0Returns True if we have a VDO with a given name.(R&(R R)((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR%˜scCsPtjj|ƒ}x7|jD],}|tjj|j|jƒkrtSqWtS(säReturns a boolean indicating if the configuration contains a VDO using the specified device. Both the specified device and the device from the vdos present in the configuration are fully resolved for the check. (tostpathtrealpathR&tdeviceR'R(R R:R*((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pytisDeviceConfigureds "cCs |jr dS|js*|jjdƒdS|jjdj|jƒƒ|jƒr`|jƒdStj i|d6dt ƒ}t j ƒr¥t dƒGH|GHt |_dS|jd}tjj|ƒrÔtj|ƒnt|dƒ‘}|jd ƒ|jtjƒ|jd jt d ƒƒƒ|jtjƒ|jd ƒ|jtjƒ|j|ƒ|jƒtj|ƒWdQXtj||jƒ|jƒt |_dS( s\Writes out the Configuration if necessary. If the Configuration is read-only or has not been modified, this method will silently return. If Command.noRunMode is True, any new Configuration will be printed to stdout instead of the file. This method will generate an assertion failure if the configuration file is not open. Ns&Configuration is clean, not persistingsWriting configuration to {0}RR.s New configuration (not written):s.newtwsD####################################################################s# {0}s>THIS FILE IS MACHINE GENERATED. DO NOT EDIT THIS FILE BY HAND.(t _readonlyR(R"R#R$Rt_emptyt _removeFileR/R0RRt noRunModeR5R7R8texiststremovetopentwritetlineseptflushtfsynctrenamet_fsyncDirectory(R tstnewFiletfh((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pytpersist«sD            cCs!|jƒ|j|=t|_dS(sRemoves a VDO by name.N(R!R&R'R((R R)((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt removeVdoás  cCsËi}d}y)tj|jƒ}|j|tdƒ/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRWès   cCs |dƒS(Ns/dev/YAMLInstance((R((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt_yamlMakeInstancescCs ddgS(Ntversiontvdos((R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt_yamlAttributeKeysscCs0tt|ƒj}|j|d<|j|d<|S(NR[R\(R Rt _yamlDatat_schemaVersionR&(R tdata((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR^ s  cCs4tt|ƒj|ƒ|d|_|d|_dS(NR[R\(R Rt_yamlSetAttributesR[R\(R t attributes((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRas cCs)tt|ƒj}|jddgƒ|S(NR[R\(R Rt_yamlSpeciallyHandledAttributestextend(R tspecials((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRcscCsZtt|ƒj|ƒ|j|_|j|_x%|jD]}|j|j|ƒq8WdS(N(R Rt_yamlUpdateFromInstanceR[R_R\R&t setConfig(R tinstanceR*((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRf s   cCs tt|ƒjƒi|_||_||_t|_||_d|_ |jr‰t j j |j ƒ r‰ttdƒj|j ƒƒ‚n|r•dnd}yYt j j |ƒrót j j|ƒdkrót||ƒ}|j|ƒWdQXqónWn%tk r}tt|ƒƒ‚nXdS(sConstruct a Configuration. Args: filename (str): The path to the XML configuration file Kwargs: readonly (bool): If True, the configuration is read-only. mustExist (bool): If True, the configuration file must exist. Raises: ArgumentError i  s&Configuration file {0} does not exist.trsa+iN(R RR R&R2R=RR(t _mustExistR_R7R8RARRR5R$tgetsizeRCt_readtIOErrortstr(R R-Rt mustExisttmodeRLR((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR )s$       cCsdjt|ƒj|jƒS(Ns{0}({1})(R$ttypeRR(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRJscCsdS(s<Asserts that mutative operations are allowed on this object.N((R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR!PscCst|jƒdkS(s,Returns True if this configuration is empty.i(tlenR&(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR>UscCsptjj|jƒ}tjƒr5td|gƒdStj|tjƒ}ztj |ƒWdtj |ƒXdS(sIOpen and issue an fsync on the directory containing the config file. RGN( R7R8tdirnameRRR@RRCtO_RDONLYRGtclose(R Rstfd((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRIZs cCs+|jjdj|jƒƒytj|ƒ}Wn)tjjk rZtt dƒƒ‚nXy|d}Wn`t k rŽtt dƒƒ‚n>t k rË}|jjdj|ƒƒtt dƒƒ‚nXy|j |ƒWn>t k r}|jjdj|ƒƒtt dƒƒ‚nXt |_dS(s%Reads in a Configuration from a file.sReading configuration from {0}sNot a valid configuration fileRs9Not a valid configuration file (missing 'config' section)s#Not a valid configuration file: {0}i(R"R#R$RR/t safe_loadtscannert ScannerErrorR R5R4t ExceptionRfRR((R RLtconfRRY((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRlhs&  cCs™tjƒr#td|jgƒdStjj|jƒrUtj|jƒ|jƒny,t |j dƒ}t j |j=WdQXWnt k r”nXdS(sfDeletes the current configuration file. In noRun mode, pretend that we're doing an rm of the file.trmNsr+(RR@RRR7R8RARBRIRRRRR4(R R((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR?…s   cCs4||jkr0ttdƒjd|ƒƒ‚ndS(såChecks a configuration file schema version string against the list of supported schemas. Args: ver (str): the schema version string to check Raises: BadConfigurationFileError: version not supported. s,Configuration file version {v} not supportedtvN(tsupportedSchemaVersionsR R5R$(Rtver((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt_validateVersion—s ((RRRRt getLoggertmynameR"R~RRtyaml_tagt classmethodR RR,R1tpropertyRR3R6R%R;RMRNRWRZR]R^RaRcRfR'R RR!R>RIRlR?R€(((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR8s>       6    !      (RtRRRRtutilsRRRRRRR7RPRRTR/RzR R(((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyts