
    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mZmZ d dlmZmZ d dlmZmZ d d	lmZmZmZ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$dZ%dZ&dZ'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'Z8d(Z9d)Z:d*Z;d+d,d-d.Z<d/d0gZ= G d1 d2      Z> G d3 d4e>      Z? G d5 d6e>      Z@ G d7 d8      ZA G d9 d:      ZBd; ZCd< ZDeEd=k(  r eC        yy)>    )absolute_importdivisionprint_functiona  
---
module: idrac_diagnostics
short_description: Run and Export iDRAC diagnostics
version_added: "9.0.0"
description:
  - This module allows you to run and export diagnostics on iDRAC.
extends_documentation_fragment:
  - dellemc.openmanage.idrac_x_auth_options
options:
  run:
    description:
      - Run the diagnostics job on iDRAC.
      - Run the diagnostics job based on the I(run_mode) and save the report in the internal storage. I(reboot_type) is applicable.
    type: bool
  export:
    description:
      - Exports the diagnostics information to the given share.
      - This operation requires I(share_parameters).
      - When I(run) is C(true) and I(job_wait) is C(false), only then the run diagnostics job is triggered. I(export) is ignored.
    type: bool
  run_mode:
    description:
      - This option provides the choices to run the diagnostics.
      - C(express) The express diagnostics runs a test package for each server subsystem. However,
        it does not run the complete set of tests available in the package for each subsystem.
      - C(extended) The extended diagnostics run all available tests in each test package for all subsystems.
      - C(long_run) The long-run diagnostics runs express and extended tests.
    type: str
    choices: [express, extended, long_run]
    default: express
  reboot_type:
    description:
      - This option provides the choice to reboot the host immediately to run the diagnostics.
      - This is applicable when I(run) is C(true).
      - C(force) Forced graceful shutdown signals the operating system to turn off and wait for ten minutes.
        If the operating system does not turn off, the iDRAC power cycles the system.
      - C(graceful) Graceful shutdown waits for the operating system to turn off and wait for the system to restart.
      - C(power_cycle) performs a power cycle for a hard reset on the device.
    type: str
    choices: [force, graceful, power_cycle]
    default: graceful
  scheduled_start_time:
    description:
      - Schedules the job at the specified time.
      - The accepted formats are yyyymmddhhmmss and YYYY-MM-DDThh:mm:ss+HH:MM.
      - This is applicable when I(run) is C(true) and I(reboot_type) is power_cycle.
    type: str
  scheduled_end_time:
    description:
      - Run the diagnostic until the specified end date and end time after the I(scheduled_start_time).
      - The accepted formats are yyyymmddhhmmss and YYYY-MM-DDThh:mm:ss+HH:MM.
      - If the run operation does not complete before the specified end time, then the operation fails.
      - This is applicable when I(run) is C(True) and I(reboot_type) is C(power_cycle).
    type: str
  job_wait:
    description:
      - Provides the option to wait for job completion.
      - This is applicable when I(run) is C(true) and I(reboot_type) is C(power_cycle).
      - This is applicable only to run the diagnostics job.
    type: bool
    default: true
  job_wait_timeout:
    description:
      - Time in seconds to wait for job completion.
      - This is applicable when I(job_wait) is C(true).
    type: int
    default: 1200
  share_parameters:
    description:
      - Parameters that are required for the export operation of diagnostics.
      - I(share_parameters) is required when I(export) is C(true).
    type: dict
    suboptions:
      share_type:
        description:
          - Share type of the network share.
          - C(local) uses local path for I(export) operation.
          - C(nfs) uses NFS share for I(export) operation.
          - C(cifs) uses CIFS share for I(export) operation.
          - C(http) uses HTTP share for I(export) operation.
          - C(https) uses HTTPS share for I(export) operation.
        type: str
        choices: [local, nfs, cifs, http, https]
        default: local
      file_name:
        description:
          - Diagnostics file name for I(export) operation.
        type: str
      ip_address:
        description:
          - IP address of the network share.
          - I(ip_address) is required when I(share_type) is C(nfs), C(cifs), C(http) or C(https).
        type: str
      share_name:
        description:
          - Network share or local path of the diagnostics file.
        type: str
      workgroup:
        description:
          - Workgroup of the network share.
          - I(workgroup) is applicable only when I(share_type) is C(cifs).
        type: str
      username:
        description:
          - Username of the network share.
          - I(username) is required when I(share_type) is C(cifs).
        type: str
      password:
        description:
          - Password of the network share.
          - I(password) is required when I(share_type) is C(cifs).
        type: str
      ignore_certificate_warning:
        description:
          - Ignores the certificate warning while connecting to Share and is only applicable when I(share_type) is C(https).
          - C(on) ignores the certificate warning.
          - C(off) does not ignore the certificate warning.
        type: str
        choices: ["off", "on"]
        default: "off"
      proxy_support:
        description:
          - Specifies if proxy support must be used or not.
          - C(off) does not use proxy settings.
          - C(default_proxy) uses the default proxy settings.
          - C(parameters_proxy) uses the specified proxy settings. I(proxy_server) is required when I(proxy_support) is C(parameters_proxy).
          - I(proxy_support) is only applicable when I(share_type) is C(http) or C(https).
        type: str
        choices: ["off", "default_proxy", "parameters_proxy"]
        default: "off"
      proxy_type:
        description:
          - The proxy type of the proxy server.
          - C(http) to select HTTP proxy.
          - C(socks) to select SOCKS proxy.
          - I(proxy_type) is only applicable when I(share_type) is C(http) or C(https) and when I(proxy_support) is C(parameters_proxy).
        type: str
        choices: [http, socks]
        default: http
      proxy_server:
        description:
          - The IP address of the proxy server.
          - I(proxy_server) is required when I(proxy_support) is C(parameters_proxy).
          - I(proxy_server) is only applicable when I(share_type) is C(http) or C(https) and when I(proxy_support) is C(parameters_proxy).
        type: str
      proxy_port:
        description:
          - The port of the proxy server.
          - I(proxy_port) is only applicable when I(share_type) is C(http) or C(https) and when I(proxy_support) is C(parameters_proxy).
        type: int
        default: 80
      proxy_username:
        description:
          - The username of the proxy server.
          - I(proxy_username) is only applicable when I(share_type) is C(http) or C(https) and when I(proxy_support) is C(parameters_proxy).
        type: str
      proxy_password:
        description:
          - The password of the proxy server.
          - I(proxy_password) is only applicable when I(share_type) is C(http) or C(https) and when I(proxy_support) is C(parameters_proxy).
        type: str
  resource_id:
    type: str
    description:
      - Id of the resource.
      - If the value for resource ID is not provided, the module picks the first resource ID available from the list of system resources returned by the iDRAC.
