
    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
mZ d dlmZmZmZ 	 d dlmZ d	Zd
ZdZd Zd Zd Zd Zd Zd ZeeeeedZ e edg d       ed       ed            Zd Zd Z e!dk(  r e         yy# e$ r Y ^w xY w)    )absolute_importdivisionprint_functiona`  
author:
  - Naval Patel (@navalkp)
  - Prashant Bhosale (@prabhosa)
module: lxca_nodes
short_description: Custom module for lxca nodes inventory utility
description:
  - This module returns/displays a inventory details of nodes.
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none

options:
  uuid:
    description: UUID of device, this is string with length greater than 16.
    type: str

  command_options:
    description: Options to filter nodes information.
    default: nodes
    choices:
      - nodes
      - nodes_by_uuid
      - nodes_by_chassis_uuid
      - nodes_status_managed
      - nodes_status_unmanaged
    type: str

  chassis:
    description: UUID of chassis, this is string with length greater than 16.
    type: str

extends_documentation_fragment:
  - community.general.lxca_common
  - community.general.attributes
a  
# get all nodes info
- name: Get nodes data from LXCA
  community.general.lxca_nodes:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"
    command_options: nodes

# get specific nodes info by uuid
- name: Get nodes data from LXCA
  community.general.lxca_nodes:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"
    uuid: "3C737AA5E31640CE949B10C129A8B01F"
    command_options: nodes_by_uuid

# get specific nodes info by chassis uuid
- name: Get nodes data from LXCA
  community.general.lxca_nodes:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"
    chassis: "3C737AA5E31640CE949B10C129A8B01F"
    command_options: nodes_by_chassis_uuid

# get managed nodes
- name: Get nodes data from LXCA
  community.general.lxca_nodes:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"
    command_options: nodes_status_managed

# get unmanaged nodes
- name: Get nodes data from LXCA
  community.general.lxca_nodes:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"
    command_options: nodes_status_unmanaged
a  
result:
  description: Nodes detail from lxca.
  returned: always
  type: dict
  sample:
    nodeList:
      - machineType: '6241'
        model: 'AC1'
        type: 'Rack-TowerServer'
        uuid: '118D2C88C8FD11E4947B6EAE8B4BDCDF'
          # bunch of properties
      - machineType: '8871'
        model: 'AC1'
        type: 'Rack-TowerServer'
        uuid: '223D2C88C8FD11E4947B6EAE8B4BDCDF'
          # bunch of properties
        # Multiple nodes details
N)AnsibleModule)LXCA_COMMON_ARGS
has_pylxcaconnection_objectnodesz5UUID of device is required for nodes_by_uuid command.z>UUID of chassis is required for nodes_by_chassis_uuid command.zSuccess %s resultc                     t        |      S Nr
   modulelxca_cons     p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/lxca_nodes.py_nodesr      s    ?    c                 ~    | j                   d   s| j                  t               t        || j                   d         S )Nuuidmsg)params	fail_jsonUUID_REQUIREDr   r   s     r   _nodes_by_uuidr      s5    == ]+6==011r   c                     | j                   d   s| j                  t               t        || j                   d         S )Nchassisr   )r   )r   r   CHASSIS_UUID_REQUIREDr   r   s     r   _nodes_by_chassis_uuidr      s6    ==#236==#;<<r   c                     t        |d      S )Nmanagedstatusr
   r   s     r   _nodes_status_managedr$      s    ),,r   c                     t        |d      S )N	unmanagedr"   r
   r   s     r   _nodes_status_unmanagedr'      s    +..r   c                  h    t        t              } | j                  t               t	        | d      }|S )zY
    this function merge argument spec and create ansible module object
    :return:
    F)argument_specsupports_check_mode)dictr   updateINPUT_ARG_SPECr   )	args_specr   s     r   setup_module_objectr/      s.    
 %&I^$NFMr   )r   nodes_by_uuidnodes_by_chassis_uuidnodes_status_managednodes_status_unmanagedr   )defaultchoices)r4   )command_optionsr   r   c                 z   	 t        |       5 }t        | j                  d      | |      }| j                  dt        | j                  d   z  |       ddd       y# 1 sw Y   yxY w# t
        $ rJ}dj                  |j                        }| j                  |t        j                                Y d}~yd}~ww xY w)zP
    This function invoke commands
    :param module: Ansible module object
    r6   F)changedr   resultNz; )r   	exception)r	   	FUNC_DICTr   	exit_jsonSUCCESS_MSG	Exceptionjoinargsr   	traceback
format_exc)r   r   r9   r:   	error_msgs        r   execute_modulerD      s    
Jv& 	,(v}}->?@RFU!,v}}=N/O!O$*  ,	, 	, 	,
  JIIinn-	Y)2F2F2HIIJs6   A' AAA' A$ A' $A' '	B:0A B55B:c                  D    t               } t        |        t        |        y r   )r/   r   rD   )r   s    r   mainrF      s     "Fv6r   __main__)"
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNrA   ansible.module_utils.basicr   Xansible_collections.community.general.plugins.module_utils.remote_management.lxca.commonr   r   r	   pylxcar   ImportErrorr   r   r=   r   r   r   r$   r'   r/   r;   r+   r-   rD   rF   __name__ r   r   <module>rT      s    C B%N*X
(  4 U  U	
 HX !2=-/	 #315	  3M N 
d	T$%7J  zF k  		s   B BB