
    Vhy                        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 dlmZ d dlm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mZ d dlmZmZ 	 d dl m!Z! d dl"m#Z# dZ$dddddddZ&dddZ'ddddZ(dZ)d Z*d!Z+d"Z,d#Z-d$Z.d%Z/d&Z0d'Z1d(Z2d)Z3d*Z4d+Z5d,Z6d-Z7d<d.Z8d/ Z9d0 Z:d1 Z;d2 Z<d3 Z=d4 Z>d5 Z?d6 Z@d7 ZAd8 ZBd9 ZCd: ZDeEd;k(  r eD        yy# e%$ r dZ$Y qw xY w)=    )absolute_importdivisionprint_functiona  
---
module: idrac_firmware
short_description: Firmware update from a repository on a network share (CIFS, NFS, HTTP, HTTPS, FTP)
version_added: "2.1.0"
description:
    - Update the Firmware by connecting to a network share (CIFS, NFS, HTTP, HTTPS, FTP) that contains a catalog of
        available updates.
    - Network share should contain a valid repository of Update Packages (DUPs) and a catalog file describing the DUPs.
    - All applicable updates contained in the repository are applied to the system.
    - This feature is available only with iDRAC Enterprise License.
extends_documentation_fragment:
  - dellemc.openmanage.idrac_auth_options
options:
    share_name:
        description: Network share path of update repository. CIFS, NFS, HTTP, HTTPS and FTP share types are supported.
        type: str
        required: true
    share_user:
        description: Network share user in the format 'user@domain' or 'domain\\user' if user is
            part of a domain else 'user'. This option is mandatory for CIFS Network Share.
        type: str
    share_password:
        description: Network share user password. This option is mandatory for CIFS Network Share.
        type: str
        aliases: ['share_pwd']
    share_mnt:
        description:
          - Local mount path of the network share with read-write permission for ansible user.
          - This option is not applicable for HTTP, HTTPS, and FTP shares.
        type: str
    job_wait:
        description: Whether to wait for job completion or not.
        type: bool
        default: true
    catalog_file_name:
        description: Catalog file name relative to the I(share_name).
        type: str
        default: 'Catalog.xml'
    ignore_cert_warning:
        description: Specifies if certificate warnings are ignored when HTTPS share is used.
            If C(true) option is set, then the certificate warnings are ignored.
        type: bool
        default: true
    apply_update:
        description:
          - If I(apply_update) is set to C(true), then the packages are applied.
          - If I(apply_update) is set to C(false), no updates are applied, and a catalog report
            of packages is generated and returned.
        type: bool
        default: true
    reboot:
        description:
          - Provides the option to apply the update packages immediately or in the next reboot.
          - If I(reboot) is set to C(true),  then the packages  are applied immediately.
          - If I(reboot) is set to C(false), then the packages are staged and applied in the next reboot.
          - Packages that do not require a reboot are applied immediately irrespective of I (reboot).
        type: bool
        default: false
    proxy_support:
        description:
          - Specifies if a proxy should be used.
          - Proxy parameters are applicable on C(HTTP), C(HTTPS), and C(FTP) share type of repositories.
          - C(ParametersProxy), sets the proxy parameters for the current firmware operation.
          - C(DefaultProxy), iDRAC uses the proxy values set by default.
          - Default Proxy can be set in the Lifecycle Controller attributes using M(dellemc.openmanage.idrac_attributes).
          - C(Off), will not use the proxy.
          - For iDRAC8 based servers, use proxy server with basic authentication.
          - "For iDRAC9 based servers, ensure that you use digest authentication for the proxy server,
          basic authentication is not supported."
        choices: ["ParametersProxy", "DefaultProxy", "Off"]
        type: str
        default: "Off"
    proxy_server:
        description:
          - The IP address of the proxy server.
          - "This IP will not be validated. The download job will be created even for invalid I(proxy_server).
          Please check the results of the job for error details."
          - This is required when I(proxy_support) is C(ParametersProxy).
        type: str
    proxy_port:
        description:
          - The Port for the proxy server.
          - This is required when I(proxy_support) is C(ParametersProxy).
        type: int
    proxy_type:
        description:
          - The proxy type of the proxy server.
          - This is required when I(proxy_support) is C(ParametersProxy).
          - "Note: SOCKS4 proxy does not support IPv6 address."
        choices: [HTTP, SOCKS]
        type: str
    proxy_uname:
        description: The user name for the proxy server.
        type: str
    proxy_passwd:
        description: The password for the proxy server.
        type: str