requirements:
  - "python >= 3.9.6"
author:
  - "Shivam Sharma(@ShivamSh3)"
notes:
    - Run this module from a system that has direct access to Dell iDRAC.
    - This module supports only iDRAC9 and above.
    - This module supports IPv4 and IPv6 addresses.
    - This module supports C(check_mode).
    - This module requires 'Dell Diagnostics' firmware package to be present on the server.
    - When I(share_type) is C(local) for I(export) operation, job_details are not displayed.
a	  
---
- name: Run and export the diagnostics to local path
  dellemc.openmanage.idrac_diagnostics:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "path/to/ca_file"
    run: true
    export: true
    share_parameters:
      share_type: "local"
      share_path: "/opt/local/diagnostics/"
      file_name: "diagnostics.txt"

- name: Run the diagnostics with power cycle reboot on schedule
  dellemc.openmanage.idrac_diagnostics:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "path/to/ca_file"
    run: true
    run_mode: "express"
    reboot_type: "power_cycle"
    scheduled_start_time: 20240101101015

- name: Run and export the diagnostics to HTTPS share
  dellemc.openmanage.idrac_diagnostics:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "path/to/ca_file"
    run: true
    export: true
    share_parameters:
      share_type: "HTTPS"
      ignore_certificate_warning: "on"
      share_name: "/share_path/diagnostics_collection_path"
      ip_address: "192.168.0.2"
      file_name: "diagnostics.txt"

- name: Run and export the diagnostics to NFS share
  dellemc.openmanage.idrac_diagnostics:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "path/to/ca_file"
    run: true
    export: true
    share_parameters:
      share_type: "NFS"
      share_name: "nfsshare/diagnostics_collection_path/"
      ip_address: "192.168.0.3"
      file_name: "diagnostics.txt"

- name: Export the diagnostics to CIFS share
  dellemc.openmanage.idrac_diagnostics:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "path/to/ca_file"
    export: true
    share_parameters:
      share_type: "CIFS"
      share_name: "/cifsshare/diagnostics_collection_path/"
      ip_address: "192.168.0.4"
      file_name: "diagnostics.txt"

- name: Export the diagnostics to HTTPS share via proxy
  dellemc.openmanage.idrac_diagnostics:
    hostname: "192.168.0.1"
    username: "username"
    password: "password"
    ca_path: "path/to/ca_file"
    export: true
    share_parameters:
      share_type: "HTTPS"
      share_name: "/share_path/diagnostics_collection_path"
      ignore_certificate_warning: "on"
      ip_address: "192.168.0.2"
      file_name: "diagnostics.txt"
      proxy_support: parameters_proxy
      proxy_type: http
      proxy_server: "192.168.0.5"
      proxy_port: 1080
      proxy_username: "proxy_user"
      proxy_password: "proxy_password"
a  
---
msg:
  type: str
  description: Status of the diagnostics operation.
  returned: always
  sample: "Successfully ran and exported the diagnostics."
