Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/deployment.pyc


Tc@sddlZddlZddlmZmZddlmZmZmZm	Z	m
Z
ddlmZm
Z
ddlmZddlmZddlmZdZd	efd
YZdefdYZd
efdYZdZdS(iN(t	ConfigObjtConfigObjError(tgetLevelNamet	getLoggertFileHandlert
StreamHandlert	Formatter(tOptionParsert
SUPPRESS_HELP(tVERSION(tPersist(tUPGRADE_MANAGERScCsg}tjj|js.tj|jntjj|j|d}|jt||js|jt	t
jntj
t|jjx7|D]/}tj|d}|jt|qWdS(s,Given a basic configuration, set up logging.s.logs;%(asctime)s %(levelname)-8s [%(threadName)-10s] %(message)sN(tostpathtexiststlog_dirtmakedirstjointappendRtquietRtsyststdoutRtsetLevelRt	log_leveltuppert
addHandlertsetFormatterR(t
configurationtprogram_namethandlerstlog_filenamethandlertformat((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytinit_loggings	
tConfigSpecOptionParsercBs#eZiZddZdZRS(cCstj||dS(N(Rt__init__(tselftunsaved_options((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR#&scOs/tj|||}t|GH|jGH|S(N(Rt
add_optiontdirtget_opt_string(R$targstkwargstoption((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR&)sN(t__name__t
__module__t_config_spec_definitionstNoneR#R&(((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR""stBaseConfigurationcBseZdZdZdZdgZejjejj	e
jdejj	dkrkejddne
eZdZdZdZdZdd	Zd
ZdZedZd
ZdZdZddZdZdZdZdZRS(sVBase class for configuration implementations.

    @cvar required_options: Optionally, a sequence of key names to require when
        reading or writing a configuration.
    @cvar unsaved_options: Optionally, a sequence of key names to never write
        to the configuration file.  This is useful when you want to provide
        command-line options that should never end up in a configuration file.
    @cvar default_config_filenames: A sequence of filenames to check when
        reading or writing a configuration.

    Default values for supported options are set as in L{make_parser}.
    s/etc/landscape/client.confitscriptsslandscape-client.conftclientcCsei|_g|_i|_d|_i|_|j|_|jjj	|_
|jjjdS(N(t_set_optionst_command_line_argst_command_line_optionsR/t_config_filenamet_config_file_optionstmake_parsert_parsertdefaultstcopyt_command_line_defaultstclear(R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR#Gs					cCsxw|j|j|j|jgD] }||kr||}PqqW|jjd|jddrnd}nt|t	|t
r|jjd|jdd}|dk	r|jd|}qn|S(sFind and return the value of the given configuration parameter.

        The following sources will be searched:
          - The attributes that were explicitly set on this object,
          - The parameters specified on the command line,
          - The parameters specified in the configuration file, and
          - The defaults.

        If no values are found and the parameter does exist as a possible
        parameter, C{None} is returned.

        Otherwise C{AttributeError} is raised.
        s--t_t-N(
R3R5R7R<R9t
has_optiontreplaceR/tAttributeErrort
isinstancet
basestringt
get_optiont
convert_value(R$tnametoptionstvalueR+((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyt__getattr__Ss	
"	"cCsR|j}|jj|_|jj|_|j|_|jj|_|S(sX
        Return a new configuration object, with the same settings as this one.
        (t	__class__R3R;R5R6R7(R$tconfig((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytclonesscCs*y|j|SWntk
r%|SXdS(s5Return the value of the C{name} option or C{default}.N(RJRB(R$RGtdefault((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytget~s
cCs<|jdr+tt|j||n
||j|<dS(sSet a configuration parameter.

        If the name begins with C{_}, it will only be set on this object and
        not stored in the configuration file.
        R>N(t
startswithtsuperR0t__setattr__R3(R$RGRI((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyRRscCs|j|jdS(shReload options using the configured command line arguments.

        @see: L{load_command_line}
        N(tloadR4(R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytreloadscCs|j||jr+|jg}t}n|j}|}x|D]>}tjj|rAtj|tjrA|j	|PqAqAW|st
|dkrd|d}nd}tj|n|j
xF|jD];}t||stjd|jdd|fqqWdS(	s
        Load configuration data from command line arguments and a config file.

        @param accept_nonexistent_default_config: If True, don't complain if
            default configuration files aren't found

        @raise: A SystemExit if the arguments are bad.

        is#error: config file %s can't be readis#error: no config file could be readsBerror: must specify --%s or the '%s' directive in the config file.R>R?N(tload_command_lineRLtFalsetdefault_config_filenamesRR
tisfiletaccesstR_OKtload_configuration_filetlenRtexitt_load_external_optionstrequired_optionstgetattrRA(R$R)t!accept_nonexistent_default_configtconfig_filenamest
allow_missingtconfig_filenametmessageR+((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyRSs,

			


	cCsdS(s<Hook for loading options from elsewhere (e.g. for --import).N((R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR^scCs2||_|jj|d}t||_dS(s4Load configuration data from the given command line.iN(R4R9t
parse_argstvarsR5(R$R)tvalues((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyRUs	cCsA||_|j}y||j|_Wntk
r<nXdS(sLoad configuration data from the given file name.

        If any data has already been set on this configuration object,
        then the old data will take precedence.
        N(R6t_get_config_objecttconfig_sectionR7tKeyError(R$tfilenamet
config_obj((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR[s	
c	Css|p|j}y"t|dtdtdt}Wn8tk
rn}t}|jt||j}nX|S(sCreate a L{ConfigObj} consistent with our preferences.

        @param config_source: Optional readable source to read from instead of
            the default configuration file.
        tlist_valuestraise_errorstwrite_empty_values(	tget_config_filenameRRVtTrueRRtwarntstrRL(R$talternative_configt
config_sourceRmtetlogger((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyRis	
cCs9|j}|j}|j|kr7i||j<n|jj}|j|j|j|j||j}x|jD]\}}|dkr||j	kr||j
j|kr||jkr||jkr|||jkr||j|=qq|||<qqW|||j<||_|j
dS(sWrite back configuration to the configuration file.

        Values which match the default option in the parser won't be saved.

        Options are considered in the following precedence:

          1. Manually set options (C{config.option = value})
          2. Options passed in the command line
          3. Previously existent options in the configuration file

        The filename picked for saving configuration options is the one
        returned by L{get_config_filename}.
        RLN(RqRiRjR7R;tupdateR5R3titemsR%R<RORltwrite(R$RlRmtall_optionstsectionRGRI((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR{s&

	c	CsQtdt}|jdddddd|jdd	dd
dddd
|S(sParser factory for supported options

        @return: An L{OptionParser} preset with options that all
            landscape-related programs accept. These include
              - C{config} (C{None})
              - C{data_path} (C{"/var/lib/landscape/client/"})
        tversions-cs--configtmetavartFILEthelps}Use config from this file (any command line options override settings from the file) (default: '/etc/landscape/client.conf').s-ds--data-pathtPATHRNs/var/lib/landscape/client/sMThe directory to store data files in (default: '/var/lib/landscape/client/').(RR	R&(R$tparser((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR8 scCse|jr|jS|jr |jS|jrax*|jD]}tj|tjr3|Sq3W|jdSdS(sPick the proper configuration file.

        The picked filename is:
          1. C{self.config}, if defined
          2. The last loaded configuration file, if any
          3. The first filename in C{self.default_config_filenames}
        iN(RLR6RWRRYRZR/(R$tpotential_config_file((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyRq3s			cCs|jS(sWGet currently loaded command line options.

        @see: L{load_command_line}
        (R5(R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytget_command_line_optionsFs((N( R,R-t__doc__R_R%RWRR
tdirnametabspathRtargvtinsertttupleRjR#RJRMR/RORRRTRVRSR^RUR[RiR{R8RqR(((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR00s0	"		 			-			
	+		t
ConfigurationcBsJeZdZdZdZedZedZedZRS(shConfiguration data for Landscape client.

    This contains all simple data, some of it calculated.
    s.https://landscape.canonical.com/message-systemc
Cstt|j}|jdddtdddd|jdd	d
ddddd
|jddddd|jddd|jdd|jddddd|jdddd|jddddtdd|jddddtdd|jddd/d!d"dd#|jd$dd1d!d"dd&|jd'dd2d!d"d
d)dd*|jd+dd,d!tdt|jd-dd3d!tdt|S(4sParser factory for supported options.

        @return: An L{OptionParser} preset for all options
            from L{BaseConfiguration.make_parser} plus:
              - C{quiet} (C{False})
              - C{log_dir} (C{"/var/log/landscape"})
              - C{log_level} (C{"info"})
              - C{url} (C{"http://landscape.canonical.com/message-system"})
              - C{ping_url} (C{"http://landscape.canonical.com/ping"})
              - C{ssl_public_key}
              - C{ignore_sigint} (C{False})
        s-qs--quietRNtactiont
store_trueRs"Do not log to the standard output.s-ls	--log-dirRRsDThe directory to write log files to (default: '/var/log/landscape').s/var/log/landscapes--log-leveltinfos/One of debug, info, warning, error or critical.s-us--urlsThe server URL to connect to.s
--ping-urls8The URL to perform lightweight exchange initiation with.s#http://landscape.canonical.com/pings-ks--ssl-public-keysMThe public SSL key to verify the server. Only used if the given URL is https.s--ignore-sigintsIgnore interrupt signals.s--ignore-sigusr1s%Ignore SIGUSR1 signal to rotate logs.s--package-monitor-intervalii<ttypetints:The interval between package monitor runs (default: 1800).s--apt-update-intervalis6The interval between apt update runs (default: 21600).s--flush-intervalitINTERVALsBThe number of seconds between flushes to disk for persistent data.s--clonesis--start-clones-overiiihi`Ti,i(RQRR8R&RVtDEFAULT_URLRR(R$R((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyR8Vs@


cCstjj|jdS(s@Return the path to the directory where Unix sockets are created.tsockets(RR
Rt	data_path(R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytsockets_pathscCstjj|jdS(sk
        Return the path to the directory where additional annotation files can
        be stored.
        s
annotations.d(RR
RR(R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytannotations_pathscCstjj|jdS(sUThe path to the previously sinlge juju-info file for
        backwards-compatibility.sjuju-info.json(RR
RR(R$((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyt
juju_filenames(	R,R-RRR8tpropertyRRR(((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyRNs	9cCsetd|j}t|j}tjj|jrD|j|n
|j||j	|j|S(sGet a L{Persist} database with upgrade rules applied.

    Load a L{Persist} database for the given C{service} and upgrade or
    mark as current, as necessary.
    Rl(
R
tpersist_filenameRtservice_nameRR
Rtapplyt
initializetsave(tservicetpersisttupgrade_manager((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pytget_versioned_persists

(RRt	configobjRRtloggingRRRRRtoptparseRRt	landscapeR	tlandscape.lib.persistR
tlandscape.upgradersRR!R"tobjectR0RR(((s8/usr/lib/python2.7/dist-packages/landscape/deployment.pyt<module>s(	U