GET /foreman_virt_who_configure/api/configs/31/deploy_script.sh
200
#!/bin/bash
heading() {
echo -e "\n== $1 =="
}
step() {
step_count=5
heading "[$1/$step_count] $2"
}
version_lte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
version_lt() {
[ "$1" = "$2" ] && return 1 || version_lte $1 $2
}
verify_minimal_version() {
minimal_version=0.24.2
installed_version=`rpm -q --queryformat '%{VERSION}' virt-who`
if version_lt $installed_version $minimal_version; then
echo "virt-who $installed_version does not meet minimum requirements, please make sure this host is properly subscribed and has access to katello-host-tools repository, minimal virt-who version is $minimal_version"
return 1
else
return 0
fi
}
result_code=0
compose_install_command() {
$1 packages unlock
$1 advanced procedure run packages-install --packages virt-who --assumeyes || result_code=$(($result_code|32))
$1 packages lock
}
install_virt_who() {
if `rpm -q satellite-maintain > /dev/null`; then
compose_install_command satellite-maintain
elif `rpm -q rubygem-foreman_maintain > /dev/null`; then
compose_install_command foreman-maintain
else
yum install -y virt-who || result_code=$(($result_code|32))
fi
}
step 1 "Installing virt-who"
install_virt_who
if verify_minimal_version; then
step 2 "Encrypting password"
cr_password=$(virt-who-password --password $(echo Y2hhbmdlbWU=|base64 -d) 2> /dev/null)
user_password=$(virt-who-password --password 'tsdd7U42PzGD63Ay' 2> /dev/null)
step 3 "Creating virt-who configuration"
cat > /etc/virt-who.d/virt-who-config-31.conf << EOF
### This configuration file is managed via the virt-who configure plugin
### manual edits will be deleted.
[virt-who-config-31]
type=esx
hypervisor_id=hostname
owner=org33
server=vmware.example.com
username=root
encrypted_password=$cr_password
rhsm_hostname=foreman.example.com
rhsm_username=virt_who_reporter_31
rhsm_encrypted_password=$user_password
rhsm_prefix=/rhsm
EOF
if [ $? -ne 0 ]; then result_code=$(($result_code|2)); fi
step 4 "Creating sysconfig virt-who configuration"
cat > /etc/virt-who.conf << EOF
### This configuration file is managed via the virt-who configure plugin
### manual edits will be deleted.
[global]
debug=0
interval=7200
oneshot=False
[system_environment]
EOF
if [ $? -ne 0 ]; then result_code=$(($result_code|4)); fi
step 5 "Enabling and restarting the virt-who service"
systemctl enable virt-who || result_code=$(($result_code|8))
systemctl restart virt-who || result_code=$(($result_code|16))
else
result_code=$(($result_code|1))
fi
heading "Finished"
if [ $result_code -ne 0 ]; then
echo "There were some errors during configuration:"
[ $(($result_code&0)) -ge 1 ] && echo 'Success'
[ $(($result_code&1)) -ge 1 ] && echo 'Newer version of virt-who is required, minimum version is 0.24.2'
[ $(($result_code&2)) -ge 1 ] && echo 'Unable to create virt-who config file'
[ $(($result_code&4)) -ge 1 ] && echo 'Unable to create sysconfig file'
[ $(($result_code&8)) -ge 1 ] && echo 'Unable to enable virt-who service using systemctl'
[ $(($result_code&16)) -ge 1 ] && echo 'Unable to start virt-who service, please see virt-who logs for more details'
[ $(($result_code&32)) -ge 1 ] && echo 'Unable to install virt-who package, make sure the host is properly subscribed and has access to katello-host-tools repository'
else
echo "Finished successfully"
fi
exit $result_code
| Param name | Description |
|---|---|
|
location_id
optional |
Set the current location context for the request Validations:
|
|
organization_id
optional |
Set the current organization context for the request Validations:
|
|
id
required |
Validations:
|