job_details:
    description: Returns the output for status of the job.
    returned: For run and export operations
    type: dict
    sample: {
        "ActualRunningStartTime": "2024-01-10T10:14:31",
        "ActualRunningStopTime": "2024-01-10T10:26:34",
        "CompletionTime": "2024-01-10T10:26:34",
        "Description": "Job Instance",
        "EndTime": "2024-01-10T10:30:15",
        "Id": "JID_XXXXXXXXXXXX",
        "JobState": "Completed",
        "JobType": "RemoteDiagnostics",
        "Message": "Job completed successfully.",
        "MessageArgs": [],
        "MessageArgs@odata.count": 0,
        "MessageId": "SYS018",
        "Name": "Remote Diagnostics",
        "PercentComplete": 100,
        "StartTime": "2024-01-10T10:12:15",
        "TargetSettingsURI": null
    }
diagnostics_file_path:
  description: Returns the full path of the diagnostics file.
  returned: For export operation
  type: str
  sample: "/share_path/diagnostics_collection_path/diagnostics.txt"
error_info:
  description: Details of the HTTP Error.
  returned: on HTTP error
  type: dict
  sample: {
    "error": {
      "code": "Base.1.12.GeneralError",
      "message": "A general error has occurred. See ExtendedInfo for more information.",
      "@Message.ExtendedInfo": [
        {
          "Message": "A Remote Diagnostic (ePSA) job already exists.",
          "MessageArgs": [],
          "MessageArgs@odata.count": 0,
          "MessageId": "IDRAC.2.9.SYS098",
          "RelatedProperties": [],
          "RelatedProperties@odata.count": 0,
          "Resolution": "A response action is not required if the scheduled start time of the existing Remote Diagnostic (ePSA) job is ok.
           Else, delete the existing Diagnostics (ePSA) job and recreate another with an appropriate start time.",
          "Severity": "Informational"
        }
      ]
    }
  }
N)iDRACRedfishAPIIdracAnsibleModule)URLError	HTTPError)ConnectionErrorSSLValidationError)config_ipv6get_current_timeget_dynamic_uri&validate_and_get_first_resource_id_uri
remove_keyidrac_redfish_job_tracking)datetimez/redfish/v1/ManagersOemDellJobsz?$expand=*($levels=1)DellLCServiceActionsz*#DellLCService.ExportePSADiagnosticsResultz!#DellLCService.RunePSADiagnosticsz#DellLCService.TestNetworkSharez(.*?)@odataz	@odata.idz@Message.ExtendedInfoz%Y%m%d_%H%M%Sz%Y%m%d%H%M%Sz%Y-%m-%dT%H:%M:%S%zz&Successfully exported the diagnostics.z+Successfully ran the diagnostics operation.z.Successfully ran and exported the diagnostics.z2Successfully triggered the job to run diagnostics.z'The diagnostics job is already present.z.Provided directory path '{path}' is not valid.zThe operation is skipped.zkProvided directory path '{path}' is not writable. Please check if the directory has appropriate permissionsz(iDRAC firmware version is not supported.zBThe parameter `job_wait_timeout` value cannot be negative or zero.z*The job is not complete after {0} seconds.z[The specified scheduled time occurs in the past, provide a future time to schedule the job.zhThe specified date and time `{0}` to schedule the diagnostics is not valid. Enter a valid date and time.zYThe end time `{0}` to schedule the diagnostics must be greater than the start time `{1}`.zChanges found to be applied.z$The diagnostics file does not exist.OffDefaultProxyParametersProxyoffdefault_proxyparameters_proxy      c                   *    e Zd Zd Zd Zd Zd Zd Zy)Diagnosticsc                 f    || _         || _        d | _        d | _        d | _        d | _        d | _        y N)idracmodulediagnostics_file_pathrun_url
export_url
share_name	file_nameselfr%   r&   s      x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/openmanage/plugins/modules/idrac_diagnostics.py__init__zDiagnostics.__init__  s4    
%)"    c                      y r$    r-   s    r.   executezDiagnostics.execute  s    r0   c                 T   i }| j                   j                  j                  d      j                  d      j                         |d<   | j                   j                  j                  d      j                  d      |d<   | j                   j                  j                  d      j                  d      |d<   | j                   j                  j                  d      j                  d      |d	<   | j                   j                  j                  d      j                  d
      |d<   | j                   j                  j                  d      j                  d      |d<   | j                   j                  j                  d      j                  d      j	                         |d<   | j                   j                  j                  d      j                  d      dk(  rt
        | j                   j                  j                  d      j                  d         |d<   | j                   j                  j                  d      j                  d      j                         |d<   | j                   j                  j                  d      j                  d      |d<   t        | j                   j                  j                  d      j                  d            |d<   | j                   j                  j                  d      j                  d      r| j                   j                  j                  d      j                  d      rn| j                   j                  j                  d      j                  d      |d<   | j                   j                  j                  d      j                  d      |d<   |S )Nshare_parameters