requirements:
    - "omsdk >= 1.2.503"
    - "python >= 3.9.6"
author:
    - "Rajeev Arakkal (@rajeevarakkal)"
    - "Felix Stephen (@felixs88)"
    - "Jagadeesh N V (@jagadeeshnv)"
notes:
    - Run this module from a system that has direct access to Dell iDRAC.
    - Module will report success based on the iDRAC firmware update parent job status if there are no individual
        component jobs present.
    - For server with iDRAC firmware 5.00.00.00 and later, if the repository contains unsupported packages, then the
        module will return success with a proper message.
    - This module supports both IPv4 and IPv6 address for I(idrac_ip) and I(share_name).
    - This module supports C(check_mode).
aa	  
---
- name: Update firmware from repository on a NFS Share
  dellemc.openmanage.idrac_firmware:
       idrac_ip: "192.168.0.1"
       idrac_user: "user_name"
       idrac_password: "user_password"
       ca_path: "/path/to/ca_cert.pem"
       share_name: "192.168.0.0:/share"
       reboot: true
       job_wait: true
       apply_update: true
       catalog_file_name: "Catalog.xml"

- name: Update firmware from repository on a CIFS Share
  dellemc.openmanage.idrac_firmware:
       idrac_ip: "192.168.0.1"
       idrac_user: "user_name"
       idrac_password: "user_password"
       ca_path: "/path/to/ca_cert.pem"
       share_name: "full_cifs_path"
       share_user: "share_user"
       share_password: "share_password"
       reboot: true
       job_wait: true
       apply_update: true
       catalog_file_name: "Catalog.xml"

- name: Update firmware from repository on a HTTP
  dellemc.openmanage.idrac_firmware:
       idrac_ip: "192.168.0.1"
       idrac_user: "user_name"
       idrac_password: "user_password"
       ca_path: "/path/to/ca_cert.pem"
       share_name: "http://downloads.dell.com"
       reboot: true
       job_wait: true
       apply_update: true

- name: Update firmware from repository on a HTTPS
  dellemc.openmanage.idrac_firmware:
       idrac_ip: "192.168.0.1"
       idrac_user: "user_name"
       idrac_password: "user_password"
       ca_path: "/path/to/ca_cert.pem"
       share_name: "https://downloads.dell.com"
       reboot: true
       job_wait: true
       apply_update: true

- name: Update firmware from repository on a HTTPS via proxy
  dellemc.openmanage.idrac_firmware:
       idrac_ip: "192.168.0.1"
       idrac_user: "user_name"
       idrac_password: "user_password"
       ca_path: "/path/to/ca_cert.pem"
       share_name: "https://downloads.dell.com"
       reboot: true
       job_wait: true
       apply_update: true
       proxy_support: ParametersProxy
       proxy_server: 192.168.1.10
       proxy_type: HTTP
       proxy_port: 80
       proxy_uname: "proxy_user"
       proxy_passwd: "proxy_pwd"

- name: Update firmware from repository on a FTP
  dellemc.openmanage.idrac_firmware:
       idrac_ip: "192.168.0.1"
       idrac_user: "user_name"
       idrac_password: "user_password"
       ca_path: "/path/to/ca_cert.pem"
       share_name: "ftp://ftp.mydomain.com"
       reboot: true
       job_wait: true
       apply_update: true
a  
---
msg:
  type: str
  description: Overall firmware update status.
  returned: always
  sample: "Successfully updated the firmware."
update_status:
  type: dict
  description: Firmware Update job and progress details from the iDRAC.
  returned: success
  sample: {
        'InstanceID': 'JID_XXXXXXXXXXXX',
        'JobState': 'Completed',
        'Message': 'Job completed successfully.',
        'MessageId': 'REDXXX',
        'Name': 'Repository Update',
        'JobStartTime': 'NA',
        'Status': 'Success',
    }
