"v:ddlmZddlmZmZddlmZmZddlm Z m Z ddl m Z ddl mZddlmZddlmZGd d eZd S) )uuid4)change_settingsload)config lveinfolib)history history_x60) history_gov)incident)servers)usercNeZdZdZdZdZddZdZdZdZ d Z dd Z d Z d Z dS)UpdateOrCreateServerIDzeChange old-style server ID 'localhost' to auto-generated uuid User can set his own server ID ) localhost Nc:||_|p tj|_dS)zi :type engine: sqlalchemy.engine.base.Engine :type config_path: Union[str, None] N)enginerGLOBAL_CONFIG_LOCATION config_path)selfrrs /builddir/build/BUILDROOT/lve-stats-4.3.2-1.el9.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/server_id.py__init__zUpdateOrCreateServerID.__init__s!  &G&*Gc t|j}|dS#t$r}t d|Yd}~dSd}~wwxYw)* :rtype: Union[None, str] )path server_idError: N)rrget Exceptionprint)rcfges r_get_current_server_id_cfgz1UpdateOrCreateServerID._get_current_server_id_cfg"sl D,---C77;'' '    -A-- 44444 s), AAAc td|i|j|S#t$r}td|Yd}~dSd}~wwxYw)zmSets option 'server_id' in config file :type server_id: str :rtype: Union[None, str] rrN)rrr r!)rrr#s r_set_server_id_cfgz)UpdateOrCreateServerID._set_server_id_cfg-se   [)4d6F G G G     -A-- 44444 s A=Ac|j|j|k}||d|idS)a updates server_id in one of the tables :type conn: sqlalchemy.engine.base.Connection :type table: Union[history, history_gov, incident, user, history_x60] :type current_server_id: str :type new_server_id: str rN) __table__updatewhererexecutevalues)rconntablecurrent_server_id new_server_id sql_updates r_update_server_id_tablez.UpdateOrCreateServerID._update_server_id_table9sn_++--33 O0 0   Z&& - (       rc6tttttg}t j|j|}|j}| } |D]}| ||||| tj ||d| tj tj|k|||S#t*$rE}||t/d|Yd}~dSd}~wwxYw)z updates server_id for all tables in the database :type current_server_id: str :type new_server_id: str :rtype: Union[None, str] )r lve_versionrN)rr r r r rget_lve_versionrconnectbeginr2r+r r(insertr,deleter*rcommitcloser rollbackr!) rr/r0 sql_tablesr4r-txr.r#s r_update_server_id_dbz+UpdateOrCreateServerID._update_server_id_dbHsy{HdKH  0>OPP {""$$ ZZ\\ !# \ \,,T5:K][[[[ LL*1133::+KHH    LL*113399':KO`:`aa b b b IIKKK JJLLL     KKMMM JJLLL -A-- 44444  s)B6E F:FFTc(ttd|j}|rtd|d}t ||r|}||jvrt d|ddS||krt d|d|St|dkrt ddS|}| |s ||jvr|S| |p|pd |r| |S|S) zw :type current_server_id: Union[None, str] :type prompt: bool :rtype: Union[None, str] NzEnter new server ID ['z']: Server ID cannot be ''zServer ID is already set to 'z(Server ID length should be less than 255r) strrserver_id_lengthinputr!striprestricted_server_id_listlenr$r?r&)rpromptr/rres cur_server_ids r_resolve_localhostz)UpdateOrCreateServerID._resolve_localhostfsN LL!7$"7!78  @@@@AAC #JJJ (IIKK D::::i:::;;;t---BiBBBCCC  9~~##@AAAt7799  $V $T%CCC  $ $%6%V-%V;Xa b b 6**955 5rc|}t|tr.||jvrt d|d||S)rrArB)r/)r$ isinstancerDrGrHr!rM)rcur_cfg_server_ids rrJzUpdateOrCreateServerID.promptsw!;;== ' - - @!''))T-KKK >*;>>> ? ? ?&&9J&KKKrc.|dS)rF)rJ)rM)rs rautozUpdateOrCreateServerID.autos&&e&444r)N)TN)__name__ __module__ __qualname____doc__rHrErr$r&r2r?rMrJrRrrrrs!/HHHH          !!!<: L L L55555rrN)uuidrclcommon.clconfparsrr lvestats.librrlvestats.orm.historyrr lvestats.orm.history_govr lvestats.orm.incidentr lvestats.orm.serversr lvestats.orm.userr objectrrWrrras55555555++++++++55555555000000******((((((""""""@5@5@5@5@5V@5@5@5@5@5r