
    Vh3                        d dl mZmZmZ eZdZdZdZdZ	dZ
dZdZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#d Z$d!Z%d"Z&d#Z'd$Z(d%Z)d&Z*d'Z+d(Z,d d)l-Z-d d)l.Z.d d*l/m0Z0 d d+l1m2Z2m3Z3 d d,l4m5Z5m6Z6 d d-l7m8Z8m9Z9 d d.l:m;Z; d d/l<m=Z= d d0l>m?Z?m@Z@ d1 ZAd2 ZBd3 ZCd4 ZDd5 ZEd6 ZFd7 ZGd8 ZHd9 ZIe+e,fd:ZJd; ZKd< ZLd= ZMd> ZNd? ZOd@ ZPdA ZQdB ZRdC ZSdD ZTdE ZUdF ZVdG ZWdH ZXdI ZYeZdJk(  r eY        y)y))K    )absolute_importdivisionprint_functiona	  
---
module: idrac_bios
short_description: Modify and clear BIOS attributes, reset BIOS settings and configure boot sources
version_added: "2.1.0"
description:
    - This module allows to modify the BIOS attributes. Also clears pending BIOS attributes and resets BIOS to default settings.
    - Boot sources can be enabled or disabled. Boot sequence can be configured.
extends_documentation_fragment:
    - dellemc.openmanage.idrac_auth_options
options:
    share_name:
        type: str
        description: (deprecated)Network share or a local path.
    share_user:
        type: str
        description: "(deprecated)Network share user name. Use the format 'user@domain' or domain//user if user
        is part of a domain. This option is mandatory for CIFS share."
    share_password:
        type: str
        description: (deprecated)Network share user password. This option is mandatory for CIFS share.
        aliases: ['share_pwd']
    share_mnt:
        type: str
        description: "(deprecated)Local mount path of the network share with read-write permission for ansible user.
        This option is mandatory for network shares."
    apply_time:
        type: str
        description:
          - Apply time of the I(attributes).
          - This is applicable only to I(attributes).
          - "C(Immediate) Allows the user to immediately reboot the host and apply the changes. I(job_wait)
          is applicable."
          - C(OnReset) Allows the user to apply the changes on the next reboot of the host server.
          - "C(AtMaintenanceWindowStart) Allows the user to apply at the start of a maintenance window as specified
          in I(maintenance_window). A reboot job will be scheduled."
          - "C(InMaintenanceWindowOnReset) Allows to apply after a manual reset but within the maintenance window as
          specified in I(maintenance_window)."
        choices: [Immediate, OnReset, AtMaintenanceWindowStart, InMaintenanceWindowOnReset]
        default: Immediate
    maintenance_window:
        type: dict
        description:
          - Option to schedule the maintenance window.
          - This is required when I(apply_time) is C(AtMaintenanceWindowStart) or C(InMaintenanceWindowOnReset).
        suboptions:
           start_time:
               type: str
               description:
                  - The start time for the maintenance window to be scheduled.
                  - "The format is YYYY-MM-DDThh:mm:ss<offset>"
                  - "<offset> is the time offset from UTC that the current timezone set in
                  iDRAC in the format: +05:30 for IST."
               required: true
           duration:
               type: int
               description:
                  - The duration in seconds for the maintenance window.
               required: true
    attributes:
        type: dict
        description:
          - "Dictionary of BIOS attributes and value pair. Attributes should be
          part of the Redfish Dell BIOS Attribute Registry. Use
          U(https://I(idrac_ip)/redfish/v1/Systems/System.Embedded.1/Bios) to view the Redfish URI."
          - This is mutually exclusive with I(boot_sources), I(clear_pending), and I(reset_bios).
    boot_sources:
        type: list
        elements: raw
        description:
          - (deprecated)List of boot devices to set the boot sources settings.
          - I(boot_sources) is mutually exclusive with I(attributes), I(clear_pending), and I(reset_bios).
          - I(job_wait) is not applicable. The module waits till the completion of this task.
          - This feature is deprecated, please use M(dellemc.openmanage.idrac_boot) for configuring boot sources.
    clear_pending:
        type: bool
        description:
          - Allows the user to clear all pending BIOS attributes changes.
          - C(true) will discard any pending changes to bios attributes or remove job if in scheduled state.
          - This operation will not create any job.
          - C(false) will not perform any operation.
          - This is mutually exclusive with I(boot_sources), I(attributes), and I(reset_bios).
          - C(Note) Any BIOS job scheduled due to boot sources configuration will not be cleared.
    reset_bios:
        type: bool
        description:
          - Resets the BIOS to default settings and triggers a reboot of host system.
          - This is applied to the host after the restart.
          - This operation will not create any job.
          - C(false) will not perform any operation.
          - This is mutually exclusive with I(boot_sources), I(attributes), and I(clear_pending).
          - When C(true), this action will always report as changes found to be applicable.
    reset_type:
        type: str
        description:
          - C(force_restart) Forcefully reboot the host system.
          - C(graceful_restart) Gracefully reboot the host system.
          - This is applicable for I(reset_bios), and I(attributes) when I(apply_time) is C(Immediate).
        choices: [graceful_restart, force_restart]
        default: graceful_restart
    job_wait:
        type: bool
        description:
          - Provides the option to wait for job completion.
          - This is applicable for I(attributes) when I(apply_time) is C(Immediate).
        default: true
    job_wait_timeout:
        type: int
        description:
          - The maximum wait time of I(job_wait) in seconds. The job is tracked only for this duration.
          - This option is applicable when I(job_wait) is C(true).
        default: 1200
requirements:
    - "omsdk >= 1.2.490"
    - "python >= 3.9.6"
author:
    - "Felix Stephen (@felixs88)"
    - "Anooja Vardhineni (@anooja-vardhineni)"
    - "Jagadeesh N V (@jagadeeshnv)"
    - "Shivam Sharma (@shivam-sharma)"
notes:
    - omsdk is required to be installed only for I(boot_sources) operation.
    - This module requires 'Administrator' privilege for I(idrac_user).
    - Run this module from a system that has direct access to Dell iDRAC.
    - This module supports both IPv4 and IPv6 address for I(idrac_ip).
    - This module supports C(check_mode).
ac  
---
- name: Configure generic attributes of the BIOS
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    attributes:
      BootMode: "Bios"
      OneTimeBootMode: "Enabled"
      BootSeqRetry: "Enabled"

- name: Configure PXE generic attributes
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    attributes:
      PxeDev1EnDis: "Enabled"
      PxeDev1Protocol: "IPV4"
      PxeDev1VlanEnDis: "Enabled"
      PxeDev1VlanId: 1
      PxeDev1Interface: "NIC.Embedded.1-1-1"
      PxeDev1VlanPriority: 2

- name: Configure BIOS attributes at Maintenance window
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    apply_time: AtMaintenanceWindowStart
    maintenance_window:
      start_time: "2022-09-30T05:15:40-05:00"
      duration: 600
    attributes:
      BootMode: "Bios"
      OneTimeBootMode: "Enabled"
      BootSeqRetry: "Enabled"

- name: Clear pending BIOS attributes
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    clear_pending: true

- name: Reset BIOS attributes to default settings.
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    validate_certs: false
    reset_bios: true

- name: Configure boot sources
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    boot_sources:
      - Name: "NIC.Integrated.1-2-3"
        Enabled: true
        Index: 0

- name: Configure multiple boot sources
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    boot_sources:
      - Name: "NIC.Integrated.1-1-1"
        Enabled: true
        Index: 0
      - Name: "NIC.Integrated.2-2-2"
        Enabled: true
        Index: 1
      - Name: "NIC.Integrated.3-3-3"
        Enabled: true
        Index: 2

- name: Configure boot sources - Enabling
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    boot_sources:
      - Name: "NIC.Integrated.1-1-1"
        Enabled: true

- name: Configure boot sources - Index
  dellemc.openmanage.idrac_bios:
    idrac_ip: "192.168.0.1"
    idrac_user: "user_name"
    idrac_password: "user_password"
    ca_path: "/path/to/ca_cert.pem"
    boot_sources:
      - Name: "NIC.Integrated.1-1-1"
        Index: 0
a  
---
status_msg:
    description: Overall status of the bios operation.
    returned: success
    type: str
    sample: Successfully cleared pending BIOS attributes.
msg:
    description: Status of the job for I(boot_sources) or status of the action performed on bios.
    returned: success
    type: dict
    sample: {
       "CompletionTime": "2020-04-20T18:50:20",
       "Description": "Job Instance",
       "EndTime": null,
       "Id": "JID_873888162305",
       "JobState": "Completed",
       "JobType": "ImportConfiguration",
       "Message": "Successfully imported and applied Server Configuration Profile.",
       "MessageArgs": [],
       "MessageId": "SYS053",
       "Name": "Import Configuration",
       "PercentComplete": 100,
       "StartTime": "TIME_NOW",
       "Status": "Success",
       "TargetSettingsURI": null,
       "retval": true
    }
invalid_attributes:
  type: dict
  description: Dict of invalid attributes provided.
  returned: on invalid attributes or values.
  sample: {
        "PxeDev1VlanId": "Not a valid integer.",
        "AcPwrRcvryUserDelay": "Integer out of valid range.",
        "BootSeqRetry": "Invalid value for Enumeration.",
        "Proc1Brand": "Read only Attribute cannot be modified.",
        "AssetTag": "Attribute does not exist."
    }
error_info:
  description: Details of the HTTP Error.
  returned: on HTTP error
  type: dict
  sample: {
    "error": {
      "code": "Base.1.0.GeneralError",
      "message": "A general error has occurred. See ExtendedInfo for more information.",
      "@Message.ExtendedInfo": [
        {
          "MessageId": "GEN1234",
          "RelatedProperties": [],
          "Message": "Unable to process the request because an error occurred.",
          "MessageArgs": [],
          "Severity": "Critical",
          "Resolution": "Retry the operation. If the issue persists, contact your system administrator."
        }
      ]
    }
  }
z%/redfish/v1/Systems/System.Embedded.1z%/redfish/v1/Managers/iDRAC.Embedded.1z*/redfish/v1/Systems/System.Embedded.1/Biosz7/redfish/v1/Systems/System.Embedded.1/Bios/BiosRegistryzX/redfish/v1/Systems/System.Embedded.1/Bios/Settings/Actions/Oem/DellManager.ClearPendingzA/redfish/v1/Systems/System.Embedded.1/Bios/Actions/Bios.ResetBiosz3/redfish/v1/Systems/System.Embedded.1/Bios/SettingszB/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Resetz*/redfish/v1/Managers/iDRAC.Embedded.1/Jobsz?/redfish/v1/Managers/iDRAC.Embedded.1/Jobs?$expand=*($levels=1)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$?$filter=MessageId%20eq%20'UEFI0157'z#?$filter=MessageId%20eq%20'SYS1003'z9BIOS Config job is running. Wait for the job to complete.zNo changes found to be applied.zChanges found to be applied.z1Successfully cleared the pending BIOS attributes.z0Successfully applied the BIOS attributes update.z>Successfully scheduled the job for the BIOS attributes update.z\Successfully committed changes. The job is in pending state. The changes will be applied {0}z)Reset BIOS action triggered successfully.zPUnable to restart the host. Check the host status and restart the host manually.zSThe BIOS reset action has been triggered successfully. The host reboot is complete.z7BIOS reset to defaults has been completed successfully.z_Pending attributes to be applied. Clear or apply the pending changes before resetting the BIOS.zGThe BIOS configuration job is scheduled. Use 'force' to delete the job.z4The values specified for the attributes are invalid.z Apply time {0} is not supported.zAThe maintenance time must be post-fixed with local offset to {0}.zsThe specified maintenance time window occurs in the past, provide a future time to schedule the maintenance window.z@The parameter job_wait_timeout value cannot be negative or zero.   
   N)recursive_diff)URLError	HTTPError)ConnectionErrorSSLValidationError)iDRACConnectionidrac_auth_params)iDRACRedfishAPI)AnsibleModule)idrac_redfish_job_trackingstrip_substr_dictc                     i }d| _         t        |j                  d          |j                  r| j                  j                          | j                  j                  |j                  d         }|S )NTboot_sources)input_boot_devices)use_redfish_validate_paramsparams
