Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyc


Tc@s^ddlZddlmZddlmZmZddlmZdZdZ	dZ
dZdZdZ
dZd	Zd
ZdZdZd
ZdZiee6ee6iee6e
e6ee6e6ie	e6ee6e
e6e6ZdZdZdZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZ defdYZ!d efd!YZ"d"efd#YZ#d$efd%YZ$d&efd'YZ%d(efd)YZ&d*efd+YZ'd,efd-YZ(d.efd/YZ)d0efd1YZ*dS(2iN(tget_fqdn(tCANONICAL_MANAGEDtNOT_MANAGED(tConfigurationProxyslandscape.canonical.comtt
standalonethostedtlocalsmanagement-typescomputer-titleslandscape-hostsaccount-nametpasswordcCscy||jdd}Wntk
r4|}nXy||jd SWntk
r^|SXdS(s/
    Extract the hostname part from a URL.
    s://it/N(tindext
ValueError(turltwithout_protocol((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt derive_server_host_name_from_url(s


cCst|}d|dS(s-
    Extrapolate a url from a host name.
    shttps://s/message-system(R(t	host_name((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytderive_url_from_host_name6scCst|}d|dS(s2
    Extrapolate a ping_url from a host name.
    shttp://s/ping(R(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytderive_ping_url_from_host_name?st
StateErrorcBseZdZRS(s_
    An exception that is raised when there is an error relating to the current
    state.
    (t__name__t
__module__t__doc__(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRHstTransitionErrorcBseZdZRS(s
    An L{Exception} that is raised when a valid transition between states fails
    for some non state related reason.  For example, this error is raised when
    the user does not have the privilege of reading the configuration file,
    this causes the transition from L{VirginState} to L{InitialisedState} to
    fail but not because that transition from one state to another was not
    permitted, but rather the transition encountered an error.
    (RRR(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyROstConfigurationStatecBskeZdZdZdZdZdZed
dZ	dZ
dZdZed
d	Z
RS(sB
    Base class for states used in the L{ConfigurationModel}.
    cCs(tj||_||_||_dS(N(tcopytdeepcopyt_datat_proxyt_uisettings(tselftdatatproxyt
uisettings((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt__init__^s	cCs
|jjS(N(Rtget_config_filename(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR"cscGst|}|dks$|dkr7td|n|dkrd}|dttgkr{|jj|di}n|j|d}t|tst	dd|j
jn|j|ddS|dtt
fkr|jj|ddSt	d|ddS(	s
        Retrieve only valid values from two level dictionary based tree.

        This mainly served to pick up programming errors and could easily be
        replaced with a simpler scheme.
        iis)get() takes either 1 or 2 keys (%d given)s0Compound key [%s][%s] is invalid. The data type s%returned from the first index was %s.isKey [%s] is invalid. N(tlent	TypeErrortNonetHOSTEDtLOCALRtgett
isinstancetdicttKeyErrort	__class__RtMANAGEMENT_TYPEtCOMPUTER_TITLE(Rtargstarglentsub_dict((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR(fs$cGst|}|dks$|dkr;tdd|n|dkr_|d|j|d<nd	}|dttgkr|jj|di}nt|tst	dd|j
jn|d||d<||j|d<d	S(
s
        Set only valid values from two level dictionary based tree.

        This mainly served to pick up programming errors and could easily be
        replaced with a simpler scheme.
        iis-set() takes either 1 or 2 keys and exactly 1 svalue (%d arguments given)iis+Compound key [%s][%s] is invalid. The data s*type returned from the first index was %s.N(R#R$RR%R&R'R(R)R*R+R,R(RR/R0R1((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytsetscCs
tdS(N(tNotImplementedError(Rtasynchronoustexit_method((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt	load_datascCs
tdS(N(R3(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytmodifyscCs
tdS(N(R3(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytrevertscCs
tdS(N(R3(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytpersistscCs%t|j|j|jd|d|S(NR4R5(tExitedStateRRR(RR4R5((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pytexitsN(RRRR!R"R(R2tTrueR%R6R7R8R9R;(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRZs							tHelpercBseZdZdZRS(s}
    Base class for all state transition helpers.

    It is assumed that the Helper classes are "friends" of the
    L{ConfigurationState} classes and can have some knowledge of their
    internals.  They shouldn't be visible to users of the
    L{ConfigurationState}s and in general we should avoid seeing the
    L{ConfigurationState}'s _data attribute outside this module.
    cCs
||_dS(N(t_state(Rtstate((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR!s(RRRR!(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR=s	tModifiableHelpercBseZdZdZRS(s8
    Allow a L{ConfigurationState}s to be modified.
    cCs"t|jj|jj|jjS(N(t
ModifiedStateR>RRR(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7s(RRRR7(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR@stUnloadableHelpercBseZdZeddZRS(s@
    Disallow loading of data into a L{ConfigurationModel}.
    cCstd|jjddS(NsA ConfiguratiomModel in a s' cannot be transitioned via load_data()(RR,R(RR4R5((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR6s
N(RRRR<R%R6(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRBstUnmodifiableHelpercBseZdZdZRS(s;
    Disallow modification of a L{ConfigurationState}.
    cCstd|jjddS(NsA ConfigurationModel in s cannot transition via modify()(RR,R(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7s
(RRRR7(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRCstRevertableHelpercBseZdZdZRS(s5
    Allow reverting of a L{ConfigurationModel}.
    cCs"t|jj|jj|jjS(N(tInitialisedStateR>RRR(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8s(RRRR8(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRDstUnrevertableHelpercBseZdZdZRS(s8
    Disallow reverting of a L{ConfigurationModel}.
    cCstd|jjddS(NsA ConfigurationModel in s cannot transition via revert()(RR,R(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8s
(RRRR8(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRFstPersistableHelpercBs)eZdZdZdZdZRS(s3
    Allow a L{ConfigurationModel} to persist.
    cCs|jjj|jjt|jjj|jjt|jjj|jjtt	|jjj
|jjtt|jjj|jjt
t|jjj|jjt
t	|jjj|jjt
tdS(sC
        Persist full content to the L{UISettings} object.
        N(R>Rtset_management_typeR(R-tset_computer_titleR.tset_hosted_account_nameR&tACCOUNT_NAMEtset_hosted_passwordtPASSWORDtset_local_landscape_hostR'tLANDSCAPE_HOSTtset_local_account_nametset_local_password(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_save_to_uisettingsscCs|jjt}|tkr!n|tkr6t}nt}t|jj|t|jj	_
t|jj|t|jj	_|jj|t
|jj	_|jj|t|jj	_|jjt|jj	_|jj	jdS(so
        Persist the subset of the data we want to make live to the actual
        configuration file.
        N(R>R(R-RRR&R'RRORRRtping_urlRKtaccount_nameRMtregistration_keyR.tcomputer_titletwrite(RRt	first_key((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_save_to_configs 	!!		cCs6|j|jt|jj|jj|jjS(N(RRRYRER>RRR(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9s

(RRRRRRYR9(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRGs		tUnpersistableHelpercBseZdZdZRS(s:
    Disallow persistence of a L{ConfigurationModel}.
    cCstd|jjddS(NsA ConfiguratonModel in s& cannot be transitioned via persist().(RR,R(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9+s
(RRRR9(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRZ&sR:cBsSeZdZdedZeddZdZdZdZ	edZ
RS(st
    The terminal state of L{ConfigurationModel}, you can't do anything further
    once this state is reached.
    cCstt|jdddt|r2|n|jd|t||_t||_	t
||_t||_
dS(NR4(tsuperR:R!R%tcallableR;RBt_unloadable_helperRCt_unmodifiable_helperRFt_unrevertable_helperRZt_unpersistable_helper(RRRR R5R4((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR!6s
cCs|jjd|d|S(NR4R5(R]R6(RR4R5((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR6BscCs
|jjS(N(R^R7(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7FscCs
|jjS(N(R_R8(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8IscCs
|jjS(N(R`R9(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9LscCs|S(N((RR4((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR;OsN(RRRR%R<R!R6R7R8R9R;(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR:1s			RAcBs2eZdZdZdZdZdZRS(s
    The state of a L{ConfigurationModel} whenever the user has modified some
    data but hasn't yet L{persist}ed or L{revert}ed.
    cCsMtt|j|||t||_t||_t||_dS(N(	R[RAR!R@t_modifiable_helperRDt_revertable_helperRGt_persistable_helper(RRRR ((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR!YscCs
|jjS(N(RaR7(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7_scCs
|jjS(N(RbR8(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8bscCs
|jjS(N(RcR9(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9es(RRRR!R7R8R9(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRASs
			REcBsSeZdZdZdZdZeddZdZ	dZ
dZRS(	s
    The state of the L{ConfigurationModel} as initially presented to the
    user. Baseline data should have been loaded from the real configuration
    data, any persisted user data should be loaded into blank values and
    finally defaults should be applied where necessary.
    cCsrtt|j|||t||_t||_t||_|j	|j
sntdndS(NsAuthentication Failure(R[RER!R@RaRFR_RZR`t_load_uisettings_datat_load_live_dataR(RRRR ((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR!qs
cCs|jj}|jt||jj}|rG|jt|n|jtt|jj|jtt	|jj
|jtt|jj
|jj}|r|jtt|n|jtt	|jjdS(sJ
        Load the complete set of dialog data from L{UISettings}.
        N(Rtget_management_typeR2R-tget_computer_titleR.R&RKtget_hosted_account_nameRMtget_hosted_passwordR'ROtget_local_landscape_hosttget_local_account_nametget_local_password(RRRVtlocal_account_name((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRdzscCs|jjdr|jj}|r7|jt|n|jj}|jtdkr|jt	t
|jj|jt	t|jj
nG|jttt||jjdkr|jtt
|jjntStSdS(sS
        Load the current live subset of data from the configuration file.
        iRN(RtloadR%RVR2R.RtfindtHOSTED_LANDSCAPE_HOSTR&RKRTRMRUR'RORR<tFalse(RRVR((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRes
cCs|S(N((RR4R5((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR6scCs
|jjS(N(RaR7(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7scCs
|jjS(N(R_R8(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8scCs
|jjS(N(R`R9(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9sN(RRRR!RdReR<R%R6R7R8R9(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyREis						tVirginStatecBsAeZdZdZeddZdZdZdZ	RS(s`
    The state of the L{ConfigurationModel} before any actions have been taken
    upon it.
    cCsMtt|jt||t||_t||_t||_	dS(N(
R[RrR!tDEFAULT_DATARCR^RFR_RZR`(RRR ((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR!scCsWyt|j|j|jSWn3tk
rRt|j|j|jd|d|SXdS(NR4R5(RERRRRR:(RR4R5((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR6s
cCs
|jjS(N(R^R7(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7scCs
|jjS(N(R_R8(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8scCs
|jjS(N(R`R9(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9sN(
RRRR!R<R%R6R7R8R9(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRrs			tConfigurationModelcBsyeZdZdgddZdZeddZdZdZ	dZ
dZdZe
eeZd	Zd
Ze
eeZdZe
eZdZd
Ze
eeZdZdZe
eeZdZdZe
eeZdZdZe
eeZdZ dZ!e
e e!Z"dZ#e
e#Z$dZ%edZ&RS(s
    L{ConfigurationModel} presents a model of configuration as the UI
    requirements describe it (separate values for the Hosted and Local
    configurations) as opposed to the real structure of the configuration
    file.  This is intended to achieve the following:

       1. Allow the expected behaviour in the UI without changing the live
          config file.
       2. Supersede the overly complex logic in the controller layer with a
          cleaner state pattern.

    The allowable state transitions are:

       VirginState      --(load_data)--> InitialisedState
       VirginState      --(load_data)--> ExitedState
       VirginState      --(exit)-------> ExitedState
       InitialisedState --(modify)-----> ModifiedState
       InitialisedState --(exit)-------> ExitedState
       ModifiedState    --(revert)-----> InitialisedState
       ModifiedState    --(modify)-----> ModifiedState
       ModifiedState    --(persist)----> InitialisedState
       ModifiedState    --(exit)-------> ExitedState
    cCs.|std|}nt|||_dS(Ntloadargs(RRrt_current_state(RRtproxy_loadargsR ((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR!scCs|jS(sT
        Expose the underlying L{ConfigurationState}, for testing purposes.
        (Rv(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt	get_statescCs.|jjd|d||_t|jtS(NR4R5(RvR6R)RE(RR4R5((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR6scCs|jj|_dS(N(RvR7(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR7scCs|jj|_dS(N(RvR8(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR8scCs|jj|_dS(N(RvR9(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR9scCs|jjtS(N(RvR(R-(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_management_typescCs|jjt|dS(N(RvR2R-(Rtvalue((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_management_typescCs|jjtS(N(RvR(R.(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_computer_titlescCs|jjt|dS(N(RvR2R.(RRz((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_computer_title
scCs|jjttS(N(RvR(R&RO(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_hosted_landscape_hostscCs|jjttS(N(RvR(R'RO(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_local_landscape_hostscCs|jjtt|dS(N(RvR2R'RO(RRz((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_local_landscape_hostscCs|jjttS(N(RvR(R&RK(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_hosted_account_namescCs|jjtt|dS(N(RvR2R&RK(RRz((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_hosted_account_name scCs|jjttS(N(RvR(R'RK(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_local_account_name&scCs|jjtt|dS(N(RvR2R'RK(RRz((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_local_account_name)scCs|jjttS(N(RvR(R&RM(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_hosted_password/scCs|jjtt|dS(N(RvR2R&RM(RRz((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_hosted_password2scCs|jjttS(N(RvR(R'RM(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_local_password8scCs|jjtt|dS(N(RvR2R'RM(RRz((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_set_local_password;scCst|jtS(N(R)RxRA(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt_get_is_modifiedAscCs
|jjS(N(RvR"(R((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR"FscCs|jjd|dS(NR4(RvR;(RR4((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyR;IsN('RRRR%R!RxR<R6R7R8R9RyR{tpropertytmanagement_typeR|R}RVR~thosted_landscape_hostRRtlocal_landscape_hostRRthosted_account_nameRRRmRRthosted_passwordRRtlocal_passwordRtis_modifiedR"R;(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyRtsN																										(+Rtlandscape.lib.networkRtlandscape.ui.constantsRRt&landscape.ui.model.configuration.proxyRRptLOCAL_LANDSCAPE_HOSTtHOSTED_ACCOUNT_NAMEtLOCAL_ACCOUNT_NAMEtHOSTED_PASSWORDtLOCAL_PASSWORDR&R'R-R.RORKRMRsRRRt	ExceptionRRtobjectRR=R@RBRCRDRFRGRZR:RARERrRt(((sJ/usr/lib/python2.7/dist-packages/landscape/ui/model/configuration/state.pyt<module>s\
					Q

7"F