
    Vh."                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZ d dlmZ g d	d
gg ddgdZd Zedk(  r e        yy)    )absolute_importdivisionprint_functionaa  
module: ocapi_command
version_added: 6.3.0
short_description: Manages Out-Of-Band controllers using Open Composable API (OCAPI)
description:
  - Builds OCAPI URIs locally and sends them to remote OOB controllers to perform an action.
  - Manages OOB controller such as Indicator LED, Reboot, Power Mode, Firmware Update.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  category:
    required: true
    description:
      - Category to execute on OOB controller.
    type: str
  command:
    required: true
    description:
      - Command to execute on OOB controller.
    type: str
  baseuri:
    required: true
    description:
      - Base URI of OOB controller.
    type: str
  proxy_slot_number:
    description: For proxied inband requests, the slot number of the IOM. Only applies if O(baseuri) is a proxy server.
    type: int
  update_image_path:
    required: false
    description:
      - For O(command=FWUpload), the path on the local filesystem of the firmware update image.
    type: str
  job_name:
    required: false
    description:
      - For O(command=DeleteJob) command, the name of the job to delete.
    type: str
  username:
    required: true
    description:
      - Username for authenticating to OOB controller.
    type: str
  password:
    required: true
    description:
      - Password for authenticating to OOB controller.
    type: str
  timeout:
    description:
      - Timeout in seconds for URL requests to OOB controller.
    default: 10
    type: int

author: "Mike Moerk (@mikemoerk)"
a'  
- name: Set the power state to low
  community.general.ocapi_command:
    category: Chassis
    command: PowerModeLow
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"

- name: Set the power state to normal
  community.general.ocapi_command:
    category: Chassis
    command: PowerModeNormal
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"
- name: Set chassis indicator LED to on
  community.general.ocapi_command:
    category: Chassis
    command: IndicatorLedOn
    baseuri: "{{ baseuri }}"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
- name: Set chassis indicator LED to off
  community.general.ocapi_command:
    category: Chassis
    command: IndicatorLedOff
    baseuri: "{{ baseuri }}"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
- name: Reset Enclosure
  community.general.ocapi_command:
    category: Systems
    command: PowerGracefulRestart
    baseuri: "{{ baseuri }}"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
- name: Firmware Upload
  community.general.ocapi_command:
    category: Update
    command: FWUpload
    baseuri: "iom1.wdc.com"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
    update_image_path: "/path/to/firmware.tar.gz"
- name: Firmware Update
  community.general.ocapi_command:
    category: Update
    command: FWUpdate
    baseuri: "iom1.wdc.com"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
- name: Firmware Activate
  community.general.ocapi_command:
    category: Update
    command: FWActivate
    baseuri: "iom1.wdc.com"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
- name: Delete Job
  community.general.ocapi_command:
    category: Jobs
    command: DeleteJob
    job_name: FirmwareUpdate
    baseuri: "{{ baseuri }}"
    proxy_slot_number: 2
    username: "{{ username }}"
    password: "{{ password }}"
a<  
msg:
  description: Message with action result or error description.
  returned: always
  type: str
  sample: "Action was successful"

jobUri:
  description: URI to use to monitor status of the operation. Returned for async commands such as Firmware Update, Firmware
    Activate.
  returned: when supported
  type: str
  sample: "https://ioma.wdc.com/Storage/Devices/openflex-data24-usalp03020qb0003/Jobs/FirmwareUpdate/"

operationStatusId:
  description: OCAPI State ID (see OCAPI documentation for possible values).
  returned: when supported
  type: int
  sample: 2
)AnsibleModule)
OcapiUtils)	to_native)urljoin)IndicatorLedOnIndicatorLedOffPowerModeLowPowerModeNormalPowerGracefulRestart)FWUploadFWUpdate
FWActivate	DeleteJob)ChassisSystemsUpdateJobsc                     i } t        t        t        d      t        dd      t        d      t        dd      t        d      t        d      t        d      t        dd      t        dd	      
	      d      }|j                  d   }|j                  d   }|j                  d   |j                  d   d}|j                  d   }d|j                  d   z   }|j                  j                  d      }t	        |||||      }|t
        vr<|j                  t        d|dt        t
        j                                            |t
        |   vr(|j                  t        d|dt
        |                |dk(  rI|j                  d      r|j                  |      } n%|j                  d      r|j                  |      } n |dk(  r#|j                  d      r|j                  |      } n|dk(  r{|d k(  rJ|j                  j                  d!      }	|	|j                  t        d"             |j                  |	      } n|d#k(  r|j                         } nn|d$k(  ri|j                         } nX|d%k(  rS|d&k(  rN|j                  j                  d'      }
|
|j                  d(       t!        |d)|
z         }|j#                  |      } | d*   d+u r|j                  t        | d,                y | d*= | j                  d-d      }| j                  d.t                     }|||j$                  sd/n| j                  d,d0      d1}| D cg c]	  }||vs| }}|D ]
  }| |   ||<     |j&                  d2i | y c c}w )3NT)requiredstr)r   type)r   int)r   no_log
   )r   default)	categorycommandjob_namebaseuriproxy_slot_numberupdate_image_pathusernamepasswordtimeout)argument_specsupports_check_moder   r    r%   r&   )userpswdr'   zhttps://r"   r#   zInvalid Category 'z'. Valid Categories = )msgzInvalid Command 'z'. Valid Commands = r   IndicatorLed	PowerModer   Powerr   r   r$   zMissing update_image_path.r   r   r   r   r!   zMissing job_namezJobs/retFr,   changedsessionzAction was successful.z"No action performed in check mode.)r1   r2   r,    )r   dictparamsgetr   CATEGORY_COMMANDS_ALL	fail_jsonr   listkeys
startswithmanage_chassis_indicator_ledmanage_system_powerupload_firmware_imageupdate_firmware_imageactivate_firmware_imager	   
delete_job
check_mode	exit_json)resultmoduler   r    credsr'   base_urir#   ocapi_utilsr$   r!   job_urir1   r2   kwargs
result_keyresult_keyss                    s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ocapi_command.pymainrN      s   F4($U3u%$U3".".4(45eR0

 !F }}Z(HmmI&G j)j)E mmI&GFMM)44H))*=>UH.?&QK ,,YYacgh}  iC  iC  iE  dF  (G  H  	I +H55YV]_tu}_~'  A  	B 9n- ==gFF, 44W=F	Y	g& 44W=F	X	j  & 1 12E F (  Y/K%L M 667HIF
" 668F$ 88:F	V	k!}}((4H  !34h((:;G ++G4Fe}Yve}565M**Y-**Y/393D3D+&**;K
 5;WjjPV>VzWW% 	4J!'
!3F:	4"6" Xs   
	M<M<__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Fansible_collections.community.general.plugins.module_utils.ocapi_utilsr   +ansible.module_utils.common.text.convertersr   +ansible.module_utils.six.moves.urllib.parser	   r7   rN   __name__r3       rM   <module>r[      sp    A @<|JX
* 5 ] A ? X&'4M	 T#n zF rZ   