share_type	ShareType
ip_address	IPAddressr*   	ShareNameusernameUserNamepasswordPasswordr+   FileNameignore_certificate_warningIgnoreCertWarningproxy_supportr   ProxySupport
proxy_type	ProxyTypeproxy_serverProxyServer
proxy_port	ProxyPortproxy_usernameproxy_password
ProxyUnameProxyPasswd)r&   paramsgetupper
capitalizePROXY_SUPPORTstr)r-   payloads     r.   get_payload_detailszDiagnostics.get_payload_details  s   #{{11556HIMMl[aac#{{11556HIMMl[#{{11556HIMMl["kk00445GHLLZX
"kk00445GHLLZX
"kk00445GHLL[Y
'+{{'9'9'='=>P'Q'U'UVr's'~'~  (A#$;;!!"4599/JN``&3DKK4F4F4J4JK]4^4b4bcr4s&tGN##';;#5#5#9#9:L#M#Q#QR^#_#e#e#gGK %)[[%7%7%;%;<N%O%S%STb%cGM"#&t{{'9'9'='=>P'Q'U'UVb'c#dGK {{!!%%&89==>NOTXT_T_TfTfTjTjk}T~  UC  UC  DT  UU(,(:(:(>(>?Q(R(V(VWg(h%)-););)?)?@R)S)W)WXh)i&r0   c                    | j                         }|d= |j                         D ci c]  \  }}|	|| }}}|j                  d      dk(  r|j                  d      }t        j                  j                  |      s1| j                  j                  t        j                  |      d       t        j                  |t        j                        s2| j                  j                  t        j                  |      d       y y 	 | j                         }| j                  j                  |d|	       y c c}}w # t         $ r}t#        t%        j&                  |      t(        
      }|j                  d      j                  t*              d   }|j                  d      }	| j                  j                  |	|d       Y d }~y d }~ww xY w)Nr@   r8   LOCALr;   )pathTmsgfailedPOSTdataregex_patternerrorr   Messager[   
error_infor\   )rV   itemsrP   osrY   existsr&   	exit_jsonINVALID_DIRECTORY_MSGformataccessW_OK%INSUFFICIENT_DIRECTORY_PERMISSION_MSGget_test_network_share_urlr%   invoke_requestr	   r   jsonloadODATA_REGEXMESSAGE_EXTENDED_INFO)
r-   rU   keyvaluerY   test_urlerr
filter_errmessage_detailsmessages
             r.   test_network_sharezDiagnostics.test_network_share  s{   **,J07U*#u5CT3:UU;;{#w.;;{+DGGNN4(%%*?*F*FD*F*QZ^%_99T277+%%*O*V*V\`*V*ajn%o ,W::<

))(F)I V  W'		#kR
",.."9"="=>S"TUV"W)--i8%%'jQU%VV	Ws#   
D6D6.D< <	G	A:GG	c                 $   t        | j                  | j                  t              \  }}|r| j                  j	                  |d       t        | j                  |      }|j                  di       j                  t        i       j                  t        i       j                  t        i       j                  t        i       }t        | j                  |      }|j                  t        i       j                  t        i       j                  di       }|S NTrZ   Linkstarget)r   r&   r%   MANAGERS_URIri   r   rP   OEMMANUFACTURER
LC_SERVICEODATAACTIONS
TEST_SHARE)r-   uri	error_msgrespurlaction_resps         r.   ro   z&Diagnostics.get_test_network_share_url  s    ?KK\3YKK!!i!=tzz3/hhw#''R044\2FJJ:WYZ^^_dfhi%djj#6oogr*..z2>BB8RP
r0   N)__name__
__module____qualname__r/   r4   rV   r|   ro   r2   r0   r.   r"   r"     s    &W(	r0   r"   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)RunDiagnosticsc                    d\  }}| j                   j                  j                  d      r| j                          | j	                          | j                          | j                          | j                         }| j                  |      }|j                  }|t        v r|j                  d      dk(  rt        }|}|t        v r|j                  d      dv rt        }|}||d fS )N)NNexportJobState	Completed)	Scheduled
SchedulingRunningNew)r&   rO   rP   r|   (_RunDiagnostics__get_run_diagnostics_urlcheck_diagnostics_jobs%_RunDiagnostics__validate_job_timeout _RunDiagnostics__run_diagnostics!_RunDiagnostics__perform_job_waitstatus_codeSTATUS_SUCCESSSUCCESS_RUN_MSGRUNNING_RUN_MSG)r-   r[   job_detailsrun_diagnostics_status
job_statusstatuss         r.   r4   zRunDiagnostics.execute  s    %[;;!!(+##%&&(##%##%!%!7!7!9,,-CD
'33^#
z(Bk(Q!C$K^#
z(BFs(s!C$KK%%r0   c                    dddd}dddd}i }| j                   j                  j                  d	      }| j                   j                  j                  d
      }|dk(  r?| j                   j                  j                  d      rJ| j                  | j                   j                  j                  d            }| j	                  |      r||d<   | j                   j                  j                  d      rJ| j                  | j                   j                  j                  d            }| j	                  |      r||d<   | j                   j                  j                  d      r<| j                   j                  j                  d      r| j                        r||d<   |j                  |      |d<   |j                  |      |d<   | j                  j                  | j                  d|      }|S )N#GracefulRebootWithoutForcedShutdown GracefulRebootWithForcedShutdown
