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/configuration.pyc


Tc@sdZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZddl
mZddlmZddlmZmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZdefdYZ de fdYZ!de"dZ#dZ$defdYZ%de&fdYZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.d Z/d!Z0e#ej1e2d"d#Z3d$Z4dS(%sInteractive configuration support for Landscape.

This module, and specifically L{LandscapeSetupScript}, implements the support
for the C{landscape-config} script.
iN(tStringIO(tis_valid_tag(t
SysVConfigtProcessError(tMethodCallError(tgather_results(tfetcht
FetchError(t
BootstrapListtBootstrapDirectory(tLandscapeReactor(tInvalidCredentialsError(tBrokerConfiguration(tRemoteBrokerConnectortConfigurationErrorcBseZdZRS(s6Raised when required configuration values are missing.(t__name__t
__module__t__doc__(((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyRstImportOptionErrorcBseZdZRS(s?Raised when there are issues with handling the --import option.(RRR(((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyR!ss
cCs:|rtj}n	tj}|j|||jdS(N(tsyststderrtstdouttwritetflush(ttexttendterrortstream((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt
print_text%s
	cCs|dk	rg|jdD]}|j^q}d|krqt|dkratdn|jdng}x@|D]8}ytj|Wq~tk
r|j	|q~Xq~W|SdS(s
    Process a string with a list of comma separated usernames, this returns
    any usernames not known to the underlying user database.
    t,tALLis$Extra users specified with ALL usersN(
tNonetsplittstriptlenRtremovetpwdtgetpwnamtKeyErrortappend(tuserstusert	user_listt
invalid_users((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytget_invalid_users.s(

tLandscapeSetupConfigurationcBs)eZdZdZdZdZRS(	tno_starttdisabletsilenttok_no_registertimport_fromcCsw|jrsd}yd|jkr|jr=|jtjd<n|jrY|jtjd<n|j|j}|jdt|}natj	j
|jstd|jn6y|jd|j}Wntd|jnXWn%tk
r}tt
|nXd}|r;|j|kr;||j}n|sWtd|jn|j|j||_ndS(	sHandle the --import parameter.

        Imported options behave as if they were passed in the
        command line, with precedence being given to real command
        line options.
        s://t
http_proxythttps_proxytalternative_configsFile %s doesn't exist.s$Couldn't read configuration from %s.sNothing to import at %s.N(R2RR3tostenvironR4tfetch_import_urlt_get_config_objectRtpathtisfileRt	Exceptiontstrtconfig_sectiontupdatet_command_line_options(tselftparsertcontentRtoptions((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt_load_external_optionsHs>					cCsotd|d}yt|}Wntk
rE}t|}nX|dk	rktd||fn|S(s(Handle fetching of URLs passed to --url.s!Fetching configuration from %s...s+Couldn't download configuration from %s: %sN(RRRRR=R(RAturlt
error_messageRCR((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyR8tscCstt|j}|jddddddd|jddd	dd
|jdddd
ddd|jdddddd|jddddd|jdddd
tdd|jdddd
tdd|jdddd
tdd|S(sK
        Specialize the parser, adding configure-specific options.
        s--importtdestR2tmetavartFILENAME_OR_URLthelpsFilename or URL to import configuration from. Imported options behave as if they were passed in the command line, with precedence being given to real command line options.s--script-userstUSERSslA comma-separated list of users to allow scripts to run.  To allow scripts to be run by any user, enter: ALLs--include-manager-pluginstPLUGINStdefaultts2A comma-separated list of manager plugins to load.s-ns
--no-starttactiont
store_trues%Don't start the client automatically.s--ok-no-registersBReturn exit code 0 instead of 2 if the client can't be registered.s--silentsRun without manual interaction.s	--disables/Stop running clients and disable start at boot.s--inits1Set up the client directories structure and exit.(tsuperR-tmake_parsert
add_optiontFalse(RARB((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyRSs((sno_startsdisablessilentsok_no_registersimport_from(RRtunsaved_optionsRER8RS(((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyR-Cs
	,	tLandscapeSetupScriptcBseZdZdZdZdZedZedZe	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZRS(s2
    An interactive procedure which manages the prompting and temporary storage
    of configuration parameters.

    Various attributes on this object will be set on C{config} after L{run} is
    called.

    @ivar config: The L{BrokerConfiguration} object to read and set values from
        and to.
    cCs
||_dS(N(tconfig(RARX((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt__init__scCsJ|jj}tddjg|D]}|jd^q%dS(Ns
RO(R!t
splitlinesRtjoin(RARtlinestline((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt	show_helpscCs>x7tr9t|}|r|S|s)Pn|jdqWdS(sPrompt the user on the terminal for a value

        @param msg: Message to prompt user with
        @param required: True if value must be entered
        s/This option is required to configure Landscape.N(tTruet	raw_inputR^(RAtmsgtrequiredtvalue((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytprompt_get_inputs	cCs{t|j|d}|r,|d|7}n
|d7}|oFt|}|j||}|rwt|j||ndS(stPrompt the user on the terminal for a value.

        @param option: The attribute of C{self.config} that contains the
            default and which the value will be assigned to.
        @param msg: The message to prompt the user with (via C{raw_input}).
        @param required: If True, the user will be required to enter a value
            before continuing.
        s [%s]: s: N(tgetattrRXRtboolRdtsetattr(RAtoptionRaRbRNtresult((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytprompts	
cCst|j|d}|d7}xtrtj|}|rOtjd}n|r||krq|jdqt|j||Pq"|s|rPq"|jdq"WdS(sPrompt the user on the terminal for a password and mask the value.

        This also prompts the user twice and errors if both values don't match.

        @param option: The attribute of C{self.config} that contains the
            default and which the value will be assigned to.
        @param msg: The message to prompt the user with (via C{raw_input}).
        @param required: If True, the user will be required to enter a value
            before continuing.
        s: sPlease confirm: sKeys must match.s/This option is required to configure Landscape.N(ReRXRR_tgetpassR^Rg(RARhRaRbRNRctvalue2((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytpassword_prompts
	
cCs||rd}nd}x`trwt||j}|rp|jdrMtS|jdr`tS|jdq|SqWdS(Ns [Y/n]s [y/N]tntysInvalid input.(R_R`tlowert
startswithRUR^(RAtmessageRNtdefault_msgRc((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt
prompt_yes_nos		cCs=d|jjkrdS|jd|jddtdS(Ntcomputer_titles%
            The computer title you provide will be used to represent this
            computer in the Landscape user interface. It's important to use
            a title that will allow the system to be easily recognized when
            it appears on the pending computers page.
            sThis computer's title(RXtget_command_line_optionsR^RjR_(RA((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytquery_computer_titles
cCs=d|jjkrdS|jd|jddtdS(Ntaccount_names
            You must now specify the name of the Landscape account you
            want to register this computer with. Your account name is shown
            under 'Account name' at https://landscape.canonical.com .
            sAccount name(RXRvR^RjR_(RA((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytquery_account_names
cCsJ|jj}d|krdS|jd|jj|jdddS(Ntregistration_keys
            A registration key may be associated with your Landscape
            account to prevent unauthorized registration attempts.  This
            is not your personal login password.  It is optional, and unless
            explicitly set on the server, it may be skipped here.

            If you don't remember the registration key you can find it
            at https://landscape.canonical.com/account/%s
            sAccount registration key(RXRvR^RxRm(RAtcommand_line_options((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytquery_registration_key#s		cCsz|jj}d|kr+d|kr+dS|jdd|krW|jddnd|krv|jddndS(NR3R4s>
            The Landscape client communicates with the server over HTTP and
            HTTPS.  If your network requires you to use a proxy to access HTTP
            and/or HTTPS web sites, please provide the address of these
            proxies now.  If you don't use a proxy, leave these fields empty.
            sHTTP proxy URLsHTTPS proxy URL(RXRvR^Rj(RARD((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt
query_proxies6scCs|jj}d|kr]d|kr]t|d}|rYtddj|ndS|jdd}g|jjjdD]}|j^q}|dgkrg}nd	|k}|j	|d
|rbd	|kr|j
d	n|jdx{tr^|jddt|jj
}|s5Pq|jddj|d|j_
qWnd	|kr~|jd	ndj||j_dS(
Ntinclude_manager_pluginstscript_userssUnknown system users: %ss, sb
            Landscape has a feature which enables administrators to run
            arbitrary scripts on machines under their control. By default this
            feature is disabled in the client, disallowing any arbitrary script
            execution. If enabled, the set of users that scripts may run as is
            also configurable.
            sEnable script execution?RROtScriptExecutionRNs!
                By default, scripts are restricted to the 'landscape' and
                'nobody' users. Please enter a comma-delimited list of users
                that scripts will be restricted to. To allow scripts to be run
                by any user, enter "ALL".
                sScript users(RXRvR,RR[R^R~R R!RtR'R_RjRRR#(RARDR+Ratptincluded_pluginsRN((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytquery_script_pluginHs>.			cCsC|jj}d|krdS|jd|jddtdS(s!Query access group from the user.taccess_groupNsBYou may provide an access group for this computer e.g. webservers.sAccess group(RXRvR^RjRU(RARD((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytquery_access_groupws

cCs`g}|r\g|jdD]}|j^q}g|D]}t|s;|^q;}n|S(sm
        Splits a string on , and checks the validity of each tag, returns any
        invalid tags.
        R(R R!R(RAttagnamestinvalid_tagsttagttags((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt_get_invalid_tagss
((cCs|jj}d|krT|j|d}|rPtddj|ndS|jdxOtr|jddt|j|jj	r|jdd|j_	qdPqdWdS(sQuery tags from the user.RsInvalid tags: %ss, Ns;You may provide tags for this computer e.g. server,precise.tTagss3Tag names may only contain alphanumeric characters.(RXRvRRR[R^R_RjRURR(RARDR((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt
query_tagss
	
cCs|jddS(Ns
            This script will interactively set up the Landscape client. It will
            ask you a few questions about this computer and your Landscape
            account, and will submit that information to the Landscape server.
            After this computer is registered it will need to be approved by an
            account administrator on the pending computers page.

            Please see https://landscape.canonical.com for more information.
            (R^(RA((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytshow_headers	cCsT|j|j|j|j|j|j|j|jdS(syKick off the interactive process which prompts the user for data.

        Data will be saved to C{self.config}.
        N(RRwRyR|R}RRR(RA((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytruns






(RRRRYR^RdRURjRmR_RtRwRyR|R}RRRRRR(((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyRWs"
					
			/	
			cCst}|jtdS(s6Configure the init script to start the client on boot.N(Rtset_start_on_bootR_(t
sysvconfig((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt"setup_init_script_and_start_clients	cCs$t}|j|jtdS(sj
    Stop landscape-client and change configuration to prevent starting
    landscape-client on boot.
    N(Rtstop_landscapeRRU(R((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt#stop_client_and_disable_init_scripts	
cCsl|jdkr4tjjdr4tjd|_n|jdkrhtjjdrhtjd|_ndS(s
    If a http_proxy and a https_proxy value are not set then copy the values,
    if any, from the environment variables L{http_proxy} and L{https_proxy}.
    R3R4N(R3RR6R7tgetR4(RX((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytsetup_http_proxys!!cCsG|jrC|jrC|jdo.|jdsCtdqCndS(s
    Ensure that silent configurations which plan to start landscape-client are
    have both an account_name and computer title.
    RxRus0An account name and computer title are required.N(R0R.RR(RX((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytcheck_account_name_and_passwordscCsb|jdr^t|jd}|rFtddj|n|js^d|_q^ndS(s{
    If the configuration allows for script execution ensure that the configured
    users are valid for that purpose.
    RsUnknown system users: %ss, RN(RR,RR[R~(RXR+((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytcheck_script_userss	cCsJ|jrF|jjdrFtj|jd}t|||_ndS(sg
    Decode base64 encoded SSL certificate and push that back into place in the
    config object.
    sbase64:iN(tssl_public_keyRqtbase64tdecodestringtstore_public_key_data(RXtdecoded_cert((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt$decode_base64_ssl_public_certificatescCsDt|t}|jsy|jr/tqy|jsytd}|jjdsftqvt	j
dqynt|t||jrt
|nt|}|jt||j|js@y|jWq@tk
r<tddttddtd}|jr,d}nt	j
|q@Xnd	S(
s
    Perform steps to ensure that landscape-client is correctly configured
    before we attempt to register it with a landscape server.

    If we are not configured to be silent then interrogate the user to provide
    necessary details for registration.
    sl
The Landscape client must be started on boot to operate correctly.

Start Landscape client on boot? (Y/n): tNs Aborting Landscape configurations&Couldn't restart the Landscape client.RsOThis machine will be registered with the provided details when the client runs.iiN(tbootstrap_treeRR.R0Rtis_configured_to_runR`tupperRqRtexitRRRRWRRRtrestart_landscapeRRR_R1(RXRtanswertscriptt	exit_code((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytsetups:
			



	



	
			cCsPtddddtddddg}t|jd|jd|jdS(	s#Create the client directories tree.s
$data_patht	landscapetrootis$annotations_patht	data_pathtannotations_pathN(R	Rt	bootstrapRR(RXtbootstrap_list((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyR,s
cCsftjj|jtjj|jd}td|t|d}|j||j	|S(s
    Write out the data from the SSL certificate provided to us, either from a
    bootstrap.conf file, or from EC2-style user-data.

    @param config:  The L{BrokerConfiguration} object in use.
    @param certificate_data: a string of data that represents the contents of
    the file to be written.
    @return the L{BrokerConfiguration} object that was passed in, updated to
    reflect the path of the ssl_public_key file.
    s.ssl_public_keys#Writing SSL CA certificate to %s...tw(
R6R:R[Rtbasenametget_config_filenameRtopenRtclose(RXtcertificate_datatkey_filenametkey_file((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyR6s	

ics1dkrtng
fdfdfdfdfd	fdddtjd		fd
}fd}t
jd|d
t}|j||j|j	r-|dn|S(sInstruct the Landscape Broker to register the client.

    The broker will be instructed to reload its configuration and then to
    attempt a registration.

    @param reactor: The reactor to use.  Please only pass reactor when you
        have totally mangled everything with mocker.  Otherwise bad things
        will happen.
    @param max_retries: The number of times to retry connecting to the
        landscape client service.  The delay between retries is calculated
        by Twisted and increases geometrically.  The default of 14 results in
        a total wait time of about 70 seconds.

        initialDelay = 0.05
        factor =  1.62
        maxDelay = 30
        max_retries = 14

        0.05 * (1 - 1.62 ** 14) / (1 - 1.62) = 69 seconds
   csQjs9x-|D]"}|dk	rj|qqWnjjdS(N(R1RR't
disconnecttstop(terrorsR(treactortexit_with_errort	connectorRX(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyRes	

csddtdS(Ns)Invalid account name or registration key.Ri(R_((t
on_message(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytfailurems	csddS(NsSystem successfully registered.(((R(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytsuccessrscsddtdS(NsWe were unable to contact the server. Your internet connection may be down. The landscape client will continue to try and contact the server periodically.Ri(R_((R(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytexchange_failureus	cs|jttjdS(N(ttrapRRR(R(R(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pythandle_registration_errors}scs-|jdtddtdgS(NRsUnknown error occurred.i(tgetTracebackR_(R(R(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt	catch_allssPlease wait... ROicsoid6d6d6}|j||jjg}t|dt}|j|jdS(Nsregistration-donesregistration-failedsexchange-failedtconsume_errors(t
call_on_eventtregistert
addErrbackRR_taddCallback(tremotethandlerst	deferredstresults(RRRRRR(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytgot_connections


cs1ddtddtdgdS(Ns;There was an error communicating with the Landscape client.RsOThis machine will be registered with the provided details when the client runs.i(R_(R(RR(s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt	got_errors
		tmax_retriestquietiN(
RR
ttimetsleepR
tconnectR_RRR(RXRton_errorRRRRRi((RRRRRRRRRRRXs;/usr/lib/python2.7/dist-packages/landscape/configuration.pyRKs*





cCs5t}y|j|Wn6tk
rR}tt|dttjdnXtj	dkrutjdn|j
rt|tjdn|jrt
dSyt|Wn0tk
r}tt|tjdnX|jrt|n.td}|jjds1t|ndS(NRiis%landscape-config must be run as root.s Aborting Landscape configurations:
Request a new registration for this computer now? (Y/n): R(R-tloadRRR=R_RRR6tgetuidtinitRR/RRR<R0RR`RRq(targsRXRteR((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pytmains0		
		
(5RRRRR6RkR$Rtlandscape.lib.tagRtlandscape.sysvconfigRRtlandscape.lib.ampRtlandscape.lib.twisted_utilRtlandscape.lib.fetchRRtlandscape.lib.bootstrapRR	tlandscape.reactorR
tlandscape.broker.registrationRtlandscape.broker.configRtlandscape.broker.ampR
R<RRRURR,R-tobjectRWRRRRRRRRRRRRR(((s;/usr/lib/python2.7/dist-packages/landscape/configuration.pyt<module>sH		d		
				
	.	
	`