a -@=jFã@sHdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z mZmZmZmZmZddlmZmZddlmZddlmZdd lmZdd lmZmZmZd Z ej!Gd d „d ej"ƒƒZ#ej!Gdd„dej"ƒƒZ$ej!Gdd„dej"ƒƒZ%e&e%j'e%j(e%j)e%j*gƒZ+Gdd„deƒZ,dZ-ee.e/e.dœdd„Z0d?dd„Z1e#e$ee.e.fdœdd„Z2e,dœdd„Z3e4d œd!d"„Z5e/d œd#d$„Z6ee%e.fd œd%d&„Z7e/d œd'd(„Z8e/e/d)œd*d+„Z9e/d œd,d-„Z:e#d œd.d/„Z;e.d œd0d1„Zeeefd œd6d7„Z?d@eee/e,d9œd:d;„Z@dk�rDeAƒdS)AzGDefine 'status' utility and handler as part of cloud-init command line.éN)Údeepcopy)ÚgmtimeÚsleepÚstrftime)ÚAnyÚDictÚListÚ NamedTupleÚOptionalÚTuple)ÚsafeyamlÚsubp)Úread_cfg_paths)Ú uses_systemd)ÚPaths)Ú get_cmdlineÚ load_jsonÚload_text_filez/etc/cloud/cloud-init.disabledc@s eZdZdZdZdZdZdZdS)Ú RunningStatusz=Enum representing user-visible cloud-init application status.z not startedÚrunningZdoneÚdisabledN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú NOT_STARTEDÚRUNNINGÚDONEÚDISABLED©rrú8/usr/lib/python3.9/site-packages/cloudinit/cmd/status.pyrs rc@seZdZdZdZdZdZdS)ÚConditionStatusz;Enum representing user-visible cloud-init condition status.ÚerrorZdegradedZhealthyN)rrrrÚERRORÚDEGRADEDÚPEACHYrrrr r!%sr!c@s0eZdZdZdZdZdZdZdZdZ dZ d Z d S) Ú EnabledStatuszcCs^|tjkr d|j›d|j›�fS|tjkrR|tjtjfvrR|j|j›d|j›�fS|j|jfS)zžTranslate running and condition status to human readable strings. Returns (status, extended_status). Much of this is for backwards compatibility r"z - ú )r!r#Úvaluer$rrr)rrUrrr Útranslate_status‘s  þrX)Údetailsc Cs@t|j|jƒ\}}|j|jj|||j|j|j|j dœ|j ¥}|j dkrþd}|d}t |›d|›�ƒ|j rü| d¡r†d|d›d�}nd}|d r¤d d  |d ¡nd }|d rÐdd d d„|d  ¡Dƒ¡nd} t tj |d||d|d||| d�ƒn>|j dk�r"t tj|dddd�ƒn|j dk�rËóz+print_status...)Újoin)r`ÚkÚvrrr rbÉsþÿz print_status..z {}rZr3r[)rZÚprefixZ boot_coder4r7r5r6rFéT)ú,z: )ÚindentZ sort_keysZ separatorsrHN)rXr1r2r8r3rWr4r5r6r7r9ÚformatÚprintZlongÚgetrdÚitemsÚTABULAR_LONG_TMPLrFÚdumpsr ) ÚargsrYrDrZZ details_dictrgÚstater7Z errors_outputZrecoverable_errors_outputrrr Ú print_status¥snÿø ÷  ÿýø ýÿÿ ö ùÿ ÿÿ rs)r>cCsŽtƒ}t||jƒ}|jr`|jtjtjfvr`|jdkrJtj   d¡tj   ¡t||jƒ}t dƒqt ||ƒ|jtjkrzdS|jtjkrŠdSdS)z4Handle calls to 'cloud-init status' as a subcommand.rGÚ.r?ér)rÚget_status_detailsr=r1rrrrkÚsysr@ÚwriteÚflushrrsr2r!r#r$)ÚnamerqÚpathsrYrrr Úhandle_status_argsçs$ þ        r|cCs4ztdg|d�}Wntjy*d}Yn0d|vS)z?Return whether cloud-init is disabled via environment variable.zshow-environment©r=r\úcloud-init=disabled)rCr rB)r=Úenvrrr Ú_disabled_via_environments  r€cCsêtƒ ¡}tƒstj}d}nÆd|vr0tj}d}n²tj |¡rNtj }d  |¡}n”d|vrbtj }d}n€dtj   dd¡vs„tƒr�t|d �r�tj}d }nRtj tj |jd ¡¡r´tj}d }n.tj tj |jd ¡¡rØtj}d}n tj}d}||fS)aXReport whether cloud-init current boot status @param disable_file: The path to the cloud-init disable file. @param paths: An initialized cloudinit.helpers.Paths object. @param wait: If user has indicated to wait for cloud-init to complete. @returns: A tuple containing (code, reason) about cloud-init's status and why. zCloud-init enabled on sysvinitzcloud-init=enabledzc CsþdD�]ò}ztdd|g|d�}Wn@tjy`}z&td|j›�tjd�WYd}~dSd}~00td d „| ¡Dƒƒ}|d  d ¡s˜|d d ks˜dS|ddkrÔ|ddkr´qn|ddkrÒ|ddkrÒdSn |ddksî|ddk�rôdSdSdS)z2Return if systemd units report a cloud-init error.)zcloud-final.servicezcloud-config.servicezcloud-init.servicezcloud-init-local.serviceZshowz5--property=ActiveState,UnitFileState,SubState,MainPIDr}z^Failed to get status from systemd. Cloud-init status may be inaccurate. Error from systemctl: )ÚfileNFcSs g|]}dd„| d¡Dƒ‘qS)cSsg|] }| ¡‘qSr)rA)r`Úxrrr rbWrcz-systemd_failed...ú=)r‚)r`Úrrrr rbWrcz"systemd_failed..Z UnitFileStater�ZstaticTZ ActiveStateZactiveZSubStateZexitedrZMainPIDÚ0Zfailed) rCr rBrlÚstderrrwÚdictÚ splitlinesÚ startswith)r=Zservicer@ÚeZstatesrrr Úsystemd_failed<sJ ýú þüÿ ÿ þ   ÿ ÿr–cCstj |¡otj |¡ S)z%Return True if cloud-init is running.)rƒr„r…)Ú status_fileÚ result_filerrr Ú is_runningvsr™cCs6|tvrtjSt||ƒrtjS|dkr,tjStjSdS)z(Return the running status of cloud-init.rN)rŠrrr™rrr)r—r˜r3Ú latest_eventrrr Úget_running_status{s r›cCs4| dd¡}|r0| d¡\}}}| ¡ dd¡}|S)zyGet the datasource from status.json. Return a lowercased non-prefixed version. So "DataSourceEc2" becomes "ec2" r8r\rV)rmÚ partitionÚlowerr_)Ú status_v1r8ZdsÚ_rrr Úget_datasource‰s  r cCs2| d¡}|r|S| d¡r*d|d›�S|SdS)z¼Return a description of the current status. If we have a datasource, return that. If we're running in a particular stage, return that. Otherwise, return the boot_description. r8ZstagezRunning in stage: N)rm)ržÚboot_descriptionr8rrr Úget_description•s   r¢cCs@d}| ¡D].}t|tƒr t|| d¡p*d| d¡p6dƒ}q |S)z,Return the latest event time from status_v1.rÚstartÚfinished)ÚvaluesÚ isinstancer’Úmaxrm)ržršÚ stage_inforrr Úget_latest_event¤s    ýr©cCsˆg}i}t| ¡ƒD]j\}}t|tƒr| | dg¡¡| di¡}| ¡D]0}||vrjt||ƒ||<qL|| ||¡qLq||fS)z>Return a list of errors and recoverable_errors from status_v1.r5r6)Úsortedrnr¦r’ÚextendrmÚkeysr)ržr5r6Z_keyr¨Zcurrent_recoverable_errorsZerr_typerrr Ú get_errors±s" ÿ ÿ ÿr­F)r{r=r>c Cstj}|ptƒ}tj |jd¡}tj |jd¡}tt||ƒ\}}i}tj  |¡rdt t |ƒƒ  di¡}t |ƒ}t||ƒ} t|ƒ} | r�tdt| ƒƒnd} t|ƒ\} } | r¬tj}n | r¶tj}t|||| ƒ}|tjkrøtƒrøt|d�røtj}tj}d} |  d¡| d d ¡t|||| | | | ||ƒ S) aReturn a dict with status, details and errors. @param paths: An initialized cloudinit.helpers.paths object. @param wait: If user has indicated to wait for cloud-init to complete. Values are obtained from parsing paths.run_dir/status.json. z status.jsonz result.jsonr9z%a, %d %b %Y %H:%M:%S %zr\r}z"Failed due to systemd unit failurez‹Failed due to systemd unit failure. Ensure all cloud-init services are enabled, and check 'systemctl' or 'journalctl' for more information.r8N)r!r%rrƒr„rdr‡r‰ÚCLOUDINIT_DISABLED_FILEr…rrrmr r¢r©rrr­r#r$r›rrrr–rÚappendÚpopr0)r{r=r2r—r˜r3r¡ržr8r4ršr7r5r6r1rrr rvÉsb  ÿ  ÿý ÿÿþýÿ ÷rvcCstƒ}t td| ¡ƒ¡dS)z$Tool to report status of cloud-init.rDN)rTrwÚexitr|Ú parse_argsrRrrr Úmainsr³Ú__main__)N)NF)CrrOÚenumrFrƒrwÚcopyrÚtimerrrÚtypingrrrr r r Z cloudinitr r Zcloudinit.cmd.develrZcloudinit.distrosrZcloudinit.helpersrZcloudinit.utilrrrr®ÚuniqueÚEnumrr!r&Ú frozensetr(r)r*r+rŠr0ror;ÚboolrCrTrXrsÚintr|r€r‰r‹r–r™r›r r¢r©r­rvr³rrrrr Úst       üÿ   ü  ) þ B *:þ   ÿþ G