N)SSLError)ElementTree)iDRACConnectionidrac_auth_params)iDRACRedfishAPI)AnsibleModule)urlparse)ConnectionErrorSSLValidationError)URLError	HTTPError)UserCredentials)FileOnShareTFNFSCIFSFTPHTTPHTTPSTFTP)nfscifsftphttphttpstftpOnOffTFUse_Default_SettingsUse_Custom_Settings)DefaultProxyr    ParametersProxyzJ/redfish/v1/Dell/Systems/System.Embedded.1/DellSoftwareInstallationServicez/redfish/v1/Dell/Systems/System.Embedded.1/DellSoftwareInstallationService/Actions/DellSoftwareInstallationService.InstallFromRepositoryz/redfish/v1/Dell/Systems/System.Embedded.1/DellSoftwareInstallationService/Actions/DellSoftwareInstallationService.GetRepoBasedUpdateListz$/redfish/v1/JobService/Jobs/{job_id}z3/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/{job_id}z7/redfish/v1/Managers/iDRAC.Embedded.1/LogServices/Lclogz?/redfish/v1/Managers/iDRAC.Embedded.1/LogServices/Lclog/Entriesz0/redfish/v1/Managers/iDRAC.Embedded.1/Logs/Lclogz`Firmware versions on server match catalog, applicable updates are not present in the repository.z{The catalog in the repository specified in the operation has the same firmware versions as currently present on the server.SUP029z3.30      z$Job wait timed out after {0} minutesc                 8   d}i }d }|dk  r>	 t        | j                        5 }|j                  |d      }d d d        |dz  }d }|dk  r>|dk  rd }d}|r|t        k  r	 t        | j                        5 }|j                  |d      }|j                  j                  d      }
|j                  j                  d      }d d d        d }dk(  r3|j                  j                  d	      d   d
   }| j                  |       |j                  j                  d      dk(  r
dk(  rn3
dv r|s|rn*|dz  }t        j                  t               |r
|t        k  r|t        kD  r#t        j                  t        t        z  dz        }||fS # 1 sw Y   TxY w# t        $ r0}	t	        |	      }|dz  }t        j                  d       Y d }	~	d }	~	ww xY w# 1 sw Y   xY w# t        $ r3}	t	        |	      }|dz  }t        j                  t               Y d }	~	d }	~	ww xY w)Nr      GET   
   JobState	JobStatusCriticalMessagesMessagemsgPercentCompleted   	Completed)StartingRunningPendingNew   <   )r
   paramsinvoke_request	Exceptionstrtimesleep
WAIT_COUNT	json_dataget	exit_jsonINTERVALJOB_WAIT_MSGformat)modulejob_urijob_waitrebootapply_updatetrack_counterresponser4   redfisherror_message	job_state
job_statuss               u/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/openmanage/plugins/modules/idrac_firmware.pywait_for_job_completionrW     s'   MH
C
!
		 / B7"11'5ABQMC !
 qM
}
2	! / A7"11'5A$..22:>	%//33K@
A C Z'((,,Z8;IF  S )!!%%&78C?IQ\D\EEfYeQMJJx ) }
2* z!!!:#8B">?S=IB B  	m$CQMJJrNN	A A
  	!m$CQMJJx  	!s^   F FF  G 5A	G>
G FF 	G%GGGG 	H&)HHc                 v    | j                         }|st        d      |j                  d      st        d      y )Nz/catalog_file_name should be a non-empty string.xmlz(catalog_file_name should be an XML file.)lower
ValueErrorendswith)catalog_file_namenormilized_file_names     rV   _validate_catalog_filer_   B  s?    ,224JKK!**51CDD 2    c                     | d   d   d   j                  d      t        j                  d      k(  rJ| j                  d      dk(  r5|j                  r|j	                  d	       |j	                  t
        	       y y y )
Njob_detailsDataGetRepoBasedUpdateList_OUTPUTr2   .r/   r7   No changes found to commit!r3   )rF   MESSAGErstrip
check_moderG   EXIT_MESSAGE)statusrK   s     rV   get_check_mode_statusrl   J  sz    mV$%DEII)TX_XfXfgjXkkJJ{#{2!>?\* 3 lr`   c                 H  
 d\  }|d<   |d<   | j                   d   }| j                   d   }| j                   d   }|j                  d      S|r|j                  j                  |j                  d            