PowerCycle)gracefulforcepower_cycleExpressExtendedExpressAndExtendedexpressextendedlong_runreboot_typerun_moder   scheduled_start_timeScheduledStartTimescheduled_end_time	UntilTimeRebootJobTypeRunModer]   r^   )	r&   rO   rP   %_RunDiagnostics__validate_time_format_RunDiagnostics__validate_time"_RunDiagnostics__validate_end_timer%   rp   r(   )	r-   reboot_job_types	run_modesrU   r   r   
start_timeend_timer   s	            r.   __run_diagnosticsz RunDiagnostics.__run_diagnostics  s   =7'
 !",
	
 kk((,,];;;%%))*5-'{{!!%%&<=!889K9K9O9OPf9gh
''
34>G01{{!!%%&:;66t{{7I7I7M7MNb7cd''1+3GK(""&&'=>4;;CUCUCYCYZnCo++JA'/$#3#7#7#D &]]84	!%!:!:4<<V]!:!^%%r0   c                 x   t        | j                  | j                  t              \  }}|r| j                  j	                  |d       t        | j                  |      }|j                  di       j                  t        i       j                  t        i       j                  t        i       j                  t        i       }|rXt        | j                  |      }|j                  t        i       j                  t        i       j                  di       }|| _        y | j                  j	                  t        d       y r~   )r   r&   r%   r   ri   r   rP   r   r   r   r   r   RUNr(   UNSUPPORTED_FIRMWARE_MSG)r-   r   r   r   r   r   r(   s          r.   __get_run_diagnostics_urlz(RunDiagnostics.__get_run_diagnostics_url  s    ?KK\3YKK!!i!=tzz3/hhw#''R044\2FJJ:WYZ^^_dfhi)$**c:K!oogr266sB?CCHbQG"DLKK!!&>t!Lr0   c                     | j                   j                  j                  d      rK| j                   j                  j                  d      dk  r"| j                   j                  t        d       y y y )Njob_waitjob_wait_timeoutr   TrZ   )r&   rO   rP   ri   TIMEOUT_NEGATIVE_OR_ZERO_MSGr3   s    r.   __validate_job_timeoutz%RunDiagnostics.__validate_job_timeout  sY    ;;!!*-$++2D2D2H2HI[2\`a2aKK!!&B4!P 3b-r0   c           	      P   i }| j                   j                  j                  d      }| j                   j                  j                  d      }|j                  j                  d      }|r;|j	                  d      d   }t        | j                   | j                  t              }|d    dt         dt         dt         d| 	}|rt        | j                  ||d      \  }	}
}}t        |t        	      }t        |      t        |      k\  r1| j                   j                  t         j#                  |      d
|       |	r-| j                   j                  |j                  d      |d
       |S | j                  j%                  |d      }|j&                  }t        |t        	      }|S )Nr   r   Location/r      )max_job_wait_secsleep_interval_secsr`   T)r[   changedr   rc   )r[   r   r\   GET)r&   rO   rP   headerssplitr   r%   r   r   r   JOBSr   r   rs   intri   WAIT_TIMEOUT_MSGrk   rp   	json_data)r-   r   job_dictr   r   job_tracking_urijob_idres_urijob_uri
job_failedr[   	wait_timejob_resps                r.   __perform_job_waitz!RunDiagnostics.__perform_job_wait  s   ;;%%))*5;;--112DE199==jI%++C04F<T[[$**VbcG AcU!L>4&&JG7QRVR\R\^ecsfg8i4
C9 &hkJy>S)9%::KK)).>.E.E(/*37H * NKK))$LL3QU * W   ::44WeD#--%hkJr0   c                 :   	 t        j                  |t              }j                  t              }|S # t        $ r^ 	 t        j                  |t              }n?# t        $ r3 | j
                  j                  dt        j                  |             Y nw xY wY }w xY wNT)r\   r[   )
r   strptimeTIME_FORMAT_WITH_OFFSET
ValueErrorTIME_FORMAT_WITHOUT_OFFSETr&   ri   INVALID_TIMErk   strftime)r-   timedatetime_objformatted_times       r.   __validate_time_formatz%RunDiagnostics.__validate_time_format+  s    	R#,,T3JKL &../IJ  	RR'007QR R%%T|7J7J47P%QR	Rs2   3 	BAB9BBBBBc                 F   t        | j                        \  }}t        j                  |t              }|j                  t              }t        j                  |t              }t        j                  |t              }||k  r!| j                  j                  dt               yr   )
r   r%   r   r   r   r   r   r&   ri   
START_TIME)r-   r   curr_idrac_timeoffsetcurrtime_objstarttime_objs         r.   __validate_timezRunDiagnostics.__validate_time6  s    "24::">"++O=TU)223MN((:TU ))$0JK<'KK!!:!>r0   c                     t        j                  |t              }t        j                  |t              }||kD  r1| j                  j	                  dt
        j                  ||             yr   )r   r   r   r&   ri   END_START_TIMErk   )r-   r   r   r   endtime_objs        r.   __validate_end_timez"RunDiagnostics.__validate_end_time@  sX     ))*6PQ''2LM;&KK!!>3H3HS]3^!_r0   c                    t        | j                  | j                  t              }|d    dt         dt
         dt         t         }| j                  j                  |d      }|j                  j                  dg       }d}|D ]B  }|j                  d      dk(  s|j                  d      d	v s,|d
   }t        |t              } n | j                  j                  r$|r"| j                  j                  t        d       | j                  j                  r#|s!| j                  j                  t         d       |r#| j                  j                  t        d       y y )Nr   r   r   Members JobTypeRemoteDiagnosticsr   )r   r   Startingr   Idr`   T)r[   r   skippedr[   r   )r   r&   r%   r   r   r   r   JOBS_EXPANDrp   r   rP   r   rs   
check_moderi   ALREADY_RUN_MSGCHANGES_FOUND_MSG)r-   r   r   r   job_listr   jbr   s           r.   r   z%RunDiagnostics.check_diagnostics_jobsG  s.   8djjR^_QZL#a~Qtf[MJ::,,We<%%)))R8 	Bvvi $77BFF:<NR}<}D%bD		
 ;;!!fKK!!o8UY!Z;;!!&KK!!&7!FKK!!o8UY!Z r0   N)r   r   r   r4   r   r   r   r   r   r   r   r   r2   r0   r.   r   r     s2    &$&>MQ4	[r0   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)ExportDiagnosticsc                 (   | j                          | j                          | j                  j                  r| j	                          i }| j                  j
                  j                  d      j                  d      }| j                  | j                  | j                  | j                  | j                  d} ||          }|dk7  r| j                  |      }|j                  }| j                   d| j                   }|t        v rt         }|}|||fS y )Nr6   r7   )localhttphttpscifsnfsr  r   )r|   ._ExportDiagnostics__get_export_diagnostics_urlr&   r  perform_check_moderO   rP   ,_ExportDiagnostics__export_diagnostics_local+_ExportDiagnostics__export_diagnostics_http+_ExportDiagnostics__export_diagnostics_cifs*_ExportDiagnostics__export_diagnostics_nfsget_job_statusr   r*   r+   r   SUCCESS_EXPORT_MSG)	r-   r   r7   share_type_methodsexport_diagnostics_statusr   r'   r[   r   s	            r.   r4   zExportDiagnostics.execute\  s   !))+;;!!##%
