
    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ZdZ	 d dlmZ d dlmZmZ d	 Zed
k(  r e        yy# e$ r  e	j                          ZdZY 3w xY w)    )absolute_importdivisionprint_functionaG	  
module: ipmi_power
short_description: Power management for machine
description:
  - Use this module for power management.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - Hostname or IP address of the BMC.
    required: true
    type: str
  port:
    description:
      - Remote RMCP port.
    default: 623
    type: int
  user:
    description:
      - Username to use to connect to the BMC.
    required: true
    type: str
  password:
    description:
      - Password to connect to the BMC.
    required: true
    type: str
  key:
    description:
      - Encryption key to connect to the BMC in hex format.
    required: false
    type: str
    version_added: 4.1.0
  state:
    description:
      - Whether to ensure that the machine in desired state.
      - 'The choices for state are:'
      - V(on) -- Request system turn on.
      - V(off) -- Request system turn off without waiting for OS to shutdown.
      - V(shutdown) -- Have system request OS proper shutdown.
      - V(reset) -- Request system reset without waiting for OS.
      - V(boot) -- If system is off, then V(on), else V(reset).
      - Either this option or O(machine) is required.
    choices: ['on', 'off', shutdown, reset, boot]
    type: str
  timeout:
    description:
      - Maximum number of seconds before interrupt request.
    default: 300
    type: int
  machine:
    description:
      - Provide a list of the remote target address for the bridge IPMI request, and the power status.
      - Either this option or O(state) is required.
    required: false
    type: list
    elements: dict
    version_added: 4.3.0
    suboptions:
      targetAddress:
        description:
          - Remote target address for the bridge IPMI request.
        type: int
        required: true
      state:
        description:
          - Whether to ensure that the machine specified by O(machine[].targetAddress) in desired state.
          - If this option is not set, the power state is set by O(state).
          - If both this option and O(state) are set, this option takes precedence over O(state).
        choices: ['on', 'off', shutdown, reset, boot]
        type: str

requirements:
  - pyghmi
author: "Bulat Gaifullin (@bgaifullin) <gaifullinbf@gmail.com>"
a  
powerstate:
  description: The current power state of the machine.
  returned: success and O(machine) is not provided
  type: str
  sample: 'on'
status:
  description: The current power state of the machine when the machine option is set.
  returned: success and O(machine) is provided
  type: list
  elements: dict
  version_added: 4.3.0
  contains:
    powerstate:
      description: The current power state of the machine specified by RV(status[].targetAddress).
      type: str
    targetAddress:
      description: The remote target address.
      type: int
  sample:
    [
      {
        "powerstate": "on",
        "targetAddress": 48
      },
      {
        "powerstate": "on",
        "targetAddress": 50
      }
    ]
a  
- name: Ensure machine is powered on
  community.general.ipmi_power:
    name: test.testdomain.com
    user: admin
    password: password
    state: 'on'

- name: Ensure machines of which remote target address is 48 and 50 are powered off
  community.general.ipmi_power:
    name: test.testdomain.com
    user: admin
    password: password
    state: 'off'
    machine:
      - targetAddress: 48
      - targetAddress: 50

- name: Ensure machine of which remote target address is 48 is powered on, and 50 is powered off
  community.general.ipmi_power:
    name: test.testdomain.com
    user: admin
    password: password
    machine:
      - targetAddress: 48
        state: 'on'
      - targetAddress: 50
        state: 'off'
N   )command)AnsibleModulemissing_required_libc                     t        t        t        d      t        dd      t        g d      t        dd      t        dd      t        d	d
      t        dd      t        ddt        t        dd      t        d	g d                        dddgf      } t         | j                  t	        d      t
               | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }	 | j                  d   r#t        j                  | j                  d         }nd }	 t        j                  ||||       }	| j                  d!|z         d"}
|n|	j                         }|d#   |k7  r&| j                  rd#|in|	j                  ||$      }d}
n|}d%|v r| j                  |d%           | j                  d0d&|
i| y g }|D ]  }|d'   }|t         k\  r| j                  d(       	 |	j                  d)|i*      }|d   r|d   }n|r|}n| j                  d,       d#   k7  rTd}
| j                  sF|	j                  ||d)|i-      }d%|v r| j                  |d%          |j%                  ||d#   d.       |d#   |k(  s| j                  s|j%                  ||d.        | j                  |
|/       y # t        $ r | j                  d       Y w xY w# t"        $ r | j                  d+       Y w xY w# t        $ r%}| j                  t'        |             Y d }~y d }~ww xY w)1NT)requiredio  int)defaulttype)onoffshutdownresetboot)choices)r   no_logstr)r   r   i,  listdict)r   r   )r   r   )targetAddressstate)r   elementsoptions)nameportr   userpasswordkeytimeoutmachiner   r#   )argument_specsupports_check_moderequired_one_ofpyghmi)msg	exceptionr   r   r   r    r"   r!   z(Unable to convert 'key' from hex string.)r(   )bmcuseridr    r   kgzipmi instantiated - name: "%s"F
powerstate)waiterrorchangedr   z-targetAddress should be set between 0 to 255.addr)bridge_requestz6targetAddress isn't supported on the installed pyghmi.z9Either state or suboption of machine state should be set.)r.   r2   )ztargetAddress:r-   )r0   status )r   r   r   	fail_jsonr	   PYGHMI_IMP_ERRparamsbinascii	unhexlify	ExceptionCommanddebug	get_power
check_mode	set_power	exit_jsonINVALID_TARGET_ADDRESS	TypeErrorappendr   )moduler   r   r   r    r   r"   r#   r!   ipmi_cmdr0   currentresponseentrytaddrtstatenewes                     p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipmi_power.pymainrN      s   t$c.IJtD145%-51f"&5"AE3]^
  !i 
%F. 1(;~V== D== D== D}}Z(HMM'"EmmI&GmmI&GI==$$V]]5%9:CC
8%??TH4C
 	5<=?((*G|$-4:4E4EL%0!++E+@ "("  Xg%6 7F9W99H  Uo.22$$)X$YV&000PG
 >"7^F"F$$)d$e<(F2"G!,,&00gW]_dVe0f"c>",,W,> /4CDUVX <(F2f6G6GOOuF$ST=U@ WX>u  IGHID ! V$$T % VV2  %SV$$%s\   /4K= $BM  'M  ,L BM  )M  =LLL=:M  <L==M   	M.	M))M.__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONRETURNEXAMPLES	tracebackr8   r6   rA   pyghmi.ipmir   ImportError
format_excansible.module_utils.basicr   r	   rN   __name__r4       rM   <module>r\      s    A @Qf
@<   #
 Kd%N zF ]  )Y))+NGs   ? AA