|rW|rU|j                  j                  |j                  d            

j                  d      
j                  d      dk(  sn|r|rU
j                  d      |d<   d	|d<   g d
}t	        
fd|D              rd|d<   d}||fS t        | t        j                  |j                  d            |||      \  
}|sY
j                  }	|	j                  d      r|	j                  d      d   d   |d<   |	j                  d      |d<   |d   dk(  rd}||fS d}||fS )N)FNNr/   r2   rM   rN   rO   JobID	ScheduledOK)failinvalidunablenotcancelc              3   `   K   | ]%  }|j                  d       j                         v  ' yw)r2   N)rF   rZ   ).0xresps     rV   	<genexpr>z!get_job_status.<locals>.<genexpr>a  s(     N1+1133Ns   +.r0   Tjob_idr1   r   )	r>   rF   job_mgrrM   anyrW   JOB_URIrJ   rE   )rK   	each_compidracfailedrM   rN   rO   fail_words_lowerr4   	resp_datary   s             @rV   get_job_statusr   R  s   ;L8FIk"Ii$8}}Z(H]]8$F==0L}}W)==)))--*@AD\}}--immG.DE88K(4dhh{>SWb>b \ $(88I#6Ii %)Ik"MN=MNN)3	+& f 0imm\cNd8egoqw0<>ID# NN	==,+4==+DQ+G	+RIi()2{)C	+&[)Z7!F f fr`   c           
         g dd}}}	 t        j                  |d         }|j                  d      D ]s  }t        |j                  d      D 	cg c]$  }|D ]  }	|j                  d   |	j
                  f & c}	}      }
t        | |
|      \  }}|s|rd}|j                  |       u d}|||fS c c}	}w # t         j                  $ r |d   }Y %w xY w)z@get all the xml data from PackageList and returns as valid json.FPackageListINSTANCENAMEPROPERTYNAMET)	ET
fromstringiterdictattribtextr   append
ParseError)rK   rb   r   datarepo_statusfailed_statusxmldatainameattrtxt	comp_data	componentr   s                rV   _convert_xmltojsonr   s  s    ')5%}+D*--M :;\\.1 	#E%**U_J`q$lpqeht{{62CHH=q=qrI .vy% HIv V $KK	"	#  m++ r == *=)*s$   AB4 )B.63B4 .B4 4CCc                     d}|j                   dk(  rE|j                  j                  d      }|| j                  d       |j	                  d      d   }|S | j                  d       |S )z(Get the Job ID from the response header.N   LocationzFailed to update firmware.r3   /)status_codeheadersrF   	fail_jsonsplit)rK   ry   jobidjoburis       rV   	get_jobidr     ss    E3!!*->!=>S!"% L 	9:Lr`   c                 <   t        j                  |      }|j                  di       j                  ddt        ig      }|rE|d   j                  dt              }t        |d   j                  d      v r| j                  |       d|v r| j                  |       y y )Nerrorz@Message.ExtendedInfor2   r   	MessageIdr3   )jsonloadrF   rj   IDEM_MSG_IDrG   r   )rK   httperrerr_messageerr_list
err_reasons        rV   handle_HTTP_errorr     s    ))G$Kw+//0G9VbJcIdeHa[__Y=
(1+//+66,+[) r`   c                 x   d}d }g d}d}d|z  }	 |s[| j                  t        d      }|j                  j                  d      j                  d      }|j                  j                  d      }d	j	                  |      }	d
j	                  ||	      }
|r| j                  |
d      }|j                  j                  d      }|D ]7  }|D ]*  }||j                  d      v sd}|j                  d      } n |s|s7 n |s|rn!|dz
  }t        j                  |       |rd}d}||fS # t        $ r
 d}d}Y ||fS w xY w)NF)SYS229SYS227RED132JCP042RED068RED137r*   r=   r+   Entries	@odata.idDateTimez?$filter=Created%20ge%20'{0}'z{0}{1}Membersr   Tr2   r,   zNo Error log found.)r?   LOG_SERVICE_URIrE   rF   rJ   rB   rC   r@   )r   	curr_timeurierror_log_foundr4   error_log_idsintrvlretriesry   fltrfltr_uri	logs_listlogerr_ids                 rV   get_error_syslogr     sj   O
