/usr/lib/python3/dist-packages/uaclient/__pycache__
NameSizeModeActions
actions.cpython-310.pyc113810644editdlrm
apt.cpython-310.pyc283670644editdlrm
apt_news.cpython-310.pyc73460644editdlrm
config.cpython-310.pyc137600644editdlrm
contract.cpython-310.pyc248990644editdlrm
contract_data_types.cpython-310.pyc80680644editdlrm
data_types.cpython-310.pyc147880644editdlrm
defaults.cpython-310.pyc29130644editdlrm
event_logger.cpython-310.pyc78400644editdlrm
exceptions.cpython-310.pyc250390644editdlrm
gpg.cpython-310.pyc10250644editdlrm
livepatch.cpython-310.pyc106950644editdlrm
lock.cpython-310.pyc46350644editdlrm
log.cpython-310.pyc46330644editdlrm
secret_manager.cpython-310.pyc12560644editdlrm
security_status.cpython-310.pyc165980644editdlrm
snap.cpython-310.pyc64710644editdlrm
status.cpython-310.pyc183610644editdlrm
system.cpython-310.pyc227620644editdlrm
types.cpython-310.pyc4720644editdlrm
update_contract_info.cpython-310.pyc13320644editdlrm
upgrade_lts_contract.cpython-310.pyc29920644editdlrm
util.cpython-310.pyc135250644editdlrm
version.cpython-310.pyc24990644editdlrm
yaml.cpython-310.pyc11780644editdlrm
__init__.cpython-310.pyc1440644editdlrm
Edit: /usr/lib/python3/dist-packages/uaclient/__pycache__/system.cpython-310.pyc (22762B)
o Kiyp@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlmZmZmZmZmZmZmZddlmZmZmZdZdZdZd Zd Ze e!e"Z#d Z$d Z%ed dej&fdej&fde'fde'fde'fgZ(edde'fde'fdeejfdee'fdee)fdee)fdee)fdee'fdee'fg Z*edde'fde'fde'fde'fgZ+ed d!ee'fd"ee'fd#ee'fd$ee'fd%ee'fd&ee'fd'ee'fd(ee'fd)ee'fd*ee'fd+ee'fd,ee'fd-ee'fd.ee'fgZ,ed/d0eee'fd1eee'fgZ-d2Z.d3ej/d4eejfd5d6Z0d3ej/d4eejfd7d8Z1e dd9d4e*fd:d;Z2dd?Z4e dd9d4e'fd@dAZ5e dd9d4e,fdBdCZ6e dd9d4e'fdDdEZ7e dd9d4e+fdFdGZ8e dd9de'd4e9fdHdIZ:e dd9d4e9fdJdKZ;e dd9de'd4e9fdLdMZe dd9ddSe'd4e9fdTdUZ?e dd9d4e9fdVdWZ@e dd9d4ee'e'ffdXdYZAe dd9de'd4e(fdZd[ZBd\e'd4ee'fd]d^ZC  dd_eee'd`eee'd4e9fdadbZDdce'd4e9fdddeZEdfe'd4e'fdgdhZFddfe'dje)d4dfdkdlZG ddfe'dme'djee)d4dfdndoZHdpe'd4dfdqdrZI  s   tdduee'dveee)dwe9dxeeJdyeee'e'fdze9d4ee'e'ffd{d|ZK  s    tdduee'dveee)dwe9dxeeJd}eeeJdyeee'e'fdze9d4ee'e'ffd~dZLde'd4dfddZMde'd4e9fddZNde'd4ee'fddZOd4e'fddZPd4ee-fddZQdS)N) lru_cache)rmtree)DictList NamedTupleOptionalSequenceSetTuple)defaults exceptionsutilz/var/run/reboot-requiredz/var/run/reboot-required.pkgsz/etc/machine-idz/var/lib/dbus/machine-idz!/usr/share/distro-info/ubuntu.csvz5(?P\d+\.\d+) (LTS\s*)?(\((?P\w+))?.*zd^(?P[\d]+)[.-](?P[\d]+)[.-](?P[\d]+)-(?P[\d]+)-(?P[A-Za-z0-9_-]+)$ DistroInfoeoleol_esmseriesreleaseseries_codename KernelInfouname_machine_arch uname_release build_dateproc_version_signature_versionmajorminorpatchabiflavor ReleaseInfo distributionpretty_versionCpuInfo cpuinfo_cpucpuinfo_cpu_architecturecpuinfo_cpu_familycpuinfo_cpu_implementercpuinfo_cpu_partcpuinfo_cpu_revisioncpuinfo_cpu_variant cpuinfo_modelcpuinfo_model_namecpuinfo_steppingcpuinfo_vendor_id"sys_firmware_devicetree_base_model sysinfo_model sysinfo_typeRebootRequiredPkgsstandard_packageskernel_packagesz(Mon|Tue|Wed|Thu|Fri|Sat|Sun).*unamereturncCsftr tddStdztd|j}tj|j tj j WSt y2tdYdSw)NzPNot attempting to use timestamp of kernel changelog because we're in a containerz3Falling back to using timestamp of kernel changelogz1/usr/share/doc/linux-image-{}/changelog.Debian.gzzUnable to stat kernel changelog) is_containerLOGwarningosstatformatrdatetime fromtimestampst_mtimetimezoneutc Exception)r3 stat_resultrB1/usr/lib/python3/dist-packages/uaclient/system.py_get_kernel_changelog_timestampqs&    rDcCstt|j}|durtdt|S|d}z tj |d}Wnt y4tdt|YSw|j durB|j tj jd}|S)Nz*Unable to find build date in uname versionrz%a %b %d %H:%M:%S %Z %Yz-Unable to parse build date from uname version)tzinfo)researchRE_KERNEL_EXTRACT_BUILD_DATEversionr6r7rDgroupr;strptime ValueErrorrEreplacer>r?)r3 date_matchdate_strdtrBrBrC_get_kernel_build_dates      rQ)maxsizec Csd}z td}|d}WntytdYnwt}|j}t |}|j }t t |}|durLtd|t||||dddddd St||||t|dt|dt|d|d |d d S) Nz/proc/version_signaturez*failed to process /proc/version_signature.zFailed to parse kernel: %s) rrrrrrrrrrrrrr) load_filesplitr@r6r7r8r3machinestriprQrrFmatchRE_KERNEL_UNAMErintrJ)rproc_version_signature_fullr3rrr uname_matchrBrBrCget_kernel_infosH         r]csnddlm}tstddd|D}ddtdD}dd|Dd d|D}fd d|DS) Nr)get_installed_packages_namesz9get_installed_ubuntu_kernels needs to be executed as rootcSsg|]}d|vr|qS) linux-image-rB).0packagerBrBrC z0get_installed_ubuntu_kernels..cSs$g|]}dtd|gdvr|qS)z Linux kernelfilersubp)r`rdrBrBrCrbs z/boot/vmlinu[x|z]-*cSg|] }|tddqS)r_Nlen)r` package_namerBrBrCrbscSrg)z/boot/vmlinu?-Nrh)r` file_namerBrBrCrbscsg|]}|vr|qSrBrB)r`rIlinux_image_versionsrBrCrbrc) uaclient.aptr^r we_are_currently_root RuntimeErrorglob)r^ linux_imagevmlinux_kernel_filesvmlinuz_versionsrBrlrCget_installed_ubuntu_kernelss(  rucCstddg\}}|S)Ndpkgz--print-architecture)rfrW)out_errrBrBrC get_dpkg_archryc Cszz tdg\}}|WStjy<ztd}d|vs!d|vr%WYdSd|vr-WYdSWYdSty;YYdSww)Nsystemd-detect-virtz/proc/1/cgroupdockerbuildkitbuildahpodman)rfrWr ProcessExecutionErrorrTr@)rw_ proc_1_cgrouprBrBrC get_virt_types  rc Csd}d}d}i}i}d}zt|}Wnty#td|Yn,w|d}tdd|Dd}|d D]} d | vrN| d d \} } | || <q8zt|} Wntyftd|Ynw| d D]} d | vr| d d \} } | || <qlzt|}Wntytd|Ynwt| d | d | d| d| d| d| d| d| d| d| d|| d| ddS)Nz /proc/cpuinfoz /proc/sysinfoz#/sys/firmware/devicetree/base/modelzcould not open {}z css|] }|dr|VqdS) processorN) startswith)r`srBrBrC szget_cpu_info..r :rScpuzCPU architecturez cpu familyzCPU implementerzCPU partz CPU revisionz CPU variantmodelz model namestepping vendor_idModelType)r"r#r$r%r&r'r(r)r*r+r,r-r.r/) rTFileNotFoundErrorr6infor:rUnextrWr!get) CPUINFO_FILE SYSINFO_FILEDEVICETREE_FILEcpuinfo_valuessysinfo_valuesdevicetree_base_modelcpuinfo_contentcpuinfo_sectionsfirst_cpu_contentlinekeyvaluesysinfo_contentrBrBrC get_cpu_info sf       rcCsddlm}ddlm}|}|jr!|jdid}|r!|S|}ttfD]}t j |r>t | d}|r>|Sq)|rC|Stt}|||S)z Get system's unique machine-id or create our own in data_dir. We first check for the machine-id in machine-token.json before looking at the system file. r) machine_token)machine_id_filemachineTokenInfo machineIdr)uaclient.filesruaclient.files.state_filesrget_machine_token_filerreadETC_MACHINE_IDDBUS_MACHINE_IDr8pathexistsrTrstripstruuiduuid4write)cfgrrmachine_token_file machine_idfallback_machine_idrcontentrBrBrCget_machine_idFs.      rcCst}|dd}tdd|dd}|dd}|dd}|r$|sStt|}|s7tj|dd|d |}|pB|d d}|sKtj |d |pR|d d}t ||| |d S)NNAMEUNKNOWNz\.\d LTSz LTSVERSIONrVERSION_CODENAME VERSION_ID)orig_vermod_verr)rIr)rrrr ) _parse_os_releaserrFsubrXREGEX_OS_RELEASE_VERSIONr ParsingErrorOnOSReleaseFile groupdictMissingSeriesOnOSReleaseFilerlower) os_releaserr rrrX match_dictrBrBrCget_release_infohs0     rcCtddg\}}||vS)N/usr/bin/ubuntu-distro-infoz--supported-esmrerrwrxrBrBrCis_ltsrzrcC ttjSN)rrrrBrBrBrCis_current_series_lts rcCr)Nrz --supportedrerrBrBrC is_supportedrzrcCs,t|sdStdd|dg\}}t|dkS)zCReturn True when Ubuntu series supports ESM and is actively in ESM.Frz--seriesz-yeolr)rrfrZrrBrBrC is_active_esms   rcCrr)rrrrBrBrBrCis_current_series_active_esmrr/runrun_pathc Cs~ztdgWdStjyYnwz tgdWdSttfy'YnwdD]}tj||}tj|r<dSq*dS)z>Checks to see if this code running in a container of some sortischrootF)r{--quietz --containerT)container_typezsystemd/container) rfr rIOErrorOSErrorr8rjoinr)rfilenamerrBrBrCr5s$   r5cCs.ddlm}|D] }d|jvrdSq dS)zReturns True if any package installed has "ubuntu-desktop" in the name. This includes ubuntu-desktop, ubuntu-desktop-minimal, kubuntu-desktop, etc. r)aptzubuntu-desktopTF)uaclientrget_installed_packagesname)rrarBrBrC is_desktops   rcCsdztd}Wn tytd}Ynwi}|D]}|dd\}}|r/|d||<q|S)Nz/etc/os-releasez/usr/lib/os-release=rS")rTr splitlinesrUrW) file_contentsdatarrrrBrBrCrs    rc Csztt}Wn tytw|D]C}|d}|d|krY|dkr*d}nd|dvr4|dn|d}t|d|d |dtj |dd  tj |d  d Sqtj |d ) N,xenialz 2026-04-23LTSrrSz%Y-%m-%d)rrrrr)r) rTDISTRO_INFO_CSVrrr MissingDistroInfoFilerUrr;rKdateMissingSeriesInDistroInfoFile)rlinesrvaluesrrBrBrCget_distro_infos(     rprogramcCsrtjj|vr t|r |SddtjddtjD}dd|D}|D]}tj||}t|r6|Sq%dS)z;Find whether the provided program is executable in our PATHcSsg|]}|dqS)r)rWr`prBrBrCrbs zwhich..PATHrcSsg|]}tj|qSrB)r8rabspathrrBrBrCrbsN) r8rsepis_exeenvironrrUpathsepr)rpathsnormalized_pathsr program_pathrBrBrCwhichs rinstalled_pkgsinstalled_pkgs_regexcCstjtsdS|dur|durdSz tttd}Wn ty'YdSw|dur7t | |dkr7dS|durO|D]}|D] }t ||rMdSqAq=dS)aCheck if the system needs to be rebooted. :param installed_pkgs: If provided, verify if the any packages in the list are present on /var/run/reboot-required.pkgs. If that param is provided, we will only return true if we have the reboot-required marker file and any package in reboot-required.pkgs file. When both installed_pkgs and installed_pkgs_regex are provided, they act as an OR, so only one of the two lists must have a match to return True. :param installed_pkgs_regex: If provided, verify if the any regex in the list matches any line in /var/run/reboot-required.pkgs. If that param is provided, we will only return true if we have the reboot-required marker file and any match in reboot-required.pkgs file. When both installed_pkgs and installed_pkgs_regex are provided, they act as an OR, so only one of the two lists must have a match to return True. FNTrr) r8rrREBOOT_FILE_CHECK_PATHsetrTREBOOT_PKGS_FILE_PATHrUrri intersectionrFrG)rrreboot_required_pkgspkg_name pkg_regexrBrBrC should_reboot s,    r rcCstj|o t|tjSr)r8risfileaccessX_OK)rrBrBrCr?srrcCsht|d}td||}Wdn1swYz|dWSty3tj|ddw)z!Read filename and decode content.rbzReading file: %sNutf-8)rk file_encoding)openr6debugrdecodeUnicodeDecodeErrorr InvalidFileEncodingError)rstreamrrBrBrCrTDs     rTmodecCs@td|tjtj|ddt|t ||dS)NzCreating file: %sTexist_ok) r6rr8makedirsrdirnamepathlibPathtouchchmod)rrrBrBrC create_fileQs r#rc Csd}tj|}|rt|}t|j}|dur|}n|dur$d}zLtjtj |ddt j ddtj |d}t d||j||d ||t|j||rgt|j|j|jt|j|WdSty}z |durt|j|d}~ww) a_Write content to the provided filename encoding it if necessary. We preserve the file ownership and permissions if the file is present and no mode argument is provided. @param filename: The full path of the file to write. @param content: The content to write to the file. @param mode: The filesystem mode to set on the file. NrTrwbF)rdeletedirz*Writing file %s atomically via tempfile %sr)r8rr rr r9S_IMODEst_moderrtempfileNamedTemporaryFiler6rrrencodeflushcloser"chownst_uidst_gidrenamer@unlink)rrrtmpfis_file_present file_statf_modeerBrBrC write_fileXs>   r8 file_pathcCs>zt|td|WdStytd|YdSw)z.NzC.UTF-8)LANGLC_ALLr )stdoutstderrenv)r>rignore)errorsr)cmd exit_coderGrH)rLzRan cmd: %s, rc: %s stderr: %s) subprocessPIPEr8rr redact_sensitive_logsrPopen communicaterrr r returncodeUnboundLocalErrorr6r)r;r<r=r>r?r@ bytes_argsrGrHset_lang merged_env redacted_cmdprocrwerr out_result err_resultrBrBrC_subpsn      r] retry_sleepsc Cs|dur|nd} zt||||||d\}}W||fStjy[} z2|r7tt| td| j| j |s:tt| tdt |t | dWYd} ~ nd} ~ wwq )aRun a command and return a tuple of decoded stdout, stderr. @param subp: A list of arguments to feed to subprocess.Popen @param rcs: A list of allowed return_codes. If returncode not in rcs raise a ProcessExecutionError. @param capture: Boolean set True to log the command and response. @param timeout: Optional float indicating number of seconds to wait for a subp call to return. @param retry_sleeps: Optional list of sleep lengths to apply between retries. Specifying a list of [0.5, 1] instructs subp to retry twice on failure; sleeping half a second before the first retry and 1 second before the next retry. @param override_env_vars: Optional dictionary of environment variables. If None, the current os.environ is used for the subprocess. If defined, these env vars get merged with the current process' os.environ for the subprocess, overriding any values that already existed in os.environ. @return: Tuple of utf-8 decoded stdout, stderr @raises ProcessExecutionError on invalid command or returncode not in rcs. @raises subprocess.TimeoutError when timeout specified and the command exceeds that number of seconds. NT)r?r@zStderr: %s Stdout: %szRetrying %d more times.r)copyr]r rr6rrr7rHrGritimesleeppop) r;r<r=r>r^r?r@rwrZr7rBrBrCrfs2   rf folder_pathcCs<z t|td|WdStytd|YdSw)NzRemoved folder: %sz,Tried to remove %s but folder does not exist)rr6rr)rcrBrBrCensure_folder_absents  rd service_namecCs.z tddd|gWdStjyYdSw)a^ Get if the systemd job is active in the system. Note that any status different from "active" will make this function return False. Additionally, if the system doesn't exist we will also return False here. @param service_name: Name of the systemd job to look at @return: A Boolean specifying if the job is active or not systemctlz is-activerFT)rfr r)rerBrBrCis_systemd_unit_active$s  rgc Csz%tdddd|g\}}|r|dr|ddWStd|WdStjyA}ztjd ||d WYd}~dSd}~ww) Nrfshowz--property=ActiveStatez --no-pagerz ActiveState=rrSz9Couldn't find ActiveState in systemctl show output for %sz-Failed to get ActiveState for systemd unit %s)exc_info)rfrrUrWr6r7r r)rerwrr7rBrBrCget_systemd_unit_active_state6s2  rjcCsHtrtjStjd}|rtj|tj Stjtj ddtj S)NXDG_CACHE_HOME~z.cache) r ror UAC_RUN_PATHr8rrrrUSER_CACHE_SUBDIR expanduser)xdg_cache_homerBrBrCget_user_cache_dirQs rqcCsrztt}Wn tyYdSwg}g}d}|D]}t||r)||q||qtt|t|dS)Nz^(linux-image|linux-base).*)r1r2) rTrrrUrFrXappendr0sorted) pkg_list_strr1r2 kernel_regexpkgrBrBrCget_reboot_required_pkgs^s       rw)r)NN)rr)NFNNT)NFNNNT)Rr;rqloggingr8rrFr9rNr)r`r functoolsrshutilrtypingrrrrrr r rr r r rrrrr getLoggerreplace_top_level_logger_name__name__r6rrYrrrrZrrr!r0rH uname_resultrDrQr]ruryrrrrboolrrrrrr5rrrrr rrTr#r8r:floatr]rfrdrgrjrqrwrBrBrBrCs  $                          +#<!      6  +    Z    8