-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbootdisk_get
executable file
·81 lines (74 loc) · 2.07 KB
/
bootdisk_get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# This script will download the foreman bootdisk for a specific host.
# Arguments:
# ARG1 = Foreman hook event
# ARG2 = Foreman object name (FQDN)
# ARG3 = Foreman hook object json file
#
HOOK_EVENT=$1
HOOK_OBJECT=$2
HOOK_OBJECT_FILE=$3
#
# Source the configuration file
#
source /etc/foreman/hooks/foreman_bootdisk.conf
#
# Source foreman bootdisk helper functions
#
source ${HOOK_DIR}/functions/hook_functions.sh
#
# If the bootdisk store directory does not exist, create it
#
function boot_disk_store() {
# If bootdisk store does not exist, create it.
if ! [ -d "$BOOT_DISK_STORE" ]; then
mkdir --parents $BOOT_DISK_STORE &&
{ log_info "Directory $BOOT_DISK_STORE created"; return 0; } ||
{ log_err "Unable to create BOOT_DISK_STORE directory"; return 1; }
fi
return 0
}
#
# Get the bootdisk iso image
#
function bootdisk_get() {
local hostname=$1
if [ "$USE_FULL_HOST_IMAGE" == "true" ]; then
hammer --output silent bootdisk host --full true \
--host ${hostname} --file ${BOOT_DISK_STORE}/${hostname}.iso &&
{ log_info "Succesfully downloaded foreman bootdisk"; return 0; } ||
{ log_err "Failed downloading foreman bootdisk"; return 1; }
else
hammer --output silent bootdisk host \
--host ${hostname} --file ${BOOT_DISK_STORE}/${hostname}.iso &&
{ log_info "Succesfully downloaded foreman bootdisk"; return 0; } ||
{ log_err "Failed downloading foreman bootdisk"; return 1; }
fi
}
#
# Clean up, delete the bootdisk iso image
#
function bootdisk_rm() {
local hostname=$1
rm -f ${BOOT_DISK_STORE}/${hostname}.iso &&
{ log_info "Succesfully deleted foreman bootdisk from bootdisk store"; return 0; } ||
{ log_err "Failed deleting foreman bootdisk from bootdisk store"; return 1; }
}
case "$HOOK_EVENT" in
create|after_build)
boot_disk_store &&
bootdisk_get $HOOK_OBJECT || exit 1
;;
after_provision)
bootdisk_rm HOOK_OBJECT || exit 1
;;
destroy)
# NOOP
;;
*)
log_info "Usage: {create|after_build|after_provision|destroy} obj < data"
exit 1
;;
esac
exit 0