܍~c0D nUdZddlmZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZmZdd lmZejeZd Zd d d eddgeedededgdgdZeed<eeZdede de dededdf dZGddeZGd d!Zd$d#ZdS)%zDRed Hat Subscription: Register Red Hat Enterprise Linux based system)Logger)dedentlog)subputil)Cloud)Config) MetaSchema get_meta_doc) PER_INSTANCEa[Register a Red Hat system either by username and password *or* activation and org. Following a successful registration, you can: - auto-attach subscriptions - set the service level - add subscriptions based on pool id - enable/disable yum repositories based on repo id - alter the rhsm_baseurl and server-hostname in ``/etc/rhsm/rhs.conf``. cc_rh_subscriptionzRed Hat Subscriptionz.Register Red Hat Enterprise Linux based systemfedorarhelz rh_subscription: username: joe@foo.bar ## Quote your password if it has symbols to be safe password: '1234abcd' zk rh_subscription: activation-key: foobar org: 12345 a rh_subscription: activation-key: foobar org: 12345 auto-attach: true service-level: self-support add-pool: - 1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a - 2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b enable-repo: - repo-id-to-enable - other-repo-id-to-enable disable-repo: - repo-id-to-disable - other-repo-id-to-disable # Alter the baseurl in /etc/rhsm/rhsm.conf rhsm-baseurl: http://url # Alter the server hostname in /etc/rhsm/rhsm.conf server-hostname: foo.bar.com rh_subscription)idnametitle descriptiondistros frequencyexamplesactivate_by_schema_keysmetarcfgcloudrargsreturnNct||}|s|d|dS|s |\}}|durt ||}|st d|jrE|j>| st d|j dnD|jr=| st d|j d|j nt|j tsd } t | ||j } | s't d |j |} | st d |d dS#t $rB} |t)| |d Yd} ~ dSd} ~ wwxYw|ddS)Nrz%s: module not configured.Tz-Registration failed or did not run completelyzSetting of service-level failedz(Completed auto-attach with service levelzSetting auto-attach failedzCompleted auto-attachz"Pools must in the format of a listzUnable to attach pools {0}zUnable to add or remove reposz-rh_subscription plugin completed successfullyz4rh_subscription plugin did not complete successfullyzSystem is already registered)SubscriptionManager is_configureddebug is_registered _verify_keysSubscriptionError rhn_register auto_attach servicelevel_set_service_levelr_set_auto_attachpools isinstancelistaddPoolformat update_repos log_successlog_warnstr) rrrrrsmverify verify_msgcont pool_fail return_states E/usr/lib/python3/dist-packages/cloudinit/config/cc_rh_subscription.pyhandler<Sst Sc * * *B     .555t    -7* P!#!2!2 FJT!!' 333??$$D 'C~ :"/"=,,..M+,MNNNFLL!KLLLL :**,,:+,HIIIFLL!8999x#!"(D117 DI+I666 jj22 "+4;;BHEE//++K I'(GHHH NNJ K K K K K  P P P KKA    KKN O O O O O O O O O P 566666sFG$$ H0.7H++H0ceZdZdS)r%N)__name__ __module__ __qualname__r;r%r%sDrBr%cfeZdZgdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdZdS)r ) orgactivation-keyusernamepassword disable-repo enable-repoadd-pool rhsm-baseurlserver-hostname auto-attach service-levelNc|t}||_||_|jdi|_|jd|_|jd|_|jd|_|jd|_|jd|_ |jd|_ |jd|_ |jd |_ |jd |_ |jd |_|jd |_dS) NrrKrLrJrErDrFrGrMrIrHrN)LOGrrgetrhel_cfg rhsm_baseurlserver_hostnamer+activation_keyrDuseridrGr' enable_repo disable_repor()selfrrs r;__init__zSubscriptionManager.__init__s> ;C %6;;  M--n==#}001BCC]&&z22 "m//0@AA=$$U++m'' 33  ))*55 =,,];;=,,];; M--n== M--o>>rBc:|j|dS)z>Simple wrapper for logging info messages. Useful for unittestsN)rinforYmsgs r;r1zSubscriptionManager.log_successs  crBc:|j|dS)zASimple wrapper for logging warning messages. Useful for unittestsN)rwarningr]s r;r2zSubscriptionManager.log_warns rBc|jD]?}||jvr4d|d|j}d|fcS@|j8t j|jst j|jsd}d|fS|j3|jr&t jt|jrd}d|fSdS)zq Checks that the keys in the rh_subscription dict from the user-data are what we expect. z?{0} is not a valid key for rh_subscription. Valid keys are: {1}, FNz8The key auto-attach must be a boolean value (True/False zqThe service-level key must be used in conjunction with the auto-attach key. Please re-run with auto-attach: True)TN) rR valid_rh_keysr/joinr'ris_trueis_falser(r3)rYkbad_keynot_boolno_autos r;r$z SubscriptionManager._verify_keyss  & &A*** &DIId.@$A$ABB g~%%% +   ( L) * * ).2mD !zrBcZdg} t|n#tj$rYdSwxYwdS)zg Checks if the system is already registered and returns True if so, else False identityFT) _sub_man_clirProcessExecutionError)rYcmds r;r#z!SubscriptionManager.is_registeredsM l      )   55 ts ((c\|j|j dd|jd|jg}|j-|d|j|j-|d|j t |dd }n#tj$rC}|j d kr-| d |j Yd}~d Sd}~wwxYw|j |j  dd |j d|j g}|j-|d|j|j-|d|j t |dd }n#tj$rC}|j d kr-| d |j Yd}~d Sd}~wwxYw| d| dd S|dd}|jd|dS)z Registers the system by userid and password or activation key and org. Returns True when successful False when not. Nregisterz--activationkey={0}z --org={0}z --baseurl={0}z--serverurl={0}T) logstring_valrzRegistration failed due to: {0}Fz--username={0}z--password={0}z8Unable to register system due to incomplete information.z9Use either activationkey and org *or* userid and passwordzID: z"Registered successfully with ID %s)rUrDr/rSappendrTrmrrnstdoutr2stderrrVrGsplitrstriprr")rYro return_outr:reg_ids r;r&z SubscriptionManager.rhn_registers   +$(2F%,,T-@AA""48,,C , ?11$2CDDEEE#/ ,33D4HIIJJJ )#TBBB1E -   8r>>MM9@@JJuuuuu  k%DM,E '' 44 '' 66C , ?11$2CDDEEE#/ ,33D4HIIJJJ )#TBBB1E -   8r>>MM9@@JJuuuuu   MMJ    MMK   5!!&))!,3355 ;VDDDts0/CD8DD G##H528H00H5cBddd|jg} t|d}n#tj$r}|jdkr9|jdD]}|dkr||n?|d|j Yd}~dSd}~wwxYw|dD]"}|dkr|j |#d S) Nattach--autoz--servicelevel={0}rrs z*Setting the service level failed with: {0}FT) r/r(rmrrnrvryrxr2rwstriprr"rYrorzr:lines r;r)z&SubscriptionManager._set_service_level1s>   ' '(9 : :  %c**1-JJ)   x  B&&HNN400,,Drzz d+++, @GG(( 55555 $$T** % %Drzzt$$$ts5C$BCC$c6ddg} t|d}nE#tj$r3}|d|Yd}~dSd}~wwxYw|dD]"}|dkr|j|#dS) Nr}r~rzAuto-attach failed with: {0}FrrsT)rmrrnr2r/rxrr"rs r;r*z$SubscriptionManager._set_auto_attachKs" %c**1-JJ)    MM8??BB C C C55555 $$T** % %Drzzt$$$tsA(AAcg}g}gd}t|d}|d}gd}t|d}|d}||fS)zh Gets the list pools for the active subscription and returns them in list form. )r-z --available --pool-onlyrr)r-z --consumedr)rmryrx)rY availableconsumedroresultss r; _getPoolszSubscriptionManager._getPoolsWs  544s##A&^^%%,,T22 433s##A&NN$$++D11(""rBcddg}t|d}g}|dD]F}d|vr@||ddGddg}t|d}g}|dD]F}d|vr@||ddG||fS) zl Obtains the current list of active yum repositories and returns them in list form. reposz--list-enabledrrzRepo ID::rtz--list-disabled)rmrxrur)rYrorz active_reposrepoinactive_reposs r; _getReposzSubscriptionManager._getReposks ()!#&&q)  $$T** B BDT!!##TZZ__Q%7$>$>$@$@AAA)*!#&&q) $$T** D DDT!!%%tzz#q'9&@&@&B&BCCC^++rBct|dkr|jddS|\}}g}dg}|D][}||vr-||vr)|d|3|d|\t|dkr|| t||jdd | d d dS#tj $r4}|d ||Yd }~d Sd }~wwxYwd S)zl Takes a list of subscription pools and "attaches" them to the current subscription rzNo pools to attachTr}z --pool={0}zPool {0} is not availablez/Attached the following pools to your system: %srbz--pool=rsz$Unable to attach pool {0} due to {1}NF) lenrr"rrur/r2extendrmrdreplacerrn)rYr+pool_available pool_consumed pool_listropoolr:s r;r.zSubscriptionManager.addPools u::?? HNN/ 0 0 04(,(8(8%  j H HDM))0F0F  !4!4T!:!:;;;; 9@@FFGGGG y>>A   JJy ! ! ! S!!!EYYy))229bAAt-    :AA$JJuuuuu    sAD&&E)5)E$$E)c|j}|j}|g}|g}t|ts|ddSt|ts|ddSt |dkr/t |dkr|jddS|\}}g}g}|D]D}||vr)| d |/| |Eg}g} |D]D}||vr)| d |/| |Et |dkrM|D]J} | |vr|jd | "|d | Kt | dkr | D]} |jd | d g} t |dkr| |t |dkr| | t| nE#tj$r3} |d | Yd} ~ dSd} ~ wwxYwt |dkrB|jdd|ddt |dkrB|jdd|dddS)z 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 Nz&Repo IDs must in the format of a list.Frz No repo IDs to enable or disableTz --enable={0}z --disable={0}zRepo %s is already enabledz!Repo {0} does not appear to existz.Repo %s not disabled because it is not enabledrz Unable to alter repos due to {0}zEnabled the following repos: %srbz --enable=rsz Disabled the following repos: %sz --disable=)rWrXr,r-r2rrr"rrur/rrmrrnrdr) rYereposdreposrr enable_listenable_list_failrepoid disable_listdisable_list_failfailror:s r;r0z SubscriptionManager.update_reposs!" >F >F&$''  MMB C C C5&$''  MMB C C C5 KK1  3v;;!#3#3 HNN= > > >4'+~~'7'7$ n  0 0F''"">#8#8#@#@AAAA ''////  1 1F%%##O$:$:6$B$BCCCC!((0000  1 $ $(  <''HNN#?FFFFMM;BB4HH  ! !A % %)  Ddi |  q JJ| $ $ $ {  a   JJ{ # # #      )    MM<CCAFF G G G55555  {  a   HNN1;''00bAA    |  q HNN2<((11,CC   tsIJ$(JJcFt|jr|jp|jSN)boolrVrGrU)rYs r;r!z!SubscriptionManager.is_configureds!T[2T]Jt7JKKKrBr)r>r?r@rcrZr1r2r$r#r&r)r*rrr.r0r!rArBr;r r s   M????$!!!F   FFFP4   ###(,,,,   DTTTlLLLLLrBr Fc6tjdg|z|S)z Uses the prefered cloud-init subprocess def of subp.subp and runs subscription-manager. Breaking this to a separate function for later use in mocking and unittests zsubscription-manager) logstring)r)rorrs r;rmrms" 9,-3} M M MMrB)F)__doc__loggingrtextwrapr cloudinitrrrcloudinit.cloudr cloudinit.configr cloudinit.config.schemar r cloudinit.settingsr getLoggerr>rPMODULE_DESCRIPTIONr__annotations__r3r-r< Exceptionr%r rmrArBr;rs* KJJ$$$$$$ !!!!!!######<<<<<<<<++++++g!!   " =%&!           !&N!22]//j///b ,t  57 5757#(57/557=A57 57575757p        kLkLkLkLkLkLkLkL\ NNNNNNrB