check_mode
config_mgris_change_applicableconfigure_boot_sources)idracmodulemsgs      q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/openmanage/plugins/modules/idrac_bios.pyrun_server_bios_configr!   l  sc    
CEV]]>23--/



1
1V]]SaEb
1
cCJ    c                 Z   dt         dddt        ddddt        ddg}g d	| D ]w  }t        |t              sd
j                  |t        |            }|c S t        fd|j                         D              rt        ||      }|c S dj                        }|c S  t        |       }|S )zk
    Validate list of dict params.
    :param params: Ansible list of dict
    :return: bool or error.
    NameT)nametyperequiredIndexFr   )r%   r&   r'   minEnabled)r$   r(   r*   z;attribute values must be of type: dict. {0} ({1}) provided.c              3   &   K   | ]  }|v  
 y w)N ).0kdefaults     r    	<genexpr>z#_validate_params.<locals>.<genexpr>  s     3!g3s   z&attribute keys must be one of the {0}.)strintbool
isinstancedictformatr&   allkeyscheck_params _validate_name_index_duplication)r   fieldsattrr   r/   s       @r    r   r   v  s     $7#5CDe<F
 +G 	$%OVVW[]abf]ghCJ3tyy{33tV,CJ:AA'JCJ	 +6
2CJr"   c                     d}t        t        |       dz
        D ]M  }t        |dz   t        |             D ]0  }| |   d   | |   d   k(  sdj                  | |   d         }|c c S  O |S )zw
    Validate for duplicate names and indices.
    :param params: Ansible list of dict
    :return: bool or error.
        r$   zduplicate name  {0})rangelenr6   )r   r   ijs       r    r:   r:     s     C3v;?# q1uc&k* 	Aay F1If$55+226!9V3DE
	
 Jr"   c                    d}|D ]  }|d   | vr|d   du r|d   | vr |d   du rdj                  |d   |d         }9t        | |d      |d         s0dj                  |d   |d   | |d      t        | |d                  }~|d   | v st        | |d      t              sd	|v s| |d      |d	   k  sd
