
    Vh                          d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlZdZ	 d dlZdZd dlmZmZ d d	lmZ  ej,                  d
       ddZd Zedk(  r e        yy# e$ r  e
j                          ZdZY Ow xY w)    )absolute_importdivisionprint_functiona  
module: hpilo_info
author: Dag Wieers (@dagwieers)
short_description: Gather information through an HP iLO interface
description:
  - This module gathers information on a specific system using its HP iLO interface. These information includes hardware and
    network related information useful for provisioning (for example macaddress, uuid).
  - This module requires the C(hpilo) python module.
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.info_module
options:
  host:
    description:
      - The HP iLO hostname/address that is linked to the physical system.
    type: str
    required: true
  login:
    description:
      - The login name to authenticate to the HP iLO interface.
    type: str
    default: Administrator
  password:
    description:
      - The password to authenticate to the HP iLO interface.
    type: str
    default: admin
  ssl_version:
    description:
      - Change the ssl_version used.
    default: TLSv1
    type: str
    choices: ["SSLv3", "SSLv23", "TLSv1", "TLSv1_1", "TLSv1_2"]
requirements:
  - hpilo
notes:
  - This module ought to be run from a system that can access the HP iLO interface directly, either by using C(local_action)
    or using C(delegate_to).
a  
- name: Gather facts from a HP iLO interface only if the system is an HP server
  community.general.hpilo_info:
    host: YOUR_ILO_ADDRESS
    login: YOUR_ILO_LOGIN
    password: YOUR_ILO_PASSWORD
  when: cmdb_hwmodel.startswith('HP ')
  delegate_to: localhost
  register: results

- ansible.builtin.fail:
    msg: 'CMDB serial ({{ cmdb_serialno }}) does not match hardware serial ({{ results.hw_system_serial }}) !'
  when: cmdb_serialno != results.hw_system_serial
a  
# Typical output of HP iLO_info for a physical system
hw_bios_date:
  description: BIOS date.
  returned: always
  type: str
  sample: 05/05/2011

hw_bios_version:
  description: BIOS version.
  returned: always
  type: str
  sample: P68

hw_ethX:
  description: Interface information (for each interface).
  returned: always
  type: dict
  sample:
    - macaddress: 00:11:22:33:44:55
      macaddress_dash: 00-11-22-33-44-55

hw_eth_ilo:
  description: Interface information (for the iLO network interface).
  returned: always
  type: dict
  sample:
    - macaddress: 00:11:22:33:44:BA
    - macaddress_dash: 00-11-22-33-44-BA

hw_product_name:
  description: Product name.
  returned: always
  type: str
  sample: ProLiant DL360 G7

hw_product_uuid:
  description: Product UUID.
  returned: always
  type: str
  sample: ef50bac8-2845-40ff-81d9-675315501dac

hw_system_serial:
  description: System serial number.
  returned: always
  type: str
  sample: ABC12345D6

hw_uuid:
  description: Hardware UUID.
  returned: always
  type: str
  sample: 123456ABC78901D2

host_power_status:
  description:
    - Power status of host.
    - Will be one of V(ON), V(OFF) and V(UNKNOWN).
  returned: always
  type: str
  sample: "ON"
  version_added: 3.5.0
NTF)AnsibleModulemissing_required_lib)	to_nativeignorec                     	 dt        t        | d         dz
        z   }| d   j                  dd      | d   d}||fS # t        $ r |}Y ,w xY w)Nhw_ethPort   MAC-:
macaddressmacaddress_dash)strint	Exceptionreplace)entrynon_numericinfonameinfos       p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/hpilo_info.pyparse_flat_interfacer      sk    c#eFm"4q"899
 El**34 <D d  s   > AAc                  P   t        t        t        dd      t        dd      t        ddd      t        ddg d	
            d      } t        s | j                  t	        d      t
               | j                  d   }| j                  d   }| j                  d   }t        t        j                  d| j                  j                  d      j                         j                  dd      z         }t        j                  ||||      }ddi}	 |j                         }|j                         }D ]  }
