.t_c@sdZddlmZmZddlmZddlmZddlmZmZddlm 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 eZdZdZdZRS(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 ConfigurationcBsSeZdZejejdZdgZiZdZ dZ e dZ e dZdZedZd Zd Zd Zd Zd ZdZdZe dZedZedZdZedZdZee dZ dZ!dZ"dZ#dZ$dZ%dZ&e dZ'RS(sConfiguration 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|jdG}|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|d6dtS(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.pyRscCs|jS(s#Retrieves a list of all known VDOs.(R&(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt getAllVdosscCsJd}y|j|}Wn,tk rEttdj|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.pytgetVdos  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|jkrtSqWtS(sReturns 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*|jjddS|jjdj|j|jr`|jdStj i|d6dt }t j rt dGH|GHt |_dS|jd}tjj|rtj|nt|d}|jd |jtj|jd jt d |jtj|jd |jtj|j||jtj|WdQXtj||j|jt |_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.pytpersistsD            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 removeVdos  cCsi}d}y)tj|j}|j|td/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyRWs   cCs |dS(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|ji|_||_||_t|_||_d|_ |jrt j j |j  rttdj|j n|rdnd}yYt j j |rt j j|dkrt||}|j|WdQXqnWn%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|jS(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|jdkS(s,Returns True if this configuration is empty.i(tlenR&(R ((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR>UscCsptjj|j}tjr5td|gdStj|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|jytj|}Wn)tjjk rZtt dnXy|d}Wn`t k rtt dn>t k r}|jjdj|tt dnXy|j |Wn>t k r}|jjdj|tt dnXt |_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&  cCstjr#td|jgdStjj|jrUtj|j|jny,t |j d}t j |j=WdQXWnt k rnXdS(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||jkr0ttdjd|ndS(sChecks 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_validateVersions ((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