3 %Tf6@sfddlmZddlmZddlmZmZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddlZddlZddlZddlZddlmZddlmZd Zed Zed Zed Zed ZedZedZedZedZedZ edZ!edZ"edZ#edZ$Gdddej%Z&Gdddej'j(Z)ddZ*Gddde+Z,dd Z-d!d"Z.dS)#)absolute_import)unicode_literals)_loggerN)copy)PRIO_PLUGINCONFIG)ustr) up2dateErrorsz_spacewalk.jsonz7CloudLinux Network based repositories will be disabled.z4CloudLinux Network channel support will be disabled.z@There was an error communicating with CloudLinux Network server.z=This system is not registered with CloudLinux Network server.z.This system is not subscribed to any channels.zSystemId could not be acquired.z%You can use rhn_register to register.z@This system is receiving updates from CloudLinux Network server.zFor security reasons packages from CloudLinux Network based repositories can be verified only with locally installed gpg keys. GPG key '%s' has been rejected.z.Package profile information could not be sent.z=Missing required login information for CloudLinux Network: %sz'Leapp upgrade is running - using cache.z>Spacewalk plugin has to be run under with the root privileges.csZeZdZdZfddZddZddZdd d Zd d Zd dZ ddZ ddZ Z S) SpacewalkZ spacewalkcstt|j||||_||_tjj|jjj t |_ d|_ i|_ t|jj|_|j|j|_d|jjkr|jjd}x |D]\}}|jj||tq|Wtjjstjtd|j_|jjsdStjd|jdS)NFmainzinitialized Spacewalk plugin)superr __init__basecliospathjoinconfZ persistdirSTORED_CHANNELS_NAMEstored_channels_pathconnected_to_spacewalk up2date_cfgrZ read_configparsersectionsitems _set_valuerdnfutilZ am_i_rootrwarning MUST_BE_ROOTenableddebugactivate_channels)selfrroptionskeyvalue) __class__/usr/lib/python3.6/spacewalk.pyr ;s(    zSpacewalk.__init__cCs|jjs dSd|jj_dS)NT)rr rZdemandsZ root_user)r#r(r(r)configRszSpacewalk.configcCstjddS)Nz$/usr/sbin/clnreg_ks --strict-edition)rsystem)r#r(r(r)clnregWszSpacewalk.clnregTcCsi}d}d}d}d}|j}|s(|}ntjjdrFtjt|}ntjj |_ t |j }|j df}d}xl|sytj j |jjd}d}Wqntjk r} z*|dkr|jd}wntjdtt| dSd} ~ XqnXqnW|stjdtt|jidSytjj|jjd} Wntjk rF} ztjdtt| dSd} ~ XnXtjk rttjdtt|jidStjk rtjd ttt tdSXd|_!tj"t#x,| D]$} | d rt$| j%|| d <qW|j||j&j'} x|j%D]\} }|j(| }d}|r|j(d }t)|j}| |j*j+krf|j*j%| }x |D]\}}|j,||t-qJWt.||j&j||j|||||j/|j0d }| j1|qWtj2|dS) Nrz/etc/cln_leapp_in_progressZuseNoSSLForPackagesF)timeoutTz%s %s %sz%s %sz %s %s %s %sversionlabel) rproxyr- sslcacert force_httpcached_version login_infogpgcheckr )3_read_channels_filerrisfilerrLEAPP_IN_PROGRESSup2date_clientr*ZinitUp2dateConfigrget_ssl_ca_certZ up2dateAuthZ getLoginInforr-r RhnServerExceptionr,errorCOMMUNICATION_ERROR RHN_DISABLEDNOT_REGISTERED_ERROR_write_channels_fileZ rhnChannelZgetChannelDetailsZCommunicationErrorZNoChannelsErrorNOT_SUBSCRIBED_ERRORCHANNELS_DISABLEDZNoSystemIdErrorNO_SYSTEM_ID_ERRORUSE_RHNREGISTERrinfoUPDATES_FROM_SPACEWALKdictrrreposgetrrrrr SpacewalkRepor5r addr!)r#Z networkingZenabled_channelsr1r2Z proxy_urlr4Zcached_channelsZ clnreg_triedeZ svrChannelschannelrHZ channel_idZ channel_dictZcached_channelr3rr$r%r&repor(r(r)r"Zs                 zSpacewalk.activate_channelscCs|jjs dS|jsdS|jddkr8|j}tjj|ytjj|jj dWn4t j k r}zt j dtt|WYdd}~XnXdS)z, Update system's profile after transaction. NZwriteChangesToLog)r-z%s %s %s)rr rr_make_package_deltar9ZrhnPackageInfoZlogDeltaPackagesZupdatePackageProfiler-r r;rr<r=PROFILE_NOT_SENT)r#deltarLr(r(r) transactions zSpacewalk.transactioncCsy.t|jd}|j}tj|}|SQRXWnXttfk rb}z|jtjkrRWYdd}~Xn&tj j k r}zWYdd}~XnXiS)Nr) openrreadjsonloadsFileNotFoundErrorIOErrorerrnoENOENTdecoderZJSONDecodeError)r# channels_fileZcontentZchannelsrLr(r(r)r6s  zSpacewalk._read_channels_filecCsfy,t|jd}tj||ddWdQRXWn4ttfk r`}z|jtjkrPWYdd}~XnXdS)Nw)indent)rUrrWdumprYrZr[r\)r#varr^rLr(r(r)r@s  zSpacewalk._write_channels_filecCs.dd|jjjDdd|jjjDd}|S)NcSs$g|]}|j|j|j|j|jfqSr()namer.releaseepocharch).0pr(r(r) sz1Spacewalk._make_package_delta..cSs$g|]}|j|j|j|j|jfqSr()rdr.rerfrg)rhrir(r(r)rjs)ZaddedZremoved)rrSZ install_setZ remove_set)r#rRr(r(r)rPs  zSpacewalk._make_package_delta)T) __name__ __module__ __qualname__rdr r*r,r"rSr6r@rP __classcell__r(r()r'r)r 7s  Yr csDeZdZdZdddddgZfddZd d Zdfd d ZZS)rJzB Repository object for Spacewalk. Uses up2date libraries. zX-RHN-Server-IdzX-RHN-Auth-User-Idz X-RHN-AuthzX-RHN-Auth-Server-TimezX-RHN-Auth-Expire-OffsetcsTttjt|d|jdt|d_fdd|dD_|jd_|jd_yt |d _ Wn<t k r}z t j ttjj|g_ WYdd}~XnX|d |jd krd _|jd _d_d_d _d_|jd_|jd_|jd_|jdr$jnjtdrPj}|rPj|dS)Nr/rrdcsg|]}|djqS)z /GET-REQ/)id)rhurl)r#r(r)rjsz*SpacewalkRepo.__init__..rpr1r0Z gpg_key_urlr.r3rOr4rr-r5r2r set_http_headers) r rJr rrIrdZbaseurlr1r0get_gpg_key_urlsZgpgkeyInvalidGpgKeyLocationrrGPG_KEY_REJECTEDrZi18nZucdZmetadata_expirer4Z keepaliveZ bandwidthZretriesZthrottler-r5r2enabledisablehasattrcreate_http_headersrq)r#rMZoptsrL http_headers)r')r#r)r s8          zSpacewalkRepo.__init__cCsg}|js|Sxb|jD]X}||jkr8t|}tjj||j|dkrV|jd|q|jd||j|fqW|js|jd|S)Nz*%s: X-libcurl-Empty-Header-Workaround: *z%s: %sz.X-RHN-Transport-Capability: follow-redirects=3)Nrz)r4needed_headersMISSING_HEADERrErrorZ RepoErrorappendr2)r#ryheaderr<r(r(r)rxs    z!SpacewalkRepo.create_http_headersTcs0tt|j||}|j}|r,|jtj||S)N)r rJ_handle_new_remoterxZsetoptlibrepoZLRO_HTTPHEADER)r#ZdestdirZ mirror_setupZhandlery)r'r(r)r&s z SpacewalkRepo._handle_new_remote)T) rkrlrm__doc__r{r rxrrnr(r()r'r)rJs %rJcCs*|j}x|D]}t|st|qW|S)a Parse the key urls and validate them. key_url_string is a space seperated list of gpg key urls that must be located in /etc/pkg/rpm-gpg/. Return a list of strings containing the key urls. Raises InvalidGpgKeyLocation if any of the key urls are invalid. )splitis_valid_gpg_key_urlrs)Zkey_url_stringZkey_urlskey_urlr(r(r)rr2s   rrc@s eZdZdS)rsN)rkrlrmr(r(r(r)rsAsrscCsP|jd}t|dkrdS|\}}|jdkr2dStjj|}|jdsLdSdS)Nz://Ffilez/etc/pki/rpm-gpg/T)rlenlowerrrnormpath startswith)rZ proto_splitprotorr(r(r)rDs     rcCs4d|ko|dst|d}t|tkr0|dS|S)NZ sslCACertr)ZBadSslCaCertConfigtypelist)rZca_certsr(r(r)r:Rs  r:)/Z __future__rrZdnfpluginscorerrrZdnf.exceptionsr[rWrrrZdnf.conf.configrZup2date_client.up2dateAuthr9Zup2date_client.configZup2date_client.rhnChannelZup2date_client.rhnPackageInfoZrhn.i18nrr rr>rBr=r?rArCrDrFrtrQr|r8rZPluginr rNZReporJrr Exceptionrsrr:r(r(r(r)sJ      -O