C QMFFlG ''?D..$$Y/33K@C**:6I.55i@??3-''%8D**95I  + F!55*.!ggi0	
 / okGJJv   (C#O C   #C s$   CD& D& 9$D& D& &D98D9c                    t        |      }i i }
}	|j                  }|j                  }|j                  j	                  d      }|j                  r||d<   ||d<   t
        |   |d<   t        }t        }|j                  d      }|rL|j                  di       j                  dt              }|j                  di       j                  dt              }	 |j                  t        d	      }|j                  j                  d
      j                  d      }|j                  j                  d      }|j                  |d|      }t        |||      \  }}t        | |      }|r| j!                  |d|       t#        | t$        j'                  |      |||      \  }}|s|j                  }
n||
d<   	 |j                  |ddd      }|j                  }	|
|	fS # t        $ r t        }d}Y w xY w# t(        $ r}t+        | |       |d}~ww xY w)BUpdate firmware through HTTP/HTTPS/FTP and return the job details.r   	ShareName	IPAddress	ShareTypeActionsz6#DellSoftwareInstallationService.InstallFromRepositorytargetz7#DellSoftwareInstallationService.GetRepoBasedUpdateListr+   r   r   r   NPOSTmethodr   T)r4   r   r|   r{   
update_msg{}Fr   r   dump)r   netlocschemepathstrip
SHARE_TYPEPATHGET_REPO_BASED_UPDATE_LIST_PATHrF   r?   r   rE   r@   iDRAC9_LC_LOGr   r   rG   rW   r   rJ   r   r   )rK   r   
share_pathrO   rN   rM   payload	repo_urlsrepo_urlrb   rk   ipaddr
share_type	sharenameinstall_urlget_repo_urlactionslog_resplog_urir   ry   r   r4   r|   resp_repo_based_update_listerrs                             rV   update_firmware_url_redfishr     s   
#HbK__FJ##C(I}}(!GK%j1GKK2LmmI&Gkk"Z\^_ccdlnrs{{#\^`aC9: 	''?$$((377D&&**:6	 FID+E9gFOSvt$FSf='f0MxY_amnID#"|&+&:&:<PV]a@E '; 'G#1;; ;)  	"  &#&	s+   AG -!G) G&%G&)	H2H  Hc	                 \   t        |      }	i i }}
|	j                  }|	j                  }|	j                  j	                  d      }t
        | j                  d      }| j                  j                  d      | j                  j                  d      nd}| j                  j                  d      | j                  j                  d      nd}| j                  j                  d      | j                  j                  d      nd}| j                  j                  d	      }| j                  j                  d
      }|dk(  r9|j                  j                  ||||||||||||||      }t        ||        ||
