Skip to content

Instantly share code, notes, and snippets.

@treydock
Last active August 29, 2015 14:05
Show Gist options
  • Save treydock/570a776b5c160bca7c9c to your computer and use it in GitHub Desktop.
Save treydock/570a776b5c160bca7c9c to your computer and use it in GitHub Desktop.
oVirt node registration using Host Deploy Protocol
#!/bin/bash
# Uses oVirt Host Deploy Protocol - http://www.ovirt.org/Features/HostDeployProtocol
# Define variables
engine="<CHANGEME ENGINE FQDN>"
address="<CHANGEME IPADDRESS>" # Could use `facter ipaddress`
sshPort=22
sshKeyFingerprint=$(ssh-keygen -lf /etc/ssh/ssh_host_rsa_key | awk -F' ' '{ print $2 }') # Facter does not yet have this fact
sshUser="root"
vdsPort=54321
name="vm-dev" # Could use `facter hostname` or `facter fqdn`
uniqueId=$(cat /etc/vdsm/vdsm.id) # Comes from /proc/sys/kernel/random/uuid , ref: https://github.com/treydock/puppet-ovirt
# Define constants
CURL_HTTP="curl --silent"
CURL_HTTPS="curl --silent --cacert /etc/pki/vdsm/certs/cacert.pem"
# Check version
VERSION=$(${CURL_HTTP} "http://${engine}/ovirt-engine/services/host-register?version=1&command=get-version")
[ $VERSION -lt 1 ] && { echo "Version must be >= 1"; exit 1 ; }
# Download engine cacert and install
${CURL_HTTP} "http://${engine}/ovirt-engine/services/host-register?version=1&command=get-pki-trust" > /root/cacert.pem
puppet resource file /etc/pki/vdsm/certs/cacert.pem ensure=file owner=root group=kvm mode=0644 source=file:///root/cacert.pem
puppet resource file /etc/pki/vdsm ensure=directory
puppet resource file /etc/pki/vdsm/certs ensure=directory
# Get SSH public key from engine
OPENSSH_PUBKEY=$(${CURL_HTTPS} "https://${engine}/ovirt-engine/services/host-register?version=1&command=get-ssh-trust")
PUBKEY=(${OPENSSH_PUBKEY})
puppet resource ssh_authorized_key "${PUBKEY[2]}" key="${PUBKEY[1]}" type="${PUBKEY[0]}" user="${sshUser}"
# Register host with engine
REGISTER_URL=()
REGISTER_URL+="https://${engine}/ovirt-engine/services/host-register?version=1&"
REGISTER_URL+="address=${address}&"
REGISTER_URL+="sshPort=${sshPort}&"
REGISTER_URL+="sshKeyFingerprint=${sshKeyFingerprint}&"
REGISTER_URL+="sshUser=${sshUser}&"
REGISTER_URL+="vdsPort=${vdsPort}&"
REGISTER_URL+="name=${name}&"
REGISTER_URL+="uniqueId=${uniqueId}&"
REGISTER_URL+="command=register"
${CURL_HTTPS} "${REGISTER_URL[@]}"
# Should see response of "OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment