
    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ZdZ	 d dlZdZd dlmZmZ  ej(                  d	       d
 Zedk(  r e        yy# e$ r  e
j                          ZdZY Ew xY w)    )absolute_importdivisionprint_functiona   
module: hpilo_boot
author: Dag Wieers (@dagwieers)
short_description: Boot system using specific media through HP iLO interface
description:
  - 'This module boots a system through its HP iLO interface. The boot media can be one of: V(cdrom), V(floppy), V(hdd), V(network),
    or V(usb).'
  - This module requires the hpilo python module.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  host:
    description:
      - The HP iLO hostname/address that is linked to the physical system.
    type: str
    required: true
  login:
    description:
      - The login name to authenticate to the HP iLO interface.
    default: Administrator
    type: str
  password:
    description:
      - The password to authenticate to the HP iLO interface.
    default: admin
    type: str
  media:
    description:
      - The boot media to boot the system from.
    choices: ["cdrom", "floppy", "rbsu", "hdd", "network", "normal", "usb"]
    type: str
  image:
    description:
      - The URL of a cdrom, floppy or usb boot media image in the form V(protocol://username:password@hostname:port/filename).
      - V(protocol) is either V(http) or V(https).
      - V(username:password) is optional.
      - V(port) is optional.
    type: str
  state:
    description:
      - The state of the boot media.
      - 'V(no_boot): Do not boot from the device.'
      - 'V(boot_once): Boot from the device once and then notthereafter.'
      - 'V(boot_always): Boot from the device each time the server is rebooted.'
      - 'V(connect): Connect the virtual media device and set to boot_always.'
      - 'V(disconnect): Disconnects the virtual media device and set to no_boot.'
      - 'V(poweroff): Power off the server.'
    default: boot_once
    type: str
    choices: ["boot_always", "boot_once", "connect", "disconnect", "no_boot", "poweroff"]
  force:
    description:
      - Whether to force a reboot (even when the system is already booted).
      - As a safeguard, without force, hpilo_boot will refuse to reboot a server that is already running.
    default: false
    type: bool
  ssl_version:
    description:
      - Change the ssl_version used.
    default: TLSv1
    type: str
    choices: ["SSLv3", "SSLv23", "TLSv1", "TLSv1_1", "TLSv1_2"]
  idempotent_boot_once:
    description:
      - "This option makes O(state=boot_once) succeed instead of failing when the server is already powered on."
    type: bool
    default: false
    version_added: 10.6.0
requirements:
  - python-hpilo
notes:
  - To use a USB key image you need to specify floppy as boot media.
  - This module ought to be run from a system that can access the HP iLO interface directly, either by using C(local_action)
    or using C(delegate_to).
a  
- name: Task to boot a system using an ISO from an HP iLO interface only if the system is an HP server
  community.general.hpilo_boot:
    host: YOUR_ILO_ADDRESS
    login: YOUR_ILO_LOGIN
    password: YOUR_ILO_PASSWORD
    media: cdrom
    image: http://some-web-server/iso/boot.iso
  when: cmdb_hwmodel.startswith('HP ')
  delegate_to: localhost

- name: Power off a server
  community.general.hpilo_boot:
    host: YOUR_ILO_HOST
    login: YOUR_ILO_LOGIN
    password: YOUR_ILO_PASSWORD
    state: poweroff
  delegate_to: localhost
z
# Default return values
NTF)AnsibleModulemissing_required_libignorec                     t        t        t        dd      t        dd      t        ddd      t        dg d	      t        d
      t        ddg d      t        dd      t        dd      t        ddg d      	            } t        s | j                  t	        d      t
               | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }t        t        j                  d| j                  j                  d      j                         j                  d d!      z         }	t        j                  ||||	"      }
d}i }d#}|r|d$v r{	 |
j                  |       |r|
j%                  ||       d}|d&k(  r&|
j'                  d&|d       |
j)                         }d}n(|d'v r$|
j+                  |d       |
j-                         }d}|d(v s|r\|
j/                         }|d)k(  r4|s|s| j                  d*|z  +       nX|s|rnS|rQ|
j1                          d}n>|
j3                          d}n+|d,v r'|
j/                         }|d-k(  s|
j5                          d} | j6                  d/||d.| y # t        j                  $ r* t!        j"                  d%       |
j                  |       Y Hw xY w)0NstrT)typerequiredAdministrator)r   defaultadmin)r   r   no_log)cdromfloppyrbsuhddnetworknormalusb)r   choices)r   	boot_once)boot_alwaysr   connect
disconnectno_bootpoweroff)r   r   r   boolFTLSv1)SSLv3SSLv23r    TLSv1_1TLSv1_2)	hostloginpasswordmediaimagestateforceidempotent_boot_oncessl_version)argument_speczpython-hpilo)msg	exceptionr%   r&   r'   r(   r)   r*   r+   r,   	PROTOCOL_r-   Vv)r&   r'   r-   UNKNOWN)r   r   r   r   r   <   r   )r   r   )r   r   ONz;HP iLO (%s) reports that the server is already powered on !)r/   r   OFF)changedpower )r   dict	HAS_HPILO	fail_jsonr   HPILO_IMP_ERRparamsgetattrhpilosslgetupperreplaceIloset_one_time_bootIloErrortimesleepinsert_virtual_mediaset_vm_statusget_vm_statusset_vf_statusget_vf_statusget_host_power_statuswarm_boot_serverpress_pwr_btnhold_pwr_btn	exit_json)moduler%   r&   r'   r(   r)   r*   r+   r,   r-   ilor8   statuspower_statuss                 p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/hpilo_boot.pymainrZ      s   540E?;ugdCE+ijE"E;  AM  NFE2!%65!A%Btu

F 1.A][== DMM'"E}}Z(HMM'"EMM'"EMM'"EMM'"E!==)?@%))[6==3D3D]3S3Y3Y3[3c3cdgil3m%mnK
))Dk
RCGFLZZ	)!!%( $$UE2GGgud3&&(FG''eT*&&(FG ,,0024!5   %bei%i j3$$& G	:	002u$GFCWLCFCk ~~ 	)JJrN!!%(	)s   "J? ?9K<;K<__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNrI   	tracebackwarningsr>   rA   r<   ImportError
format_excansible.module_utils.basicr   r   simplefilterrZ   __name__r:       rY   <module>ri      s    A @Ob(
   I
 K   h \D~ zF U  (I((*MIs   A A.-A.