Current File : //lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyc
�
.�t_c@s�dZddlmZmZddlmZddlmZddlmZmZddlm	Z	m
Z
ddlZddl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
ArgumentErrortMgmntLogger(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__RR(((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR	's	t
ConfigurationcBsSeZdZejejd�ZdgZiZdZ	dZ
ed��Ze
d�Zd�Zed��Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zed��Zed��Zed��Zd�Zed��Zd�Zee
d�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&ed��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|<nWdQX|S(sRAllocates, as necessary, and returns a modifiable, singleton
    Configuration instance for the specified filepath.  Separate entities can
    thus share one in memory copy of the configuration file allowing for
    encapsulation of per-entity manipulation of the configuration.

    Args:
      filepath (str):   path to config file
    sr+treadonlyN(tNoneRt
singletonLocktmodifiableSingltonstgetRtFalse(tclstfilepathtconfigtf((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pytmodifiableSingletonTs
cCsW|j�|jjdj|��|r=|j|�r=tS||j|<t|_tS(stAdds or replaces a VDOService object in the configuration.
    Generates an assertion error if this object is read-only.

    Arguments:
    name -- name of the VDOService
    vdo -- the VDOService to add or replace
    replace -- if True, any existing VDOService will be replaced
    Returns: False if the VDOService exists and replace is False,
      True otherwise
    s!Adding vdo "{0}" to configuration(	t_assertCanModifytlogtdebugtformatthaveVdoRt_vdostTruet_dirty(R
tnametvdotreplace((s>/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.pytisDeviceConfigured�s
"cCs�|jr
dS|js*|jjd�dS|jjdj|j��|j�r`|j�dStj	i|d6dt
�}tj�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�<WnAtk
rx}|jtjkr_�ntd�|td�<nX|dkr�td�|td�<n)tj	dtj
|t��|td�<|S(sAReturns a dictionary representing the status of this object.
    tFilesdoes not exists
not availables
Last modifieds%Y-%m-%d %H:%M:%SN(RR7tstatRR5tOSErrorterrnotENOENTttimetstrftimet	localtimeR(R
tstatuststtex((s>/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
jj|j
�r�ttd�j|j
���n|r�dnd}yYt
jj|�r�t
jj|�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
RRR&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.pyRJscCs|jstd��dS(s<Asserts that mutative operations are allowed on this object.sConfiguration is read-onlyN(R=tAssertionError(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
Rttfd((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>tk
r�}|jjdj|��tt	d���nXy|j|�Wn>tk
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��}tj|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"RRRtyaml_tagtclassmethodR RR,R1tpropertyRR3R6R%R;RMRNRWRZR]R^RaRcRfR'RRR!R>RIRlR?R�(((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyR8s>				
			6					!						(RtRRRRtutilsRRRRRRR7RPRRTR/R{R	R(((s>/usr/lib/python2.7/site-packages/vdo/vdomgmnt/Configuration.pyt<module>s