j                  |d   |d	         } |S )z
    Each dictionary parameters validation as per the rule defined in fields.
    :param each: validating each dictionary
    :param fields: list of dictionary which has the set of rules.
    :return: tuple which has err and message
    r>   r%   r'   FTz({0} is required and must be of type: {1}r&   z-{0} must be of type: {1}. {2} ({3}) provided.r)   z){0} must be greater than or equal to: {1})r6   r4   r&   r2   )eachr;   r   fs       r    r9   r9     s    C 
^V9D Qz]e%;yD Qz]d%:<CCAfIqQWyYCD6OQvY7AHH&	1V9d1V9otD6O7LNCvY$:d1V9os#CQR
AfI5)AHH6TUV[T\]
^ Jr"   c                 
   | j                  t        d      }|j                  j                  dg       }d }d}|D ]E  }|j                  d      dk(  s|j                  d      dv s,|d   }|j                  d      } ||fS  ||fS )	NGETMembersUnknownJobTypeBIOSConfigurationJobState)	ScheduledRunningStartingId)invoke_requestiDRAC_JOBS_EXP	json_dataget)redfish_objjob_respjob_listsch_jbjb_statejbs         r    check_scheduled_bios_jobr\     s    )).%@H!!%%i4HFH 66) 33z8JNr8rXFvvj)H8
 8r"   c                 R    | j                  t        j                  |      d      }|S )Njob_idDELETE)rR   iDRAC_JOB_URIr6   )rV   r_   resps      r    delete_scheduled_bios_jobrc     s'    %%m&:&:&&:&I8TDKr"   c                     	 | j                  t        d      }|j                  j                  d      }|S # t        $ r i }Y |S w xY w)NrH   