fS |j                  j                  ||||||||||||||      }t        ||        ||
fS )r   r   proxy_support
proxy_typer   proxy_server 
proxy_portP   proxy_unameproxy_passwdzdownloads.dell.com)	ipaddressr   
share_namecatalog_filerO   reboot_neededignore_cert_warningrM   r   r   r   r   r   r   )r   r   r   r   r   PROXY_SUPPORTr>   rF   
update_mgrupdate_from_dell_repo_urlrl   update_from_repo_url)rK   r   r   r]   rO   rN   r   rM   r   r   rb   rk   r   r   r   r   r   r   r   r   r   s                        rV   update_firmware_url_omsdkr    s    
#HbK__FJ##C(I!&--"@AM4:MM4E4El4S4_""<0ekJ8>8I8I.8Y8e6==$$^4kmL4:MM4E4El4S4_""<0egJ--##M2K==$$^4L%%!!;;	Xi%VQdow'J\fp#,	 < @
 	ff- ; !!66	Xi%VQdow'J\!{	 7 W
 	ff-;r`   c                    i }ddi c|d<   |d<   |d<   d|d<   	 |j                   d   }|j                   d   }|j                   d	   }|j                   d
   }|j                   d   }|j                   d   }|j                   d   }	|j                   d   }
||t        |
      t        |	   d}|||d<   |||d<   |j                         j	                  d      r$t        || |||
||	||	      \  |d<   }|r||d   d<   nvt        dj                  |t        j                  |      |j                   d   dt        ||            }| j                  j                  ||
||      |d<   t        |d   |       |d   d   dd}}}d|vrD|j                  d      }d|v r|d   n|j                  d      }d|v r)t        |||       \  |d<   }}nt        ||d      \  |d<   }}|
s|sd|d<   n3|
r|s
|s|sd|d<   n%|
r|r|s|sd|d<   d |d<   n|
r|r|s|r
d!|d<   d |d<   |j$                  rAj                  d      s0|j                  d      s|d   d#   d$k(  r|j'                  d%"       |S |j$                  rFj                  d      s|j                  d      r$|d   d#   d$k(  r|j'                  d&d |d   '       |S |j$                  r7|d   d#   d$k(  s,|d   j)                  d       |j#                  d(|d   )       |S |j$                  sd*|d   v r|d   d*   d+v r|j                   d   r5|j                   d   r&|j                   d   rd|d   v rrsd |d<   d,|d<   |S |j                   d   r9|j                   d   r*|j                   d   rd|d   v rrrd-\  |d<   |d<   d.|d<   |S d.}
sd/}|j#                  ||d   )       |S # t         $ r&}|j#                  t        |      "       Y d}~d}~ww xY w)0@Update firmware from a network share and return the job details.Fchangedr   update_status6Successfully triggered the job to update the firmware.r   r   r]   
share_usershare_passwordrN   rM   r   rO   RebootNeededCatalogFileApplyUpdateIgnoreCertWarningNUserNamePasswordzhttp://zhttps://zftp://rb   z	{0}{1}{2}	share_mnt)remotemount_pointisFoldercreds)rO   r   rM   r   rc   bodyrd   ASuccessfully fetched the applicable firmware update package list.5Successfully triggered the job to stage the firmware.<Successfully staged the applicable firmware update packages.TJSuccessfully staged the applicable firmware update packages with error(s).r3   r/   r7   rf   Changes found to commit!r4   r  r  4Unable to complete the firmware repository download.r4   r  Status)Success
InProgress"Successfully updated the firmware.r!   Firmware update failed.)Unable to complete the repository update.)r>   rA   	CERT_WARNrZ   
startswithr  r   rJ   ossepr   r   update_from_reporl   rF   r   RuntimeErrorr   ri   rG   pop)r   rK   r4   r   r]   r	  	share_pwdrN   rM   r   rO   r   rb   	upd_sharerE   r   r   job_datapkglste
failed_msgs                        rV   update_firmware_omsdkr4    s   
C:?7C	NCM3#7PC3%]]<0
"MM*=>]]<0
MM"23	x(==,$mm,AB}}^4#):K\_`l\m(12E(FH!",GJ "+GJ(()JK0I&RWYcevJVX^`sJRT[1]-C + 6AO$]3#;+=+=j"&&Rc+d06k0JUZ*9*i*PRI $)#3#3#D#DFU] $E $`C !#o"6?),_)=m)LeUZ;		) }}V,H)/8);Xf%NmAnF&=OPVX^`e=f:}%{F<NvW`bf<g9Im$k6F cC&& WChvf ^C!C	Nhv& lC CM
 )--">)--PVBW -<:;0 J/ 
			m <	f@U -<7'*?'; 	 	=* J' 
		3#7#D#SO  /S'*?'; 	 	=" J 8s?/C#C)-FF}}Z(V]]>-Jv}}]eOf!S%99kSY!%I$HL! J z*v}}^/LQWQ^Q^_gQh!S%99kv0;-Hs9~$=L! J	 3JH
3;OPJ;  %SV$$%s   G;N? ?	O.O))O.c           
      
   i }d\  |d<   |d<   d|d<   	 |j                   d   }|j                   d   }|j                   d   }|j                   d	   }|j                   d
   }|j                   d   }	|j                   d   }