[[''++,>?CCLQ
4422332200
 %C$6z$B$D! ,,-FGJ*66#'??"31T^^4D E^#$C$K%::: $r0   c                 L   i }d|d<   | j                   j                  j                  d      j                  d      }|j                  d      | _        | j                  |      }|j                  d      }| j                  j                  |j                  j                  d      d      }t        j                  j                  ||      }t        |d	      5 }|j                  |j                  j                         j!                  d
d             d d d        |S # 1 sw Y   |S xY w)NLocalr8   r6   r*   r   r@   r   r   wr   )r&   rO   rP   rstripr*   &_ExportDiagnostics__export_diagnosticsr%   rp   r   rg   rY   joinopenwritebodydecodereplace)r-   rU   	file_pathdiagnostics_statusdiagnostics_file_namediagnostics_datar+   fps           r.   __export_diagnostics_localz,ExportDiagnostics.__export_diagnostics_localt  s    &KK&&**+=>BB<P	#**3/!66w? 'J 7::445G5O5O5S5ST^5_afgGGLL,AB	)S! 	GRHH%**113;;D"EF	G!!	G!!s   :DD#c                 >   | j                         }| j                  |      }| j                  j                  j	                  d      }t        |j	                  d            }|j	                  d       d| d|j	                  d      j                  d       | _        |S )Nr6   r9   r7   z://r   r*   )rV   r#  r&   rO   rP   r   stripr*   )r-   rU   export_statusshareips        r.   __export_diagnostics_httpz+ExportDiagnostics.__export_diagnostics_http  s    **,11':""&&'9:<01"YY|45SAeii>U>[>[\_>`=abr0   c                 B   | j                         }| j                  j                  j                  d      j                  d      r7| j                  j                  j                  d      j                  d      |d<   | j	                  |      }| j                  j                  j                  d      j                  d      j                  dd      }d| j                  j                  j                  d      j                  d       d|j                  d       | _        |S )	Nr6   	workgroup	Workgroupr*   \r   z//r9   )rV   r&   rO   rP   r#  r)  r1  r*   )r-   rU   r2  r*   s       r.   __export_diagnostics_cifsz+ExportDiagnostics.__export_diagnostics_cifs  s    **,;;!!"4599+F#';;#5#5#9#9:L#M#Q#QR]#^GK 11':[[''++,>?CCLQYYZ^`cd
t{{11556HIMMl[\\]^h^n^nor^s]tur0   c                    | j                         }|d= |d= | j                  |      }| j                  j                  j	                  d      }|j	                  d       d|j	                  d      j                  d       | _        |S )Nr=   r?   r6   r9   z:/r*   r   )rV   r#  r&   rO   rP   r1  r*   )r-   rU   r2  r3  s       r.   __export_diagnostics_nfsz*ExportDiagnostics.__export_diagnostics_nfs  s    **,J!411':""&&'9:"YY|45R		,8O8U8UVY8Z7[\r0   c                 x   t        | j                  | j                  t              \  }}|r| j                  j	                  |d       t        | j                  |      }|j                  di       j                  t        i       j                  t        i       j                  t        i       j                  t        i       }|rXt        | j                  |      }|j                  t        i       j                  t        i       j                  di       }|| _        y | j                  j	                  t        d       y r~   )r   r&   r%   r   ri   r   rP   r   r   r   r   r   EXPORTr)   r   )r-   r   r   r   r   r   r)   s          r.   __get_export_diagnostics_urlz.ExportDiagnostics.__get_export_diagnostics_url  s    ?KK\3YKK!!i!=tzz3/hhw#''R044\2FJJ:WYZ^^_dfhi)$**c:K$"599&"EII(TVWJ(DOKK!!&>t!Lr0   c                    | j                   j                  j                  d      j                  d      }|swt        j                         }| j                   j                  j                  d      }| j                  |      }|j                  dd      }| d|j                  t               d}||d<   || _	        | j                  j                  | j                  d	|
      }|S )Nr6   r+   idrac_ip:._z.txtr@   r]   r^   )r&   rO   rP   r   nowexpand_ipv6r)  r   TIME_FORMAT_FILEr+   r%   rp   r)   )r-   rU   r,  rE  hostnamer+  s         r.   __export_diagnosticsz&ExportDiagnostics.__export_diagnostics  s     $ 2 2 6 67I J N N{ [$,,.C{{))--j9H''1H''S1H'/j#,,?O2P1QQU$V!3
.!ZZ66tU\6]!!r0   c           	         t        | j                  | j                  t              }|j                  j                  d      }|j                  d      d   }|d    dt         dt         dt         d| 	}t        | j                  |      \  }}}}	t        |t              }|r-| j                  j                  |j                  d      d|       |S )	Nr   r   r   r   r`   rc   T)r[   r\   r   )r   r&   r%   r   r   rP   r   r   r   r   r   r   rs   ri   )
r-   r  r   r   r   r   r   r[   r   r   s
             r.   r  z ExportDiagnostics.get_job_status  s    8djjR^_4<<@@L!'',R0QZL#a~QtfAfXF/I$**V]/^,
C9hkBKK!!hll9&=dX`!ar0   c                    	 i }d|d<   | j                   j                  | j                  d|      }|j                  t        v r"| j
                  j                  t        d       y y # t        $ r}t        t        j                  |      t              }|j                  d      j                  t              d	   }|j                  d
      }d|v r&| j
                  j                  t        d       Y d }~y Y d }~y d }~ww xY w)Nr  r8   r]   r^   Tr  r`   rb   r   	MessageIdSYS099r[   r  )r%   rp   r)   r   r   r&   ri   r	  r	   r   rq   rr   rs   rP   rt   NO_FILE)r-   rU   r2  rx   ry   rz   
message_ids          r.   r  z$ExportDiagnostics.perform_check_mode  s    	AG#*GK  JJ55doovT[5\M((N:%%*;T%J ; 	A#DIIcN+NJ(nnW599:OPQRSO(,,[9J:%%%'4%@@ &		As   A"A& &	C?/BC::C?c                    |j                  d      }t        |      }d|v r|j                  d      nd}|dk7  rd|z
  dz   }dg|z  |||dz    |D cg c]  }|j                  d       }}dj	                  |      }|S c c}w )NrB  r   r      r   0000   )r   lenindexzfillr$  )r-   r4  sectionsnum_sectionsdouble_colon_indexmissing_sectionssectionexpanded_ips           r.   rF  zExportDiagnostics.expand_ipv6  s    88C=8}35>X^^B/r# </!3CI(M]B]H'(:Q(>?4<=GMM!$==hhx( >s   A>N)r   r   r   r4   r  r  r  r  r  r#  r  r  rF  r2   r0   r.   r  r  Z  s6    ;0"M"	A	r0   r  c                       e Zd Zd Zd Zy)RunAndExportDiagnosticsc                 V    t        ||      | _        t        ||      | _        || _        y r$   )r   runr  r   r&   r,   s      r.   r/   z RunAndExportDiagnostics.__init__  s%    !%0'v6r0   c                     | j                   j                         \  }}}| j                  j                  j	                  d      r$| j
                  j                         \  }}}t        }|||fS )Nr   )ra  r4   r&   rO   rP   r   SUCCESS_RUN_AND_EXPORT_MSG)r-   r[   r   r*  s       r.   r4   zRunAndExportDiagnostics.execute  s^    %)XX%5%5%7"Z;;!!*-)-)<)<)>&CY,CJ	))r0   N)r   r   r   r/   r4   r2   r0   r.   r_  r_    s    
*r0   r_  c                   (    e Zd ZeeedZed        Zy)DiagnosticsType)ra  r   run_and_exportc                 r   d }|j                   j                  d      r|j                   j                  d      rd}n;|j                   j                  d      rd}n|j                   j                  d      rd}|r(t        j                  j                  |      } || |      S |j	                  t
        d       y )Nra  r   rf  TrN  )rO   rP   re  _diagnostics_classesri   NO_OPERATION_SKIP_MSG)r%   r&   
class_typediagnostics_classs       r.   diagnostics_operationz%DiagnosticsType.diagnostics_operation  s    
==U#(9(9((C)J]]u%J]]x(!J / D D H H T$UF33!6Er0   N)	r   r   r   r   r  r_  rh  staticmethodrl  r2   r0   r.   re  re    s)    #1 F Fr0   re  c                     t               } t        | ddggg dg dgd      }	 t        |j                        5 }t        j                  ||      }|j                         \  }}}||j                  |d|       |j                  |d||       d d d        y # 1 sw Y   y xY w# t        $ r}t        t        j                  |      t        	      }|j                  d
      j                  t              d   }	|	j                  d      }
d|
v r|j                  t        d       d|
v r"|j                  |	j                  d      d       |j                  t!        |      |d       Y d }~y d }~wt"        $ r&}|j                  t!        |      d       Y d }~y d }~wt$        t&        t(        t*        t,        f$ r&}|j                  t!        |      d       Y d }~y d }~ww xY w)Nra  r   )ra  T)r   r   )r   T)r6   T)argument_specrequired_one_ofrequired_ifsupports_check_mode)r[   r   r   )r[   r   r   r'   r`   rb   r   rL  rM  rN  SYS098rc   rd   )r[   unreachablerZ   )get_argument_specr   r   rO   re  rl  r4   ri   r	   r   rq   rr   rs   rP   rt   rO  rT   r   OSErrorr   r   r
   	TypeError)specsr&   r%   diagnostics_objr[   r   r*  rx   ry   rz   rP  es               r.   mainr{     s   E*+73
 !F2V]]+ 	mu-CCE6RO)8)@)@)B&CY   S$J Od