Attributes)rR   BIOS_SETTINGSrT   rU   	Exception)rV   rb   r<   s      r    get_pending_attributesrh     sO    ))-?~~!!,/ K  Ks   15 AAc                     d}d}|dkD  r5	 | j                  t        d      }|j                  j                  d      }	 |S |S # t        $ r |dz
  }Y nw xY w|dkD  rQ)N   rJ   r   rH   
PowerStater?   )rR   
SYSTEM_URIrT   rU   rg   )rV   retriespstaterb   s       r    get_power_statero     sp    GF
A+	"--j%@D^^''5F M6M  	"kG	" A+s   1A AAc                 d    	 | j                  t        dd|i       d}|S # t        $ r d}Y |S w xY w)NPOST	ResetTypedataTF)rR   POWER_HOST_URIr
   )rV   p_statep_acts      r    power_act_hostrx     sH    "">6g@V"W L  Ls     //c                 t    |}|r1t        |       }||v rd}	 |S t        j                  |       |dz
  }|r1d}|S )NTr?   F)ro   timesleep)rV   desired_staterm   intervalcountpsachieveds          r    track_power_stater     sS    E
[)H O	 JJx 	  Or"   c                 p   | j                   j                  d      }d}t        |      }dg}||v rUd}d|v rd}t        ||      }|s| j	                  dt
               t        |dg      }d}|st        j                  d	       d
}t        ||      }|s| j	                  dt
               t        ||      }|S )N
reset_typeOnGracefulShutdownforceForceOffTfailed
status_msgOffr   ForceRestart)	r   rU   ro   rx   	exit_jsonHOST_RESTART_FAILEDr   rz   r{   )r   rV   r   rv   r   on_staterw   state_achieveds           r    
reset_hostr     s    ""<0JG		%BvH	X~$j  G{G4D5HI*;@JJrN$G;0E1DE&{H=Nr"   c                     	 | j                  t        d      }|j                  j                  d      }|j                  j                  d      }||fS # t        $ r Y yw xY w)NrH   DateTimeDateTimeLocalOffset)NN)rR   MANAGER_URIrT   rU   rg   )rV   rb   	curr_timedate_offsets       r    get_current_timer     sc    ))+u=NN&&z2	nn(()>? k!!  s   AA 	AAc                    d }t         t        g}d}d|z  }t        j                  |       	 | j	                  t
        d      }|j                  j                  d      j                  d      }g }|D ]#  }|j                  dj                  ||             % t        |      }	d}
|dz  }|j                  j                  d	      }|r| j	                  |||
z     d      }|j                  j                  d
      }|D ]  }|j                  d      |kD  st        } n |r	 |S |dz
  }t        j                  |       ||k  r|	}
|rt        }	 |S # t        $ r
 t        }Y |S w xY w)N   ih  rH   Entriesz	@odata.idz{0}{1}r?   rj   r   rI   Created)LC_LOG_FILTERCPU_RST_FILTERrz   r{   rR   LOG_SERVICE_URIrT   rU   appendr6   rA   BIOS_RESET_COMPLETEBIOS_RESET_TRIGGEREDrg   )rV   r   filter_listintrvlrm   rb   uri	fltr_urisfltrflenflnpvtr   	logs_listlogs                  r    track_log_entryr     ss   
