How to use boot_once method in autotest

Best Python code snippet using autotest_python Github


Full Screen

1#!/usr/bin/python2# -*- coding: utf-8 -*-3# Copyright 2012 Dag Wieers <>4# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or SPDX-License-Identifier: GPL-3.0-or-later6from __future__ import absolute_import, division, print_function7__metaclass__ = type8DOCUMENTATION = '''9---10module: hpilo_boot11author: Dag Wieers (@dagwieers)12short_description: Boot system using specific media through HP iLO interface13description:14- "This module boots a system through its HP iLO interface. The boot media15 can be one of: cdrom, floppy, hdd, network or usb."16- This module requires the hpilo python module.17options:18 host:19 description:20 - The HP iLO hostname/address that is linked to the physical system.21 type: str22 required: true23 login:24 description:25 - The login name to authenticate to the HP iLO interface.26 default: Administrator27 type: str28 password:29 description:30 - The password to authenticate to the HP iLO interface.31 default: admin32 type: str33 media:34 description:35 - The boot media to boot the system from36 choices: [ "cdrom", "floppy", "rbsu", "hdd", "network", "normal", "usb" ]37 type: str38 image:39 description:40 - The URL of a cdrom, floppy or usb boot media image.41 protocol://username:password@hostname:port/filename42 - protocol is either 'http' or 'https'43 - username:password is optional44 - port is optional45 type: str46 state:47 description:48 - The state of the boot media.49 - "no_boot: Do not boot from the device"50 - "boot_once: Boot from the device once and then notthereafter"51 - "boot_always: Boot from the device each time the server is rebooted"52 - "connect: Connect the virtual media device and set to boot_always"53 - "disconnect: Disconnects the virtual media device and set to no_boot"54 - "poweroff: Power off the server"55 default: boot_once56 type: str57 choices: [ "boot_always", "boot_once", "connect", "disconnect", "no_boot", "poweroff" ]58 force:59 description:60 - Whether to force a reboot (even when the system is already booted).61 - As a safeguard, without force, hpilo_boot will refuse to reboot a server that is already running.62 default: no63 type: bool64 ssl_version:65 description:66 - Change the ssl_version used.67 default: TLSv168 type: str69 choices: [ "SSLv3", "SSLv23", "TLSv1", "TLSv1_1", "TLSv1_2" ]70requirements:71- python-hpilo72notes:73- To use a USB key image you need to specify floppy as boot media.74- This module ought to be run from a system that can access the HP iLO75 interface directly, either by using C(local_action) or using C(delegate_to).76'''77EXAMPLES = r'''78- name: Task to boot a system using an ISO from an HP iLO interface only if the system is an HP server79 community.general.hpilo_boot:80 host: YOUR_ILO_ADDRESS81 login: YOUR_ILO_LOGIN82 password: YOUR_ILO_PASSWORD83 media: cdrom84 image: http://some-web-server/iso/boot.iso85 when: cmdb_hwmodel.startswith('HP ')86 delegate_to: localhost87- name: Power off a server88 community.general.hpilo_boot:89 host: YOUR_ILO_HOST90 login: YOUR_ILO_LOGIN91 password: YOUR_ILO_PASSWORD92 state: poweroff93 delegate_to: localhost94'''95RETURN = '''96# Default return values97'''98import time99import traceback100import warnings101HPILO_IMP_ERR = None102try:103 import hpilo104 HAS_HPILO = True105except ImportError:106 HPILO_IMP_ERR = traceback.format_exc()107 HAS_HPILO = False108from ansible.module_utils.basic import AnsibleModule, missing_required_lib109# Suppress warnings from hpilo110warnings.simplefilter('ignore')111def main():112 module = AnsibleModule(113 argument_spec=dict(114 host=dict(type='str', required=True),115 login=dict(type='str', default='Administrator'),116 password=dict(type='str', default='admin', no_log=True),117 media=dict(type='str', choices=['cdrom', 'floppy', 'rbsu', 'hdd', 'network', 'normal', 'usb']),118 image=dict(type='str'),119 state=dict(type='str', default='boot_once', choices=['boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot', 'poweroff']),120 force=dict(type='bool', default=False),121 ssl_version=dict(type='str', default='TLSv1', choices=['SSLv3', 'SSLv23', 'TLSv1', 'TLSv1_1', 'TLSv1_2']),122 )123 )124 if not HAS_HPILO:125 module.fail_json(msg=missing_required_lib('python-hpilo'), exception=HPILO_IMP_ERR)126 host = module.params['host']127 login = module.params['login']128 password = module.params['password']129 media = module.params['media']130 image = module.params['image']131 state = module.params['state']132 force = module.params['force']133 ssl_version = getattr(hpilo.ssl, 'PROTOCOL_' + module.params.get('ssl_version').upper().replace('V', 'v'))134 ilo = hpilo.Ilo(host, login=login, password=password, ssl_version=ssl_version)135 changed = False136 status = {}137 power_status = 'UNKNOWN'138 if media and state in ('boot_always', 'boot_once', 'connect', 'disconnect', 'no_boot'):139 # Workaround for: Error communicating with iLO: Problem manipulating EV140 try:141 ilo.set_one_time_boot(media)142 except hpilo.IloError:143 time.sleep(60)144 ilo.set_one_time_boot(media)145 # TODO: Verify if image URL exists/works146 if image:147 ilo.insert_virtual_media(media, image)148 changed = True149 if media == 'cdrom':150 ilo.set_vm_status('cdrom', state, True)151 status = ilo.get_vm_status()152 changed = True153 elif media in ('floppy', 'usb'):154 ilo.set_vf_status(state, True)155 status = ilo.get_vf_status()156 changed = True157 # Only perform a boot when state is boot_once or boot_always, or in case we want to force a reboot158 if state in ('boot_once', 'boot_always') or force:159 power_status = ilo.get_host_power_status()160 if not force and power_status == 'ON':161 module.fail_json(msg='HP iLO (%s) reports that the server is already powered on !' % host)162 if power_status == 'ON':163 ilo.warm_boot_server()164# ilo.cold_boot_server()165 changed = True166 else:167 ilo.press_pwr_btn()168# ilo.reset_server()169# ilo.set_host_power(host_power=True)170 changed = True171 elif state in ('poweroff'):172 power_status = ilo.get_host_power_status()173 if not power_status == 'OFF':174 ilo.hold_pwr_btn()175# ilo.set_host_power(host_power=False)176 changed = True177 module.exit_json(changed=changed, power=power_status, **status)178if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?