
    f              
           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ed<   dZ dZdZdZ ej,                  e      ZdZdede	dededdf
dZd Zd Zd Zd Z d Z!y)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.
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                    |j                   j                  dk(  rt        j                  d       y t        j
                  j                  t              st        j                  d       y t        j                  j                  d      }	 t        |       t                |r|t        j                  d<   y t        j                  d= y # |r|t        j                  d<   w t        j                  d= w xY 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_paths        ?/usr/lib/python3/dist-packages/cloudinit/config/cc_reset_rmc.pyhandler,   A   s    %%/		<=77==#		:;

v&I#!*BJJv

6" !*BJJv

6"s   	C )C/c                      	 t        j                   t        g      d   } t        j                  | j	                                | S # t         j
                  $ r t        j                  t        d        w xY w)Nr   z*Failed to reconfigure the RSCT subsystems.)r   RECFGCTr    r!   stripProcessExecutionErrorr   logexc)outs    r+   reconfigure_rsct_subsystemsr3   V   sZ    ii	"1%		#))+
%% CEFs   AA /A3c                      	 t        j                  t              } | j                  d      d   }|S # t        $ r# t        j
                  t        dt        z          w xY w)N
r   z#Failed to get node ID from file %s.)r   load_text_fileNODE_ID_FILEsplit	Exceptionr1   r    )fpnode_ids     r+   get_node_idr<   c   sT      .((4.# C>MNs	   .1 ,Ac                 n    | rd| z   nd}t         |z   t        j                  d<   t        j                  d   S )N:r   r   )r%   r"   r&   )r*   suffs     r+   r(   r(   m   s3     (3?RD"T)BJJv::f    c                      	 t        j                   t        dg      S # t        $ r t        j                  t
        d        w xY w)Nz-zz!Failed to stop the RMC subsystem.)r   RMCCTRLr9   r   r1   r     r@   r+   r   r   v   s;    yy'4)) C<=s	    %Ac                  $   t         j                  d       t               } t         j                  d|        t                t	                t               }t         j                  d|       || k(  r"d}t         j                  |       t        |      y )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   r3   errorRuntimeError)node_id_beforenode_id_aftermsgs      r+   r)   r)      sr    II() ]NII2NC I!MMII,m< &2		#3 'r@   )"__doc__loggingr"   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   cloudinit.settingsr	   MODULE_DESCRIPTIONr   __annotations__r%   rB   r.   	getLogger__name__r    r7   strlistr,   r3   r<   r(   r   r)   rC   r@   r+   <module>rX      s    $  	   ! # . ) + , !%}!	j 	  $	

g! # #6 #% #t # #*
 r@   