
    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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 Vw xY w)    )absolute_importdivisionprint_functiona  
author:
  - Naval Patel (@navalkp)
  - Prashant Bhosale (@prabhosa)
module: lxca_cmms
short_description: Custom module for lxca cmms inventory utility
description:
  - This module returns/displays a inventory details of cmms.
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: cmms
    choices:
      - cmms
      - cmms_by_uuid
      - cmms_by_chassis_uuid
    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 cmms info
- name: Get nodes data from LXCA
  community.general.lxca_cmms:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"

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

# get specific cmms info by chassis uuid
- name: Get nodes data from LXCA
  community.general.lxca_cmms:
    login_user: USERID
    login_password: Password
    auth_url: "https://10.243.15.168"
    chassis: "3C737AA5E31640CE949B10C129A8B01F"
    command_options: cmms_by_chassis_uuid
a  
result:
  description: Cmms detail from lxca.
  returned: success
  type: dict
  sample:
    cmmList:
      - machineType: ''
        model: ''
        type: 'CMM'
        uuid: '118D2C88C8FD11E4947B6EAE8B4BDCDF'
          # bunch of properties
      - machineType: ''
        model: ''
        type: 'CMM'
        uuid: '223D2C88C8FD11E4947B6EAE8B4BDCDF'
          # bunch of properties
        # Multiple cmms details
N)AnsibleModule)LXCA_COMMON_ARGS
has_pylxcaconnection_objectcmmsz4UUID of device is required for cmms_by_uuid command.z=UUID of chassis is required for cmms_by_chassis_uuid command.zSuccess %s resultc                     t        |      S Nr
   modulelxca_cons     o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/lxca_cmms.py_cmmsr   m   s    >    c                 ~    | j                   d   s| j                  t               t        || j                   d         S )Nuuidmsg)params	fail_jsonUUID_REQUIREDr   r   s     r   _cmms_by_uuidr   q   s5    == ]+&--/00r   c                     | j                   d   s| j                  t               t        || j                   d         S )Nchassisr   )r   )r   r   CHASSIS_UUID_REQUIREDr   r   s     r   _cmms_by_chassis_uuidr   w   s6    ==#23&--	":;;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   cmms_by_uuidcmms_by_chassis_uuidr   )defaultchoices)r*   )command_optionsr   r   c                    	 t        |       5 }t        | j                  d      | |      }| j                  dt        | j                  d   z  |       ddd       y# 1 sw Y   yxY w# t
        $ rQ}dj                  d |j                  D              }| j                  |t        j                                Y d}~yd}~ww xY w)zP
    This function invoke commands
    :param module: Ansible module object
    r,   F)changedr   resultNz; c              3       K   | ]  }|  y wr    ).0es     r   	<genexpr>z!execute_module.<locals>.<genexpr>   s     :aq:s   )r   	exception)r	   	FUNC_DICTr   	exit_jsonSUCCESS_MSG	Exceptionjoinargsr   	traceback
format_exc)r   r   r/   r5   	error_msgs        r   execute_moduler?      s    
Jv& 	,(v}}->?@RFU!,v}}=N/O!O$*  ,	, 	, 	,
  JII:9>>::	Y)2F2F2HIIJs6   A' AAA' A$ A' $A' '	C0AB<<Cc                  D    t               } t        |        t        |        y r   )r'   r   r?   )r   s    r   mainrA      s     "Fv6r   __main__) 
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNr<   ansible.module_utils.basicr   Xansible_collections.community.general.plugins.module_utils.remote_management.lxca.commonr   r   r	   pylxcar   ImportErrorr   r   r8   r   r   r   r'   r6   r#   r%   r?   rA   __name__r1   r   r   <module>rN      s    C B#J6
(  4 U  U	
 GW !1<	 !1	  2J K	d		J  zF U  		s   A= =BB