
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me              	   @   s   U d Z ddlZddl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dZ dZdZdZejeZdZee	eedd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)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.
Zcc_reset_rmcz	Reset RMCzreset rsct node id)idnametitledescriptionZdistrosZ	frequencyZexamplesZactivate_by_schema_keys z/opt/rsct/install/binrmcctrlZrecfgctz/etc/ct_node_id)r
   cfgcloudargsreturnc             C   sr   |j jdkrtjd d S tjjts4tjd d S tjj	d}zt
| t  W d |rd|tjd< ntjd= X d S )NZnonez(Skipping creation of new ct_node_id nodez&module disabled, RSCT_PATH not presentPATH)Z
datasourceZ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.6/cc_reset_rmc.pyhandleA   s    


r!   c              C   sL   y"t j tgd } tj| j  | S  t jk
rF   tjtd  Y nX d S )Nr   z*Failed to reconfigure the RSCT subsystems.)r   RECFGCTr   r   stripZProcessExecutionErrorr   logexc)outr   r   r    reconfigure_rsct_subsystemsV   s    r&   c              C   sH   yt jt} | jdd }|S  tk
rB   t jtdt   Y nX d S )N
r   z#Failed to get node ID from file %s.)r   Z	load_fileNODE_ID_FILEsplit	Exceptionr$   r   )fpZnode_idr   r   r    get_node_idc   s    
r,   c             C   s(   | rd|  nd}t | tjd< tjd S )N:r   r   )r   r   r   )r   Zsuffr   r   r    r   m   s    r   c               C   s6   yt j tdgS  tk
r0   tjtd  Y nX d S )Nz-zz!Failed to stop the RMC subsystem.)r   RMCCTRLr*   r   r$   r   r   r   r   r    r   v   s
    c              C   s\   t jd t } t jd|  t  t  t }t jd| || krXd}t j| 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   r&   errorRuntimeError)Znode_id_beforeZnode_id_aftermsgr   r   r    r      s    

r   )!__doc__Zloggingr   Z	cloudinitr   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   Zcloudinit.distrosr   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONmetar   r.   r"   Z	getLogger__name__r   r(   strlistr!   r&   r,   r   r   r   r   r   r   r    <module>   s:   

	