C .1KFVmGJJv#))/5Ann  +//<	 	9DX__S$78	99~lNN&&z2	--i#.FND**95I  779%	1-C  J kGJJv}  'C J  #"J#s$   C%E E  #E E E E c                 r   t        |      }|r| j                  t        d       | j                  r| j                  t        d       |j                  t        ddd       t        | |      }|s+| j                  ddj                  t        t                     t        |      }| j                  |d       y )	NTr   r   r   changedrq   {}rt   dumpz{0} {1}r   )rh   r   BIOS_RESET_PENDINGr   CHANGES_MSGrR   RESET_BIOS_DEFAULTr   r6   RESET_TRIGGERREDr   r   )r   rV   r<   reset_successlog_msgs        r    
reset_biosr   =  s    !+.D$6tDK>164Pv{3M1A1ABRTg1hik*G
6r"   c                    t        |      }|s| j                  t               t        |      \  }}|rg|dv r| j                  dt        |       nJ|dv rF| j
                  r| j                  t        d       t        ||       | j                  t        d       | j
                  r| j                  t        d       |j                  t        ddd	
       | j                  t        d       y )Nr   rO   rP   Tr   r   r_   rN   
Schedulingr   rq   r   Fr   )rh   r   NO_CHANGES_MSGr\   BIOS_JOB_RUNNINGr   r   rc   SUCCESS_CLEARrR   CLEAR_PENDING_URI)r   rV   r<   r_   	job_states        r    clear_pending_biosr   K  s    !+.DN30=FI//D5EfU55     K F%k6:tDK>0&t%P
t<r"   c                     i }	 | j                  t        d      }|j                  j                  d      j                  d      }t	        d |D              }|S # t
        $ r i }Y |S w xY w)NrH   RegistryEntriesre   c              3   *   K   | ]  }|d    |f  yw)AttributeNameNr,   )r-   xs     r    r0   z*get_attributes_registry.<locals>.<genexpr>e  s     @a(!,@s   )rR   BIOS_REGISTRYrT   rU   r5   rg   )r   reggyrb   	attr_lists       r    get_attributes_registryr   `  sp    E##M59NN&&'89==lK	@i@@ L  Ls   AA A'&A'c                    i }|j                         D ]  \  }}|| v r| j                  |      }|j                  d      rd||<   2|j                  d      }|dk(  r8d}|j                  dg       D ]  }||j                  d      k(  sd} n |sd	||<   |d
k(  s	 t        |      }	|j                  d      |	cxk  r|j                  d      k  rn d||<   d||<    |S # t        $ r d||<   Y w xY w)NReadOnlyz'Read only attribute cannot be modified.TypeEnumerationFValue	ValueNameTzInvalid value for enumeration.Integer
LowerBound
UpperBoundzInteger not in a valid range.zInvalid integer.zThe attribute does not exist.)itemsrU   r2   rg   )
registry	attr_dictinvalidr.   vval_dictr&   foundvalrB   s
             r    validate_vs_registryr   k  s   G! 91=||AH||J'F
||F+=(!E'||GR8 " 44$(E!" !%E
9$IF !)\ :a ]8<<P\C] ])HGAJ8GAJ192 N % 8%7
8s   C  C10C1c                 p    	 | j                  t        d      }|j                  }|S # t        $ r i }Y |S w xY w)NrH   )rR   BIOS_URIrT   rg   )rV   rb   settings      r    get_current_attributesr     sD    ))(E:.. N  Ns   "& 55c                     t        |      \  }}|j                  |      s&| j                  dt        j	                  |             ||k  r| j                  dt
               y y )NTr   )r   endswithr   MAINTENANCE_OFFSETr6   MAINTENANCE_TIME)r   rV   mtimer   r   s        r    validate_timer     s]    -k:I{>>+&1C1J1J;1WXy1AB r"   c                 n   i }d}|rd|v r||vr*| j                  dt        j                  |             ||fS ||d<   | j                  j	                  d      }t        | ||j	                  d             |j	                  d      |d<   |j	                  d	      |d
<   ||fS |dk(  r||vrd}d}||d<   ||fS )NFMaintenanceTr   	ApplyTimemaintenance_window
start_timeMaintenanceWindowStartTimeduration"MaintenanceWindowDurationInSeconds	ImmediateOnReset)r   UNSUPPORTED_APPLY_TIMEr6   r   rU   r   )r   rV   aplytmrf_settingsrf_set
reboot_reqm_wins          r    get_redfish_apply_timer     s    FJF"[(  9O9V9VW]9^ _ : '-{#))*>?fk599\3JK7<yy7N34?Dyy?T;< : $,!%J&F"(F;:r"   c                     d }dt         i}| j                  t        d|      }|j                  d   j	                  d      d   }|S )NTargetSettingsURIrq   rs   Location/)rf   rR   IDRAC_JOBS_URIheaderssplit)rV   r_   payloadrb   s       r    trigger_bios_jobr    sK    F"M2G%%nf7%KD\\*%++C04FMr"   c                 X   d|i}| j                   j                  d      }t        | |||      \  }}|r||d<   |j                  t        d|      }|rD|j                  |j
                  d   d       |j
                  d   j                  d      d	   }	|	|fS |d
k(  rd}t        |      }	|	|fS )Nre   
apply_timez@Redfish.SettingsApplyTimePATCHrs   r   rH   r  r  r   T)r   rU   r   rR   rf   r  r  r  )
r   rV   pendingr   r  r   r   reboot_requiredrb   r_   s
             r    apply_attributesr    s    W%G]]|,F4V[&R]^FO06,-%%mW7%KD""4<<
#;UCj)//4R8
 ?"" [ "O!+.?""r"   c                 
   t        |      }|j                  di       }| j                  j                  d      }t        ||      }i }|r
|d   r|d   }i }t	        |      }|r5|j                  t        ||             |r| j                  dt        |       |s| j                  t               | j                  r| j                  t        d       t        |      }	|	j                  |       |	r=t        |      \  }
}|
r-|dv r| j                  t        |
d	       n|d
v rt        ||
       |j                  di       j                  dg       }t!        | ||	|      \  }
}|r|
rt#        | |      }|s&| j                  dj%                  t&              d       | j                  j                  d      ryt)        |t*        j%                  |
      | j                  j                  d            \  }}}}|r| j                  d||
       | j                  t,        |
t/        |      d       n| j                  t0        |
d       | j                  t2        j%                  | j                  j                  d            |
d       y )Nre   
attributesr   T)r   r   invalid_attributesr   r   r   )r   r_   r   r   z@Redfish.SettingsSupportedApplyTimesz.Attributes committed but reboot has failed {0}r   job_waitr^   job_wait_timeout)max_job_wait_secr   )r   r_   r   r   )r   r_   r   r	  )r   rU   r   r   r   updater   r   INVALID_ATTRIBUTES_MSGr   r   r   rh   r\   r   rc   r  r   r6   r   r   ra   SUCCESS_COMPLETEr   SCHEDULED_SUCCESSCOMMITTED_SUCCESS)r   rV   	curr_resp	curr_attrinp_attr
diff_tupler<   r   attr_registryr  r_   r   r   r  r   
job_failedr   job_dict	wait_times                      r    attributes_configr"    sd   &{3IlB/I}}  .H)4JDa=a=DG+K8M+M4@AD5K`ghN3K>$[1GNN44[A	33  ,<VTX Y99 *+v>-- 3R8<<=RTVWK.v{G[YFO6"6;7(X(_(_`s(t$(  *==Z(3M]111@!'!2!23E!F4H0JXy   V L(8M^_gMhrvw(9&RVW
 1 8 89J9J<9X Y"D  2r"   c                 n    | j                   j                  d      dk  r| j                  t               y y )Nr  r   r   )r   rU   	fail_jsonNEGATIVE_TIMEOUT_MESSAGE)r   s    r    validate_negative_job_time_outr'    s1    }}+,156 2r"   c                  v   ddiddiddgddddiddiddd	dd
g dddddddddddddiddidddgddddddddd} | j                  t               t        | dgdgg dg dgd      }t        |       	 i }|j                  j                  d      t        |j                        5 }t        ||      }d\  }}|j                  d      dk(  rd}|j                  d       d!k(  rd"}n|j                  d      d#k(  rd}d d d        |j                  |$       y t        |j                  d%      5 }|j                  j                  d&      rt        ||       |j                  j                  d'      rt        ||       |j                  j                  d(      rt        ||       d d d        |j                  t        )       y # 1 sw Y   xY w# 1 sw Y   ,xY w# t        $ r9}|j                  t!        |      t#        j$                  |      *       Y d }~y d }~wt&        $ r@}|j(                  r|j(                  n
t!        |      }|j                  |d+       Y d }~y d }~wt*        t,        t.        t0        t2        t4        t6        f$ r%}	|j                  t!        |	      ,       Y d }	~	y d }	~	ww xY w)-Nr&   r1   	share_pwdT)r&   aliasesno_logr5   listraw)r&   elementsr   )r   r   AtMaintenanceWindowStartInMaintenanceWindowOnReset)r&   r/   choices)r&   r'   r2   )r   r   )r&   optionsr3   graceful_restartforce_restart)r&   r1  r/   )r&   r/   i  )
share_name
share_usershare_password	share_mntr  r   r	  r   clear_pendingr   r   r  r  )r   r  r9  r   )r	  r/  r   )r	  r0  r:  )argument_specmutually_exclusiverequired_one_ofrequired_ifsupports_check_moder   )FFStatusSuccessMessagezNo changes found to commit!FFailed)r   r   r   )req_sessionr9  r   r  r   )r   
error_info)r   unreachabler$  )r  r   r   r'  r   rU   r   r!   r   r   r   r   r"  r   r
   r%  r1   jsonloadr	   reasonRuntimeErrorr   r   KeyErrorImportError
