blob: 29b9d4637420105256fb8d26f3e4d4a209c181a0 [file] [log] [blame]
#!/bin/sh
set -e
# Prepare RHEL image for bootstrap on VSPHERE
: "${DOWNLOAD_INSTALL:="true"}"
: "${VCENTER_CONFIG_PATH:="/etc/virt-who.d/vcenter.conf"}"
if [ -z "${VC_SERVER}" ] || [ -z "${VC_USER}" ] || [ -z "${VC_PASSWORD}" ]; then
echo "VC_SERVER or VC_USER or VC_PASSWORD is not provided"
exit 1
fi
yum -y install open-vm-tools cloud-init virt-who
systemctl enable virt-who
VC_PASSWORD_ENCRYPTED="$(virt-who-password -p "${VC_PASSWORD}")"
VC_OWNER=$(subscription-manager identity | grep 'org ID' | awk -F ':' '{print $2}' | xargs)
mkdir -p "$(dirname "${VCENTER_CONFIG_PATH}")"
cat <<EOF > "${VCENTER_CONFIG_PATH}"
[vcenter]
type=${VC_TYPE:-esx}
server=${VC_SERVER}
username=${VC_USER}
encrypted_password=${VC_PASSWORD_ENCRYPTED}
owner=${VC_OWNER}
hypervisor_id=${VC_HYPERVISOR_ID:-hostname}
EOF
if [ -n "${VC_FILTER_HOSTS}" ]; then
echo "filter_hosts=${VC_FILTER_HOSTS}" >> "${VCENTER_CONFIG_PATH}"
fi
# The script to lookup the path to the cloud-init's datasource directory, "sources".
PY_SCRIPT='import os; from cloudinit import sources; print(os.path.dirname(sources.__file__));'
# Get the path to the cloud-init installation's datasource directory.
CLOUD_INIT_SOURCES=$(python -c ''"${PY_SCRIPT}"'' 2>/dev/null || \
python3 -c ''"${PY_SCRIPT}"'' 2>/dev/null) ||
{ exit_code="${?}"; echo "failed to find python runtime" 1>&2; exit "${exit_code}"; }
# If no "sources" directory was located then it's likely cloud-init is not installed.
[ -z "${CLOUD_INIT_SOURCES}" ] && echo "cloud-init not found" 1>&2 && exit 1
if [ "${DOWNLOAD_INSTALL}" = "true" ]; then
REPO_URL="${REPO_URL:-https://gerrit.mcp.mirantis.com/plugins/gitiles/kubernetes/vmware-guestinfo/+/refs/heads}"
# The git reference to use. This can be a branch or tag name as well as a commit ID.
GIT_REF="${GIT_REF:-mcp}"
# Download the cloud init datasource into the cloud-init's "sources" directory.
curl "${REPO_URL}/${GIT_REF}/DataSourceVMwareGuestInfo.py?format=TEXT" | base64 -d \
> "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py"
# Add the configuration file that tells cloud-init what datasource to use.
mkdir -p /etc/cloud/cloud.cfg.d
curl "${REPO_URL}/${GIT_REF}/99-DataSourceVMwareGuestInfo.cfg?format=TEXT" | base64 -d \
> /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg
else
BASEDIR=$(dirname "$0")
cp "${BASEDIR}/DataSourceVMwareGuestInfo.py" "${CLOUD_INIT_SOURCES}/DataSourceVMwareGuestInfo.py"
mkdir -p /etc/cloud/cloud.cfg.d
cp "${BASEDIR}/99-DataSourceVMwareGuestInfo.cfg" /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg
fi