|j                   d   }||t        |      t        |
   d}|||d<   |||d<   |j                         j	                  d      r|j                   j                  d      }|dk(  rEddddddd}|j                         D ](  \  }}|j                   j                  |      }|$|||<   * n#|dk(  r|j                   j                  d      |d<   t        || ||||	||      \  |d<   }|r-||d   d<   n#|j	                  d      r6|j                  d       }|d!   |d"<   d j                  |d#d       |d$<   d%|d&<   nOt        d'|z         }|j                  j                  d(      |d"<   |j                  j                  d)      |d$<   d*|d&<   | j                  t        d+|,      }t!        ||      }t#        |t$        j'                  |-      |	||      \  }}|s|j(                  |d<   n||d<   	 | j                  t*        d+d.d/0      }|j(                  |d   d<   |d   d   d/d/}}}d1|vrD|j                  d2      }d3|v r|d3   n|j                  d4      }d1|v r)t1        |||       \  |d1<   }}nt1        ||d      \  |d1<   }}|s|sd5|d<   n3|r|s
|	s|sd6|d<   n%|r|	r|s|sd7|d<   d8|d<   n|r|	r|s|r
d9|d<   d8|d<   |j6                  rAj                  d1      s0|j                  d2      s|d   d;   d<k(  r|j9                  d=:       |S |j6                  rFj                  d1      s|j                  d2      r$|d   d;   d<k(  r|j9                  d>d8|d   ?       |S |j6                  r7|d   d;   d<k(  s,|d   j;                  d       |j5                  d@|d   A       |S |j6                  sd;|d   v r|d   d;   dBk(  s|j                   d   r5|j                   d   r&|j                   d
   rd|d   v rrsd8|d<   dC|d<   |S |j                   d   r9|j                   d   r*|j                   d
   rd|d   v rrrdD\  |d<   |d<   dE|d<   |S dE} sdF} |j5                  | |d   A       |S # t,        $ r}t/        ||       |d}~ww xY w# t2        $ r&}|j5                  t        |      :       Y d}~d}~ww xY w)Gr  )FFr  r   r  r   r   r]   r	  r
  rN   rM   r   rO   r  Nr  r  r  r   r%   ProxyServer	ProxyPortProxySupport	ProxyType
ProxyUnameProxyPasswd)r   r   r   r   r   r   r$   r  rb   z\\\r<   r      r   r   r   znfs://:r   r   r   r   r{   r   Fr   r   rc   r  rd   r  r  r  Tr  r3   r/   rp   rf   r  r  r  r   r0   r$  r!   r%  r&  )r>   rA   r'  rZ   r(  rF   itemsr   r   joinr   r   r   r   r?   r   r   rW   r   rJ   rE   r   r   r   r   r,  r   ri   rG   r-  )!r   rK   r   r4   r   r]   r	  r.  rN   rM   r   rO   r   proxy
proxy_dictpkpvprmrb   r   r   ry   r|   mesgrepo_based_update_listr   rE   r   r   r0  r1  r2  r3  s!                                    rV   update_firmware_redfishrH  k  s-   
C$0!C	NCMPCQ%]]<0
"MM*=>]]<0
MM"23	x(==,$mm,AB}}^4#):K\_`l\m(12E(FH!",GJ "+GJ(()JKMM%%o6E)).;,7/=,7-9.;=
 )..0 *FB --++B/C&)* .(*0--*;*;O*L'0Kz<7T]1_-C +6AO$]3$$V,!''-'+Aw$'+yyab':$'-$x*45'*zz'7'7'<$'*xx~~c':$',$''V''JDvt,F0v9VX`bhjvwJD$'+~~O$'+O$).)=)=>]flCGe *> *U&6L6V6VO$]3 *-_)=m)LeUZ;		) }}V,H)/8);Xf%NmAnF&=OPVX^`e=f:}%{F<NvW`bf<g9Im$k6F cC&& WChvf ^C!C	Nhv& lC CM
 )--">)--PVBW -5:;0 J/ 
			m <	f@U -57'*?'; 	 	=* J' 
		3#7#D#LO  /S'*?'; 	 	=" J ;#o2F#F?#K0J>}}Z(V]]>-Jv}}]eOf"c/&::{TZ!%I$HL! J z*v}}^/LQWQ^Q^_gQh"c/&::{PV0;-Hs9~$=L! J	 3JH
3;OPJi  !&#.	.  %SV$$%sD   DT -ET 5+S1  B%T 1	T:TTT 	T?T::T?c                     dddddiddgddddidddd	d
dd	ddd	ddd	ddddg dddddgdddiddiddidddd} | j                  t               t        | g dgd      }d
}	 t        |j                        5 }|j                  t        d      }|j                  }d}d d d        	 t        |j                  d          |j                  r-d
|j                  d<   d
|j                  d<   d|j                  d<   |r,t        |j                        5 }t        ||      }d d d        n*t        |j                        5 }t        ||      }d d d        |j+                  d    |d!   |d"   |d#   $       y # 1 sw Y   xY w# t        $ r i }d
}Y w xY w# 1 sw Y   JxY w# 1 sw Y   VxY w# t        $ r9}	|j                  t!        |	      t#        j$                  |	             Y d }	~	d }	~	wt&        $ rA}	|	j(                  r|	j(                  n |	t               }
|j+                  |
d       Y d }	~	d }	~	wt,        t.        t0        t2        t4        t6        t8        t:        f$ r&}|j                  t!        |             Y d }~/d }~wt        $ r,}|j                  dj=                  |             Y d }~bd }~ww xY w)%NTrA   )requiredtyperK  r.  )rK  aliasesno_logzCatalog.xml)rK  defaultboolFr    )r    r%   r$   )rN  rK  choicesr   SOCKS)rK  rP  int)rK  rM  )r   r	  r
  r  r]   rN   rM   r   rO   r   r   r   r   r   r   )r   r%   )r   r   r   )argument_specrequired_ifsupports_check_moder+   )r   r]   rO   rN   rM   r   )r4   unreachabler3   zUnhandled Exception {0}r   r  r  r   )r4   r  r  r   )updater	   r   r
   r>   r?   
IDRAC_PATHrE   r@   r_   ri   rH  r   r4  r   r   rA   r   r   r   reasonrG   r,  r   r   KeyErrorImportErrorr[   	TypeErrorr   rJ   )specsrK   redfish_checkobjry   software_service_dataredfish_objrk   r   r   messager2  excs                rV   mainrd    s   #'7uo#(k]dSe_&+F!e4#5(.4@!'D9%*EFpq$&'1BCuo!&$7#E& 
LL"# `
 !"F MV]]+ 	!s%%j%?D$(NN! M	!Dv}}-@AB,1FMM.)&+FMM(#(,FMM*% / ];0fF[\] ] !/ >5.uf=> -VO=T#I.vh7G  IC	! 	!   "] ]> > ESXTYYs^DD 8 #

