Viewing File: /usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyo

ó
oBú]c@s†dZddlmZddlmZejeƒZddgZd„Z	de
fd„ƒYZd	efd
„ƒYZ
ed„ZdS(
s"
RedHat Subscription
-------------------
**Summary:** register red hat enterprise linux based system

Register a RedHat system either by username and password *or* activation and
org. Following a sucessful registration, you can auto-attach subscriptions, set
the service level, add subscriptions based on pool id, enable/disable yum
repositories based on repo id, and alter the rhsm_baseurl and server-hostname
in ``/etc/rhsm/rhs.conf``. For more details, see the ``Register RedHat
Subscription`` example config.

**Internal name:** ``cc_rh_subscription``

**Module frequency:** per instance

**Supported distros:** rhel, fedora

**Config keys**::

    rh_subscription:
        username: <username>
        password: <password>
        activation-key: <activation key>
        org: <org number>
        auto-attach: <true/false>
        service-level: <service level>
        add-pool: <list of pool ids>
        enable-repo: <list of yum repo ids>
        disable-repo: <list of yum repo ids>
        rhsm-baseurl: <url>
        server-hostname: <hostname>
iÿÿÿÿ(tlog(tutiltfedoratrhelcCsñt|d|ƒ}|jƒs2|jd|ƒdS|jƒsàyi|jƒ\}}|tk	rnt|ƒ‚n|jƒ}|stdƒ‚n|j	rÕ|j
dk	rÕ|jƒsÂtdƒ‚q|jjdƒn7|j	r|j
ƒsùtdƒ‚q|jjdƒn|jdk	rxt|jtƒsBd}	t|	ƒ‚n|j|jƒ}
|
sxtd	j|jƒƒ‚qxn|jƒ}
|
s™td
ƒ‚n|jdƒWqítk
rÜ}|jt|ƒƒ|jdƒqíXn
|jd
ƒdS(NRs%s: module not configured.s-Registration failed or did not run completelysSetting of service-level faileds(Completed auto-attach with service levelsSetting auto-attach failedsCompleted auto-attachs"Pools must in the format of a listsUnable to attach pools {0}sUnable to add or remove reposs-rh_subscription plugin completed successfullys4rh_subscription plugin did not complete successfullysSystem is already registered(tSubscriptionManagert
is_configuredtdebugtNonet
is_registeredt_verify_keystTruetSubscriptionErrortrhn_registertauto_attachtservicelevelt_set_service_levelRt_set_auto_attachtpoolst
isinstancetlisttaddPooltformattupdate_repostlog_successtlog_warntstr(tnametcfgt_cloudRt_argstsmtverifyt
verify_msgtcontt	pool_failtreturn_statte((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pythandle1sH		RcBseZRS((t__name__t
__module__(((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyRfsRcBs§eZdddddddddd	d
gZdd„Zd„Zd
„Zd„Zd„Zd„Z	d„Z
d„Zd„Zd„Z
d„Zd„Zd„ZRS(torgsactivation-keytusernametpasswordsdisable-reposenable-reposadd-poolsrhsm-baseurlsserver-hostnamesauto-attachs
service-levelcCs*|dkrt}n||_||_|jjdiƒ|_|jjdƒ|_|jjdƒ|_|jjdƒ|_|jjdƒ|_	|jjdƒ|_
|jjdƒ|_|jjdƒ|_|jjd	ƒ|_
|jjd
ƒ|_|jjdƒ|_|jjdƒ|_dS(
Ntrh_subscriptionsrhsm-baseurlsserver-hostnamesadd-poolsactivation-keyR(R)R*sauto-attachsenable-reposdisable-repos
service-level(RtLOGRRtgettrhel_cfgtrhsm_baseurltserver_hostnameRtactivation_keyR(tuseridR*R
tenable_repotdisable_repoR(tselfRR((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyt__init__ps 			cCs|jj|ƒdS(s>Simple wrapper for logging info messages. Useful for unittestsN(Rtinfo(R5tmsg((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR‚scCs|jj|ƒdS(sASimple wrapper for logging warning messages. Useful for unittestsN(Rtwarning(R5R8((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR†scCsÚxH|jD]=}||jkr
dj|dj|jƒƒ}t|fSq
W|jdk	rtj|jƒp{tj	|jƒrd}t|fS|j
dk	rÐ|jsÀtj	t|jƒƒrÐd}t|fStdfS(sq
        Checks that the keys in the rh_subscription dict from the user-data
        are what we expect.
        s?{0} is not a valid key for rh_subscription. Valid keys are: {1}s, s8The key auto-attach must be a boolean value (True/False sqThe service-level key must be used in conjunction with the auto-attach key.  Please re-run with auto-attach: TrueN(
R.t
valid_rh_keysRtjointFalseR
RRtis_truetis_falseRRR
(R5tktbad_keytnot_booltno_auto((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR	Šs

cCs3dg}yt|ƒWntjk
r.tSXtS(sg
        Checks if the system is already registered and returns
        True if so, else False
        tidentity(t_sub_man_cliRtProcessExecutionErrorR<R
(R5tcmd((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR§s	cCsH|jdk	rý|jdk	rýddj|jƒdj|jƒg}|jdk	rp|jdj|jƒƒn|jdk	r›|jdj|jƒƒnyt|dtƒd}Wqt	j
k
rù}|jdkrõ|jd	j|j
ƒƒntSXn|jdk	rú|jdk	rúdd
j|jƒdj|jƒg}|jdk	rm|jdj|jƒƒn|jdk	r˜|jdj|jƒƒnyt|dtƒd}Wqt	j
k
rö}|jdkrò|jd	j|j
ƒƒntSXn|jdƒ|jd
ƒtS|jdƒdjƒ}|jjd|ƒtS(sŽ
        Registers the system by userid and password or activation key
        and org.  Returns True when successful False when not.
        tregisters--activationkey={0}s	--org={0}s
--baseurl={0}s--serverurl={0}t
logstring_valitsRegistration failed due to: {0}s--username={0}s--password={0}s8Unable to register system due to incomplete information.s9Use either activationkey and org *or* userid and passwordsID: is"Registered successfully with ID %sN(R1RR(RR/tappendR0RDR
RREtstdoutRtstderrR<R2R*tsplittrstripRR(R5RFt
return_outR$treg_id((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyRµsD	

cCsödddj|jƒg}yt|ƒd}Wn‡tjk
r¸}|jjƒdkr•xX|jjdƒD]"}|dkrl|j|ƒqlqlWn|jdj|j	j
ƒƒƒtSXx6|jdƒD]%}|dkrÉ|jj
|ƒqÉqÉWtS(Ntattachs--autos--servicelevel={0}iRIs
s*Setting the service level failed with: {0}(RRRDRRERKRNRMRRLtstripR<RRR
(R5RFROR$tline((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyRós cCsddg}yt|ƒd}Wn-tjk
rO}|jdj|ƒƒtSXx6|jdƒD]%}|dkr`|jj|ƒq`q`Wt	S(NRQs--autoisAuto-attach failed with: {0}s
RI(
RDRRERRR<RMRRR
(R5RFROR$RS((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyRscCs~g}g}dddg}t|ƒd}|jƒjdƒ}dddg}t|ƒd}|jƒjdƒ}||fS(sh
        Gets the list pools for the active subscription and returns them
        in list form.
        Rs--availables--pool-onlyis
s
--consumed(RDRNRM(R5t	availabletconsumedRFtresults((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyt	_getPoolsscCsàddg}t|ƒd}g}xF|jdƒD]5}d|kr2|j|jdƒdjƒƒq2q2Wddg}t|ƒd}g}xF|jdƒD]5}d|kr|j|jdƒdjƒƒqqW||fS(	sl
        Obtains the current list of active yum repositories and returns
        them in list form.
        treposs--list-enabledis
sRepo ID:t:is--list-disabled(RDRMRJRR(R5RFROtactive_repostrepotinactive_repos((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyt	_getRepos's''cCs2t|ƒdkr&|jjdƒtS|jƒ\}}g}dg}xU|D]M}||kr…||kr…|jdj|ƒƒqN|jdj|ƒƒqNWt|ƒdkr.|j|ƒy:t	|ƒ|jjddj
|ƒjdd	ƒƒtSWq.tj
k
r*}|jd
j||ƒƒtSXndS(sl
        Takes a list of subscription pools and "attaches" them to the
        current subscription
        isNo pools to attachRQs
--pool={0}sPool {0} is not availables/Attached the following pools to your system: %ss, s--pool=RIs$Unable to attach pool {0} due to {1}N(tlenRRR
RWRJRRtextendRDR;treplaceRRER<(R5Rtpool_availablet
pool_consumedt	pool_listRFtpoolR$((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR=s,	




c
Cs|j}|j}|dkr'g}n|dkr<g}nt|tƒs\|jdƒtSt|tƒs||jdƒtSt|ƒdkr´t|ƒdkr´|jj	dƒt
S|jƒ\}}g}g}x@|D]8}||kr|jdj
|ƒƒqÙ|j|ƒqÙWg}g}	x@|D]8}||krS|jdj
|ƒƒq(|	j|ƒq(Wt|ƒdkrÂxI|D]>}
|
|kr¥|jj	d|
ƒq}|jdj
|
ƒƒq}Wnt|	ƒdkrûx$|	D]}
|jj	d|
ƒqÛWnd	g}t|ƒdkr&|j|ƒnt|ƒdkrH|j|ƒnyt|ƒWn-tjk
r…}|jd
j
|ƒƒtSXt|ƒdkrÃ|jj	ddj|ƒjd
dƒƒnt|ƒdkr|jj	ddj|ƒjddƒƒnt
S(sÑ
        Takes a list of yum repo ids that need to be disabled or enabled; then
        it verifies if they are already enabled or disabled and finally
        executes the action to disable or enable
        s&Repo IDs must in the format of a list.is No repo IDs to enable or disables--enable={0}s
--disable={0}sRepo %s is already enableds!Repo {0} does not appear to exists.Repo %s not disabled because it is not enabledRXs Unable to alter repos due to {0}sEnabled the following repos: %ss, s	--enable=RIs Disabled the following repos: %ss
--disable=N(R3R4RRRRR<R^RRR
R]RJRR_RDRRER;R`(
R5terepostdreposRZR\tenable_listtenable_list_failtrepoidtdisable_listtdisable_list_failtfailRFR$((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR]sn				

$



	cCst|jr|jp|jƒS(N(tboolR2R*R1(R5((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyR­sN(R&R'R:RR6RRR	RRRRRWR]RRR(((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyRjs"						>					 	PcCstjdg|d|ƒS(s¶
    Uses the prefered cloud-init subprocess def of util.subp
    and runs subscription-manager.  Breaking this to a
    separate function for later use in mocking and unittests
    ssubscription-managert	logstring(Rtsubp(RFRH((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyRD±sN(t__doc__t	cloudinitRtloggingRt	getLoggerR&R,tdistrosR%t	ExceptionRtobjectRR<RD(((sG/usr/lib/python2.7/site-packages/cloudinit/config/cc_rh_subscription.pyt<module>'s	5ÿH
Back to Directory File Manager