o
    wÚ7e÷  ã                
   @   sò   U d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ d
Zdddeegeg g dœZeed< dZ dZdZdZe e¡ZdZdede
dededdf
dd„Zdd„ Zdd„ Zd d!„ Z d"d„ Z!d#d$„ Z"dS )%zReset RMC: Reset rsct node idé    N)Úlog)ÚsubpÚutil)ÚCloud)ÚConfig)Ú
MetaSchema)ÚALL_DISTROS)ÚPER_INSTANCEa|  Reset RMC module is IBM PowerVM Hypervisor specific

Reliable Scalable Cluster Technology (RSCT) is a set of software components,
that  together provide a comprehensive clustering environment (RAS features)
for IBM PowerVM based virtual machines. RSCT includes the Resource monitoring
and control (RMC) subsystem. RMC is a generalized framework used for managing,
monitoring, and manipulating resources. RMC runs as a daemon process on
individual machines and needs creation of unique node id and restarts
during VM boot.
More details refer
https://www.ibm.com/support/knowledgecenter/en/SGVKBA_3.2/admin/bl503_ovrv.htm

This module handles
- creation of the unique RSCT node id to every instance/virtual machine
  and ensure once set, it isn't changed subsequently by cloud-init.
  In order to do so, it restarts RSCT service.

Prerequisite of using this module is to install RSCT packages.
Úcc_reset_rmcz	Reset RMCzreset rsct node id)ÚidÚnameÚtitleÚdescriptionÚdistrosÚ	frequencyÚexamplesÚactivate_by_schema_keysÚmetaÚ z/opt/rsct/install/binÚrmcctrlÚrecfgctz/etc/ct_node_idr   ÚcfgÚcloudÚargsÚreturnc              	   C   sŠ   |j jdkrt d¡ d S tj t¡st d¡ d S tj 	d¡}zt
|ƒ tƒ  W |r2|tjd< d S tjd= d S |r@|tjd< w tjd= w )NÚnonez(Skipping creation of new ct_node_id nodez&module disabled, RSCT_PATH not presentÚPATH)Ú
datasourceÚplatform_typeÚLOGÚdebugÚosÚpathÚisdirÚ	RSCT_PATHÚenvironÚgetÚadd_pathÚ	reset_rmc)r   r   r   r   Ú	orig_path© r*   ú?/usr/lib/python3/dist-packages/cloudinit/config/cc_reset_rmc.pyÚhandleC   s    

ý
r,   c                  C   sD   zt   tg¡d } t |  ¡ ¡ | W S  t jy!   t td¡ ‚ w )Nr   z*Failed to reconfigure the RSCT subsystems.)r   ÚRECFGCTr   r    ÚstripÚProcessExecutionErrorr   Úlogexc)Úoutr*   r*   r+   Úreconfigure_rsct_subsystemsX   s   þr2   c                  C   s@   zt  t¡} |  d¡d }|W S  ty   t  tdt ¡ ‚ w )NÚ
r   z#Failed to get node ID from file %s.)r   Ú	load_fileÚNODE_ID_FILEÚsplitÚ	Exceptionr0   r   )ÚfpÚnode_idr*   r*   r+   Úget_node_ide   s   
þr:   c                 C   s(   | rd|  nd}t | tjd< tjd S )Nú:r   r   )r$   r!   r%   )r)   Úsuffr*   r*   r+   r'   o   s   
r'   c                   C   s.   zt   tdg¡W S  ty   t td¡ ‚ w )Nz-zz!Failed to stop the RMC subsystem.)r   ÚRMCCTRLr7   r   r0   r   r*   r*   r*   r+   r   x   s   þc                  C   s\   t  d¡ tƒ } t  d| ¡ tƒ  tƒ  tƒ }t  d|¡ || kr,d}t  |¡ t|ƒ‚d S )NzAttempting to reset RMC.z"Node ID at beginning of module: %szNode ID at end of module: %sz"New node ID did not get generated.)r   r    r:   r   r2   ÚerrorÚRuntimeError)Únode_id_beforeÚnode_id_afterÚmsgr*   r*   r+   r(   ‚   s   

ýr(   )#Ú__doc__r!   Ú	cloudinitr   Úloggingr   r   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   Úcloudinit.distrosr   Úcloudinit.settingsr	   ÚMODULE_DESCRIPTIONr   Ú__annotations__r$   r=   r-   Ú	getLoggerÚ__name__r   r5   ÚstrÚlistr,   r2   r:   r'   r   r(   r*   r*   r*   r+   Ú<module>   s>   ø

	
