Merge "Add ironic image generation and node registration scripts"
This commit is contained in:
commit
62a41aef85
134
scripts/ironic_generate-images.sh
Executable file
134
scripts/ironic_generate-images.sh
Executable file
@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script is set up to be run on infra01 and on ubunut xenial (16.04), but could be run on any node as long as the infra01_util node is in the hosts file.
|
||||
# You can also define/export the UTILITY01_HOSTNAME yourself.
|
||||
|
||||
set -e -u
|
||||
|
||||
function cleanup {
|
||||
# it's ok if we have some errors on cleanup
|
||||
set +e
|
||||
unset DIB_DEV_USER_USERNAME DIB_DEV_USER_PASSWORD DIB_DEV_USER_PWDLESS_SUDO
|
||||
unset ELEMENTS_PATH DIB_CLOUD_INIT_DATASOURCES DIB_RELEASE DISTRO_NAME
|
||||
unset DIB_HPSSACLI_URL IRONIC_AGENT_VERSION
|
||||
unset -f make-base-image
|
||||
unset -f cleanup
|
||||
deactivate
|
||||
}
|
||||
# clean up our variables on exit, even exit on error
|
||||
trap cleanup EXIT
|
||||
|
||||
function make-base-image {
|
||||
disk-image-create -o baremetal-$DISTRO_NAME-$DIB_RELEASE $DISTRO_NAME baremetal bootloader dhcp-all-interfaces local-config proliant-tools ${DEBUG_USER_ELEMENT:-""}
|
||||
|
||||
rm -R *.d/
|
||||
scp -o StrictHostKeyChecking=no baremetal-$DISTRO_NAME-$DIB_RELEASE* "${UTILITY01_HOSTNAME}":~/images
|
||||
rm baremetal-$DISTRO_NAME-$DIB_RELEASE* # no reason to keep these around
|
||||
|
||||
VMLINUZ_UUID=$(ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "source ~/openrc; glance image-create --name baremetal-$DISTRO_NAME-$DIB_RELEASE.vmlinuz \
|
||||
--visibility public \
|
||||
--disk-format aki \
|
||||
--property hypervisor_type=baremetal \
|
||||
--protected=True \
|
||||
--container-format aki < ~/images/baremetal-$DISTRO_NAME-$DIB_RELEASE.vmlinuz" | awk '/\| id/ {print $4}')
|
||||
INITRD_UUID=$(ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "source ~/openrc; glance image-create --name baremetal-$DISTRO_NAME-$DIB_RELEASE.initrd \
|
||||
--visibility public \
|
||||
--disk-format ari \
|
||||
--property hypervisor_type=baremetal \
|
||||
--protected=True \
|
||||
--container-format ari < ~/images/baremetal-$DISTRO_NAME-$DIB_RELEASE.initrd" | awk '/\| id/ {print $4}')
|
||||
ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "source ~/openrc; glance image-create --name baremetal-$DISTRO_NAME-$DIB_RELEASE \
|
||||
--visibility public \
|
||||
--disk-format qcow2 \
|
||||
--container-format bare \
|
||||
--property hypervisor_type=baremetal \
|
||||
--property kernel_id=${VMLINUZ_UUID} \
|
||||
--protected=True \
|
||||
--property ramdisk_id=${INITRD_UUID} < ~/images/baremetal-$DISTRO_NAME-$DIB_RELEASE.qcow2"
|
||||
}
|
||||
|
||||
# install needed binaries
|
||||
apt-get install -y kpartx parted qemu-utils
|
||||
|
||||
mkdir -p ~/dib
|
||||
pushd ~/dib
|
||||
virtualenv env
|
||||
source env/bin/activate
|
||||
|
||||
# newton pip.conf sucks
|
||||
if [[ -f ~/.pip/pip.conf ]]; then
|
||||
mv ~/.pip/pip.conf{,.bak}
|
||||
fi
|
||||
# install dib
|
||||
pip install pbr # newton pbr is too old
|
||||
if [[ ! -d ~/dib/diskimage-builder ]]; then
|
||||
git clone https://github.com/openstack/diskimage-builder/
|
||||
fi
|
||||
# let's use a newer kernel for interfaces we may need
|
||||
if ! grep -q linux-image-generic-lts-xenial ~/dib/diskimage-builder/diskimage_builder/elements/ubuntu/package-installs.yaml; then
|
||||
echo 'linux-image-generic-lts-xenial:' > ~/dib/diskimage-builder/diskimage_builder/elements/ubuntu/package-installs.yaml
|
||||
fi
|
||||
pushd diskimage-builder
|
||||
pip install .
|
||||
popd
|
||||
if [[ -f ~/.pip/pip.conf.bak ]]; then
|
||||
mv ~/.pip/pip.conf.bak ~/.pip/pip.conf
|
||||
fi
|
||||
|
||||
UTILITY01_HOSTNAME="${UTILITY01_HOSTNAME:-$(grep infra01_util /etc/hosts | awk '{print $NF}')}"
|
||||
|
||||
# create image directory in util01 container
|
||||
ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "mkdir -p ~/images"
|
||||
|
||||
# set up envars for the deploy image debug user
|
||||
export DIB_DEV_USER_USERNAME=debug-user
|
||||
export DIB_DEV_USER_PASSWORD=secrete
|
||||
export DIB_DEV_USER_PWDLESS_SUDO=yes
|
||||
# Uncomment the following line to enable a debug user login
|
||||
#export DEBUG_USER_ELEMENT=devuser
|
||||
|
||||
# set up envars for all images
|
||||
export DIB_CLOUD_INIT_DATASOURCES="Ec2, ConfigDrive, OpenStack"
|
||||
|
||||
# set up envars for the deploy image ironic agent
|
||||
# export DIB_HPSSACLI_URL="http://downloads.hpe.com/pub/softlib2/software1/pubsw-linux/p1857046646/v109216/hpssacli-2.30-6.0.x86_64.rpm"
|
||||
export IRONIC_AGENT_VERSION="stable/ocata"
|
||||
# create the deploy image
|
||||
disk-image-create --install-type source -o ironic-deploy ironic-agent ubuntu proliant-tools ${DEBUG_USER_ELEMENT:-""}
|
||||
|
||||
rm ironic-deploy.vmlinuz # not needed or uploaded
|
||||
rm -R *.d/ # don't need dib dirs
|
||||
scp -o StrictHostKeyChecking=no ironic-deploy* "${UTILITY01_HOSTNAME}":~/images
|
||||
rm ironic-deploy* # no reason to keep these around
|
||||
|
||||
ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "source ~/openrc; glance image-create --name ironic-deploy.kernel \
|
||||
--visibility public \
|
||||
--disk-format aki \
|
||||
--property hypervisor_type=baremetal \
|
||||
--protected=True \
|
||||
--container-format aki < ~/images/ironic-deploy.kernel"
|
||||
ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "source ~/openrc; glance image-create --name ironic-deploy.initramfs \
|
||||
--visibility public \
|
||||
--disk-format ari \
|
||||
--property hypervisor_type=baremetal \
|
||||
--protected=True \
|
||||
--container-format ari < ~/images/ironic-deploy.initramfs"
|
||||
|
||||
# Ubuntu Xenial
|
||||
export DIB_RELEASE=xenial
|
||||
export DISTRO_NAME=ubuntu
|
||||
make-base-image
|
||||
|
||||
# Ubuntu Trusty
|
||||
export DIB_RELEASE=trusty
|
||||
export DISTRO_NAME=ubuntu
|
||||
make-base-image
|
||||
|
||||
# CentOS 7
|
||||
export DIB_RELEASE=7
|
||||
export DISTRO_NAME=centos7
|
||||
make-base-image
|
||||
popd
|
||||
|
||||
# utility container doesn't have much space...
|
||||
ssh -o StrictHostKeyChecking=no "${UTILITY01_HOSTNAME}" "rm ~/images -R"
|
66
scripts/ironic_register-images.sh
Executable file
66
scripts/ironic_register-images.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e -u
|
||||
|
||||
inventory_hostname=123456-node01
|
||||
Port1NIC_MACAddress="ab:cd:ef:gh:ij:kl"
|
||||
|
||||
# IPMI details
|
||||
ipmi_address="0.0.0.0"
|
||||
ipmi_password="password"
|
||||
ipmi_user="username"
|
||||
|
||||
# Image details belonging to a particular node
|
||||
image_vcpu=12
|
||||
image_ram=254802
|
||||
ironic_disk_available=80 # for the scheduler, this should be BIGGER than image_disk_root
|
||||
image_disk_root=40
|
||||
image_total_disk_size=3600
|
||||
image_cpu_arch="x86_64"
|
||||
RESOURCE_CLASS="baremetal.general"
|
||||
NOVA_RESOURCE_FLAVOR_NAME=${RESOURCE_CLASS//./_}
|
||||
NOVA_RESOURCE_FLAVOR_NAME=$(echo ${NOVA_RESOURCE_FLAVOR_NAME//-/_} | awk '{print toupper($0)}')
|
||||
|
||||
KERNEL_IMAGE=$(glance image-list | awk '/baremetal-ubuntu-xenial.vmlinuz/ {print $2}')
|
||||
INITRAMFS_IMAGE=$(glance image-list | awk '/baremetal-ubuntu-xenial.initrd/ {print $2}')
|
||||
DEPLOY_RAMDISK=$(glance image-list | awk '/ironic-deploy.initramfs/ {print $2}')
|
||||
DEPLOY_KERNEL=$(glance image-list | awk '/ironic-deploy.kernel/ {print $2}')
|
||||
|
||||
if ironic node-list | grep "$inventory_hostname"; then
|
||||
NODE_UUID=$(ironic --ironic-api-version 1.22 node-list | awk "/$inventory_hostname/ {print \$2}")
|
||||
else
|
||||
NODE_UUID=$(ironic --ironic-api-version 1.22 node-create \
|
||||
-d agent_ipmitool \
|
||||
-i ipmi_address="$ipmi_address" \
|
||||
-i ipmi_password="$ipmi_password" \
|
||||
-i ipmi_username="$ipmi_user" \
|
||||
-i deploy_ramdisk="${DEPLOY_RAMDISK}" \
|
||||
-i deploy_kernel="${DEPLOY_KERNEL}" \
|
||||
-p cpus=$image_vcpu \
|
||||
-p memory_mb=$image_ram \
|
||||
-p local_gb=$ironic_disk_available \
|
||||
-p size=$image_total_disk_size \
|
||||
-p cpu_arch=$image_cpu_arch \
|
||||
-p capabilities=boot_option:local,disk_label:gpt \
|
||||
-n $inventory_hostname \
|
||||
--resource-class ${RESOURCE_CLASS} | awk '/ uuid / {print $4}')
|
||||
ironic --ironic-api-version 1.22 port-create -n "$NODE_UUID" \
|
||||
-a $Port1NIC_MACAddress
|
||||
fi
|
||||
|
||||
# flavor creation
|
||||
if ! nova flavor-list | grep "${RESOURCE_CLASS}"; then
|
||||
FLAVOR_ID=$(cat /proc/sys/kernel/random/uuid)
|
||||
nova flavor-create ${RESOURCE_CLASS} ${FLAVOR_ID} ${image_ram} ${image_disk_root} ${image_vcpu}
|
||||
nova flavor-key ${RESOURCE_CLASS} set cpu_arch=x86_64
|
||||
nova flavor-key ${RESOURCE_CLASS} set capabilities:boot_option="local"
|
||||
nova flavor-key ${RESOURCE_CLASS} set capabilities:disk_label="gpt"
|
||||
nova flavor-key ${RESOURCE_CLASS} set resources:VCPU=0
|
||||
nova flavor-key ${RESOURCE_CLASS} set resources:MEMORY_MB=0
|
||||
nova flavor-key ${RESOURCE_CLASS} set resources:DISK_GB=0
|
||||
nova flavor-key ${RESOURCE_CLASS} set resources:CUSTOM_${NOVA_RESOURCE_FLAVOR_NAME}=1
|
||||
fi
|
||||
|
||||
ironic --ironic-api-version 1.22 node-set-provision-state "${NODE_UUID}" manage
|
||||
sleep 1m # necessary to get power state
|
||||
ironic --ironic-api-version 1.22 node-set-provision-state "${NODE_UUID}" provide
|
Loading…
x
Reference in New Issue
Block a user