1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-10 14:05:07 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -119,6 +119,7 @@ import warnings
HPILO_IMP_ERR = None
try:
import hpilo
HAS_HPILO = True
except ImportError:
HPILO_IMP_ERR = traceback.format_exc()
@ -128,45 +129,47 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
# Suppress warnings from hpilo
warnings.simplefilter('ignore')
warnings.simplefilter("ignore")
def main():
module = AnsibleModule(
argument_spec=dict(
host=dict(type='str', required=True),
login=dict(type='str', default='Administrator'),
password=dict(type='str', default='admin', no_log=True),
media=dict(type='str', choices=['cdrom', 'floppy', 'rbsu', 'hdd', 'network', 'normal', 'usb']),
image=dict(type='str'),
state=dict(type='str', default='boot_once', choices=['boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot', 'poweroff']),
force=dict(type='bool', default=False),
idempotent_boot_once=dict(type='bool', default=False),
ssl_version=dict(type='str', default='TLSv1', choices=['SSLv3', 'SSLv23', 'TLSv1', 'TLSv1_1', 'TLSv1_2']),
host=dict(type="str", required=True),
login=dict(type="str", default="Administrator"),
password=dict(type="str", default="admin", no_log=True),
media=dict(type="str", choices=["cdrom", "floppy", "rbsu", "hdd", "network", "normal", "usb"]),
image=dict(type="str"),
state=dict(
type="str",
default="boot_once",
choices=["boot_always", "boot_once", "connect", "disconnect", "no_boot", "poweroff"],
),
force=dict(type="bool", default=False),
idempotent_boot_once=dict(type="bool", default=False),
ssl_version=dict(type="str", default="TLSv1", choices=["SSLv3", "SSLv23", "TLSv1", "TLSv1_1", "TLSv1_2"]),
)
)
if not HAS_HPILO:
module.fail_json(msg=missing_required_lib('python-hpilo'), exception=HPILO_IMP_ERR)
module.fail_json(msg=missing_required_lib("python-hpilo"), exception=HPILO_IMP_ERR)
host = module.params['host']
login = module.params['login']
password = module.params['password']
media = module.params['media']
image = module.params['image']
state = module.params['state']
force = module.params['force']
idempotent_boot_once = module.params['idempotent_boot_once']
host = module.params["host"]
login = module.params["login"]
password = module.params["password"]
media = module.params["media"]
image = module.params["image"]
state = module.params["state"]
force = module.params["force"]
idempotent_boot_once = module.params["idempotent_boot_once"]
ssl_version = getattr(hpilo.ssl, f"PROTOCOL_{module.params.get('ssl_version').upper().replace('V', 'v')}")
ilo = hpilo.Ilo(host, login=login, password=password, ssl_version=ssl_version)
changed = False
status = {}
power_status = 'UNKNOWN'
if media and state in ('boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot'):
power_status = "UNKNOWN"
if media and state in ("boot_always", "boot_once", "connect", "disconnect", "no_boot"):
# Workaround for: Error communicating with iLO: Problem manipulating EV
try:
ilo.set_one_time_boot(media)
@ -179,21 +182,20 @@ def main():
ilo.insert_virtual_media(media, image)
changed = True
if media == 'cdrom':
ilo.set_vm_status('cdrom', state, True)
if media == "cdrom":
ilo.set_vm_status("cdrom", state, True)
status = ilo.get_vm_status()
changed = True
elif media in ('floppy', 'usb'):
elif media in ("floppy", "usb"):
ilo.set_vf_status(state, True)
status = ilo.get_vf_status()
changed = True
# Only perform a boot when state is boot_once or boot_always, or in case we want to force a reboot
if state in ('boot_once', 'boot_always') or force:
if state in ("boot_once", "boot_always") or force:
power_status = ilo.get_host_power_status()
if power_status == 'ON':
if power_status == "ON":
if not force and not idempotent_boot_once:
# module.deprecate(
# 'The failure of the module when the server is already powered on is being deprecated.'
@ -201,30 +203,29 @@ def main():
# version='11.0.0',
# collection_name='community.general'
# )
module.fail_json(msg=f'HP iLO ({host}) reports that the server is already powered on !')
module.fail_json(msg=f"HP iLO ({host}) reports that the server is already powered on !")
elif not force and idempotent_boot_once:
pass
elif force:
ilo.warm_boot_server()
# ilo.cold_boot_server()
# ilo.cold_boot_server()
changed = True
else:
ilo.press_pwr_btn()
# ilo.reset_server()
# ilo.set_host_power(host_power=True)
# ilo.reset_server()
# ilo.set_host_power(host_power=True)
changed = True
elif state in ('poweroff'):
elif state in ("poweroff"):
power_status = ilo.get_host_power_status()
if not power_status == 'OFF':
if not power_status == "OFF":
ilo.hold_pwr_btn()
# ilo.set_host_power(host_power=False)
# ilo.set_host_power(host_power=False)
changed = True
module.exit_json(changed=changed, power=power_status, **status)
if __name__ == '__main__':
if __name__ == "__main__":
main()