ValueError	TypeError)
specsr   r   r   r   r   rV   errmessagees
             r    mainrS    s   uouo#(k]dSe_v&!'U;$"tv'-BGUY9Z@ESW7X+Z[ !&)v&$2Do1Vcuv#5%*t<!E$ 
LL"#YZVWXZ\ "F #6*%==^,8 / "5,UF;".778$	1"Gwwy)-JJ"'WWX&(2!F" gfE DA ;[==$$_5&v{;==$$\2v{3==$$\2%fk:; 7%" "; ;  BSX$))C.AA 8 #

#**CW$77,oxY0 %SV$$%sh   <2G$ .AGG$  G$ 7A6G-G$ GG$ G!G$ $	J8-/H!!J8-6I((+J8J33J8__main__)[
__future__r   r   r   r&   __metaclass__DOCUMENTATIONEXAMPLESRETURNrl   r   r   r   r   r   rf   ru   r  rS   ra   r   iDRAC9_LC_LOGiDRAC8_LC_LOGr   r   r   r   r   r   r  r  r  r   r   r   r   r   FORCE_BIOS_DELETEr  r   r   r   r&  POWER_CHECK_RETRIESPOWER_CHECK_INTERVALrG  rz   0ansible.module_utils.common.dict_transformationsr   +ansible.module_utils.six.moves.urllib.errorr	   r
   ansible.module_utils.urlsr   r   Iansible_collections.dellemc.openmanage.plugins.module_utils.dellemc_idracr   r   Iansible_collections.dellemc.openmanage.plugins.module_utils.idrac_redfishr   ansible.module_utils.basicr   Aansible_collections.dellemc.openmanage.plugins.module_utils.utilsr   r   r!   r   r:   r9   r\   rc   rh   ro   rx   r   r   r   r   r   r   r   r   r   r   r   r  r  r"  r'  rS  __name__r,   r"   r    <module>rg     s   C B~@iV;
z 5
57In X EU=REKQB66N 2,CE T r > h l O U ] O ; X O ]      K K I x e 44,


 ;NXl 0"#L7=*<C,#"02f7
9%x zF r"   