d|
vr	|
d   dk(  r|
d   |d<   |
d   |d<   "|
d   dk(  r/|
d    |d!<   |
d"   j%                         |d#<   |
d$   |d%<   |
d&   |d'<   Y|
d   d(k(  rd)|
v r{|
d)   D 	cg c]  }	|	d*   |	d+   f c}	D ]\  \  }}|j'                  d,      r	 d-t)        t+        |      dz
        z   }3|j'                  d/      sE|j                  d0d1      |d2|<   ^ t/        |
d.      \  }}|||<   |
d   d(k(  r||
d)   D 	cg c]  }	|	d*   |	d+   f c}	D ]\  \  }}|j'                  d,      r	 d3t)        t+        |      dz
        z   }3|j'                  d/      sE|j                  d0d1      |d2|<   ^ y|
d   d5k(  st/        |
d.      \  }}|||<    |j1                         }||d6<   |j                  d7i       j                  d8      }|r||d9<   d|d:<   |j3                         D ]j  \  }}|j                  d;      }|st5        j6                  d<|      }|s3|j9                  d=      d>k(  sH|d:   t+        |j9                  d            z   |d:<   l d?j;                  |d:         |d:<   xs d@|dA<    | j<                  dBi | y # t        j                   $ r&}	| j                  t#        |	             Y d }	~	d }	~	ww xY wc c}	w # t,        $ r d.}Y [w xY wc c}	w # t,        $ r d4}Y w xY w)CNr   T)typerequiredAdministrator)r   defaultadmin)r   r"   no_logTLSv1)SSLv3SSLv23r%   TLSv1_1TLSv1_2)r   r"   choices)hostloginpasswordssl_version)argument_specsupports_check_modezpython-hpilo)msg	exceptionr+   r,   r-   	PROTOCOL_r.   Vv)r,   r-   r.   	module_hw)r1   r   r   Familyhw_bios_versionDatehw_bios_dater   UUIDhw_uuidzSerial Numberhw_system_serialzProduct Namehw_product_namecUUIDhw_product_uuid   fieldsnamevaluer   r   
hw_eth_ilor   r   r   r   hw_iscsihw_iscsi_ilo   	hw_healthmemorymemory_details_summaryhw_memory_details_summaryhw_memory_totaltotal_memory_sizez(\d+)\s+(\w+)   GBz{0} GBUNKNOWNhost_power_status )r   dict	HAS_HPILO	fail_jsonr   HPILO_IMP_ERRparamsgetattrhpilosslgetupperr   Iloget_host_dataget_host_power_statusIloCommunicationErrorr   rstrip
startswithr   r   r   r   get_embedded_healthitemsresearchgroupformat	exit_json)moduler+   r,   r-   r.   ilor   datapower_stateer   rC   rD   r   
entry_infohealthrK   cpudetailscpu_total_memory_sizerams                        r   mainrv      s   540E?;ugdC%Btu	
 !F 1.A][== DMM'"E}}Z(H%))[6==3D3D]3S3Y3Y3[3c3cdgil3m%mnK
))Dk
RC 	TD
+  "//1  )(6]a&+HoD"##(=D 6]a#FmDO',_'='D'D'FD#$&+N&;D"#&+GnD"#6]c!5 GLX%W!qy!G*&=%W 
MT5v.4'/#c%j1n2E'EH /*/--S*A/4*X
 *>e\)R&:!+X6]c!CH?!Sa1V9aj"9!S 
u??6*2#-CJN0C#C __U+&+mmC&=+0&DN
 6]c!%9%%N"Xz'DNS)(X $$&FD#ZZ"599:RS,B()"#288: 	^LC$+KK0C$D!$ii 02GHyy|t+267H2ICPSPYPYZ[P\L]2]./	^ #+//$7H2I"J !, 8yD	FtK && +Yq\**+  &X  ) 4'3H4 "T % 2#12sH    N> O:
O?6P"P>O7O22O7?PPP%$P%__main__)rE   )
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNrf   	tracebackwarningsrW   rZ   rU   ImportError
format_excansible.module_utils.basicr   r   +ansible.module_utils.common.text.convertersr   simplefilterr   rv   __name__rS       r   <module>r      s    A @&P>
@ 
  I
 K A   h 
cL zF   (I((*MIs   A A87A8