#**CW$77,oxY: %SV$$ D6==cBCCDs   +F  &E:&F /A(F1 F%F1 F%F1 :F?F FFF"F1 %F.*F1 1	J?:/G..J?:7H660J?&JJ?!J::J?__main__)FFF)F
__future__r   r   r   rK  __metaclass__DOCUMENTATIONEXAMPLESRETURNr)  r   rB   sslr   	xml.etreer   r   Iansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idracr   r	   Iansible_collections.dellemc.openmanage.plugins.module_utils.idrac_redfishr
   ansible.module_utils.basicr   +ansible.module_utils.six.moves.urllib.parser   ansible.module_utils.urlsr   r   +ansible.module_utils.six.moves.urllib.errorr   r   omsdk.sdkcredsr   omsdk.sdkfiler   	HAS_OMSDKr[  r   r'  r   rX  r   r   r   iDRAC_JOB_URIr   r   iDRAC8_LC_LOGrg   rj   r   REDFISH_VERSIONrH   rD   rI   rW   r_   rl   r   r   r   r   r   r   r  r4  rH  rd  __name__ r`   rV   <module>r{     sY   C BrhM^
. 
    ' x e 4 @ I K.)I F5w@
&	!7ZopY
?#c 
0EKQB
l5
5+\E+B,$
*( V*Z>TnrjAIH zF W  Is   C CC