bkl	m 	m 	m  K		#kJ
$..1556KLQO$((5
z!$7z!!4!4Y!?NSX*TJJ 9SX488Z!3_iP 2SVD112sN   B$ ABB$ B!B$ !B$ $	G -B:E,,G 8F!G :GG c                  "   ddiddiddg ddddg ddddiddidd	d
ddd
dddg ddddddgdddidd	dddd
ddiddddgdddiddiddiddg ddddiddidd	ddddgdddggddddggddg dgddddggdd ddggd!d"d#gggd$ddid%
S )&NtypeboolrT   r   r   )r}  defaultchoicesr   )r   r   r   T)r}  r  r   i  dictr  )r  r  r  r  r  r  socks)r}  no_logP   r   onr   )r7   rE   r<   r>   rI   r+   rA   r9   rG   r7  rC   r*   rK   rL   )r<   r>   )rK   rL   r7   r*   r  r9   r  )r9   r*   r<   r>   r  rC   r   rG   )r}  optionsrequired_togetherrq  )
ra  r   r   r   r   r   r   r   r6   resource_idr2   r2   r0   r.   ru  ru  #  sp   6" :
 !;

 "(%uo#5%*t< "&H "% &0
 $UO%*d;',<$e_!$ %t}/
  &uo!'$e_!$K"
  &uo#)5/+0D"A=B )4"
 w7u|\&BCv'[\vl'CDw|(DE "4~6FGM.
^ AA Ar0   __main__)F
__future__r   r   r   r}  __metaclass__DOCUMENTATIONEXAMPLESRETURNrq   rg   Iansible_collections.dellemc.openmanage.plugins.module_utils.idrac_redfishr   r   +ansible.module_utils.six.moves.urllib.errorr   r	   ansible.module_utils.urlsr
   r   Aansible_collections.dellemc.openmanage.plugins.module_utils.utilsr   r   r   r   r   r   r   r   r   r   r   r  r   r   r>  r   r   rs   r   rt   rG  r   r   r  r   rc  r   r  rj   ri  rn   r   r   r   r   r   r   r	  rO  rS   r   r"   r   r  r_  re  r{  ru  r   r2   r0   r.   <module>r     sw   C BrhWr9
v  	 y K ID D %%

	5).
/ " + / = ?M F;H 3 )d %E c ? :
yl2 
0Tefs? ?DK[[ K[\} }@* *F F. 2FBJ zF r0   