Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
35163bce
Commit
35163bce
authored
Oct 12, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1310 from dagwieers/hpilo_boot-cleanup
hpilo_boot: Various clean ups in documentation and code
parents
b1ccda00
5927373c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
34 deletions
+41
-34
library/hpilo_boot
+41
-34
No files found.
library/hpilo_boot
View file @
35163bce
...
@@ -41,11 +41,6 @@ options:
...
@@ -41,11 +41,6 @@ options:
description:
description:
- The password to authenticate to the HP iLO interface.
- The password to authenticate to the HP iLO interface.
default: admin
default: admin
match:
description:
- An optional string to match against the iLO server name.
- This is a safety measure to prevent accidentally using the wrong
HP iLO interface with dire consequences.
media:
media:
description:
description:
- The boot media to boot the system from
- The boot media to boot the system from
...
@@ -54,8 +49,8 @@ options:
...
@@ -54,8 +49,8 @@ options:
image:
image:
description:
description:
- "The URL of a cdrom, floppy or usb boot media image.
- "The URL of a cdrom, floppy or usb boot media image.
C(protocol://username:password@hostname:port/filename)
"
'protocol://username:password@hostname:port/filename'
"
- protocol is either
C(http) or C(https)
- protocol is either
'http' or 'https'
- "username:password is optional"
- "username:password is optional"
- port is optional
- port is optional
state:
state:
...
@@ -66,26 +61,33 @@ options:
...
@@ -66,26 +61,33 @@ options:
- "boot_always: Boot from the device each time the serveris rebooted"
- "boot_always: Boot from the device each time the serveris rebooted"
- "connect: Connect the virtual media device and set to boot_always"
- "connect: Connect the virtual media device and set to boot_always"
- "disconnect: Disconnects the virtual media device and set to no_boot"
- "disconnect: Disconnects the virtual media device and set to no_boot"
- "poweroff: Power off the server"
default: boot_once
default: boot_once
choices: [ "boot_always", "boot_once", "connect", "disconnect", "no_boot" ]
choices: [ "boot_always", "boot_once", "connect", "disconnect", "no_boot"
, "poweroff"
]
force:
force:
description:
description:
- Whether to force a reboot (even when the system is already booted)
- 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: no
default: no
choices: [ "yes", "no" ]
choices: [ "yes", "no" ]
examples:
examples:
- description: Task to boot a system using an ISO from an HP iLO interface only if the system is an HP server
- description: Task to boot a system using an ISO from an HP iLO interface only if the system is an HP server
code: |
code: |
local_action: hpilo_boot host=$ilo_address login=$ilo_login password=$ilo_password match=$inventory_hostname_short media=cdrom image=$iso_url
- local_action: fail msg="CMDB serial ($cmdb_serialno) does not match hardware serial ($hw_system_serial) !"
only_if: "'$cmdb_hwmodel'.startswith('HP ')
only_if: "'$cmdb_serialno' != '$hw_system_serial'"
- local_action: hpilo_boot host=$ilo_address login=$ilo_login password=$ilo_password media=cdrom image=$iso_url
only_if: "'$cmdb_hwmodel'.startswith('HP ')"
- description: Power off a server
code: "local_action: hpilo_boot host=$ilo_address login=$ilo_login password=$ilo_password state=poweroff"
notes:
notes:
- To use a USB key image you need to specify floppy as boot media.
- 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
- This module ought to be run from a system that can access the HP iLO
interface directly, either by using
C(local_action)
or
interface directly, either by using
local_action
or
using
C(delegate_to)
.
using
delegate_to
.
'''
'''
import
sys
import
sys
import
time
import
warnings
import
warnings
try
:
try
:
import
hpilo
import
hpilo
...
@@ -103,10 +105,9 @@ def main():
...
@@ -103,10 +105,9 @@ def main():
host
=
dict
(
required
=
True
),
host
=
dict
(
required
=
True
),
login
=
dict
(
default
=
'Administrator'
),
login
=
dict
(
default
=
'Administrator'
),
password
=
dict
(
default
=
'admin'
),
password
=
dict
(
default
=
'admin'
),
match
=
dict
(
default
=
None
),
media
=
dict
(
default
=
None
,
choices
=
[
'cdrom'
,
'floppy'
,
'hdd'
,
'network'
,
'normal'
,
'usb'
]),
media
=
dict
(
default
=
None
,
choices
=
[
'cdrom'
,
'floppy'
,
'hdd'
,
'network'
,
'normal'
,
'usb'
]),
image
=
dict
(
default
=
None
),
image
=
dict
(
default
=
None
),
state
=
dict
(
default
=
'boot_once'
,
choices
=
[
'boot_always'
,
'boot_once'
,
'connect'
,
'disconnect'
,
'no_boot'
]),
state
=
dict
(
default
=
'boot_once'
,
choices
=
[
'boot_always'
,
'boot_once'
,
'connect'
,
'disconnect'
,
'no_boot'
,
'poweroff'
]),
force
=
dict
(
default
=
'no'
,
choices
=
BOOLEANS
),
force
=
dict
(
default
=
'no'
,
choices
=
BOOLEANS
),
)
)
)
)
...
@@ -114,25 +115,17 @@ def main():
...
@@ -114,25 +115,17 @@ def main():
host
=
module
.
params
.
get
(
'host'
)
host
=
module
.
params
.
get
(
'host'
)
login
=
module
.
params
.
get
(
'login'
)
login
=
module
.
params
.
get
(
'login'
)
password
=
module
.
params
.
get
(
'password'
)
password
=
module
.
params
.
get
(
'password'
)
match
=
module
.
params
.
get
(
'match'
)
media
=
module
.
params
.
get
(
'media'
)
media
=
module
.
params
.
get
(
'media'
)
image
=
module
.
params
.
get
(
'image'
)
image
=
module
.
params
.
get
(
'image'
)
state
=
module
.
params
.
get
(
'state'
)
state
=
module
.
params
.
get
(
'state'
)
force
=
module
.
boolean
(
module
.
params
.
get
(
'force'
))
force
=
module
.
boolean
(
module
.
params
.
get
(
'force'
))
ilo
=
hpilo
.
Ilo
(
host
,
login
=
login
,
password
=
password
)
ilo
=
hpilo
.
Ilo
(
host
,
login
=
login
,
password
=
password
)
changed
=
False
status
=
{}
power_status
=
'UNKNOWN'
# If match=string is provided, only reboot server if iLO name matches 'string'
if
media
and
state
in
(
'boot_always'
,
'boot_once'
,
'connect'
,
'disconnect'
,
'no_boot'
):
if
match
!=
None
:
try
:
server_name
=
ilo
.
get_server_name
()
except
Exception
,
e
:
module
.
fail_json
(
rc
=
1
,
msg
=
'Failed to connect to
%
s:
%
s'
%
(
host
,
e
.
message
))
if
not
server_name
.
lower
()
.
startswith
(
match
.
lower
()):
module
.
fail_json
(
rc
=
1
,
msg
=
'The iLO server name
\'
%
s
\'
does not match
\'
%
s
\'
'
%
(
server_name
,
match
))
if
media
:
# Workaround for: Error communicating with iLO: Problem manipulating EV
# Workaround for: Error communicating with iLO: Problem manipulating EV
try
:
try
:
...
@@ -144,16 +137,16 @@ def main():
...
@@ -144,16 +137,16 @@ def main():
# TODO: Verify if image URL exists/works
# TODO: Verify if image URL exists/works
if
image
:
if
image
:
ilo
.
insert_virtual_media
(
media
,
image
)
ilo
.
insert_virtual_media
(
media
,
image
)
changed
=
True
if
media
==
'cdrom'
:
if
media
==
'cdrom'
:
ilo
.
set_vm_status
(
'cdrom'
,
state
,
True
)
ilo
.
set_vm_status
(
'cdrom'
,
state
,
True
)
status
=
ilo
.
get_vm_status
()
status
=
ilo
.
get_vm_status
()
elif
media
==
'floppy'
:
changed
=
True
ilo
.
set_vf_status
(
state
,
True
)
elif
media
in
(
'floppy'
,
'usb'
):
status
=
ilo
.
get_vf_status
()
elif
media
==
'usb'
:
ilo
.
set_vf_status
(
state
,
True
)
ilo
.
set_vf_status
(
state
,
True
)
status
=
ilo
.
get_vf_status
()
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
# 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
:
...
@@ -161,14 +154,28 @@ def main():
...
@@ -161,14 +154,28 @@ def main():
power_status
=
ilo
.
get_host_power_status
()
power_status
=
ilo
.
get_host_power_status
()
if
not
force
and
power_status
==
'ON'
:
if
not
force
and
power_status
==
'ON'
:
module
.
fail_json
(
rc
=
1
,
msg
=
'
The server
\'
%
s
\'
is already powered on !'
%
server_name
)
module
.
fail_json
(
rc
=
1
,
msg
=
'
HP iLO (
%
s) reports that the server is already powered on !'
%
host
)
if
power_status
==
'ON'
:
if
power_status
==
'ON'
:
# ilo.cold_boot_server()
ilo
.
warm_boot_server
()
ilo
.
warm_boot_server
()
changed
=
True
else
:
else
:
ilo
.
cold_boot_server
()
ilo
.
press_pwr_btn
()
# ilo.reset_server()
# ilo.set_host_power(host_power=True)
changed
=
True
elif
state
in
(
'poweroff'
):
power_status
=
ilo
.
get_host_power_status
()
if
not
power_status
==
'OFF'
:
ilo
.
hold_pwr_btn
()
# ilo.set_host_power(host_power=False)
changed
=
True
module
.
exit_json
(
changed
=
True
,
**
status
)
module
.
exit_json
(
changed
=
changed
,
power
=
power_status
,
**
status
)
# this is magic, see lib/ansible/module_common.py
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment