Move generation of baremetal VM names to lib/ironic
The create-nodes script currently receives a total # of VMs to create and creates them all, generating their names on the fly. This moves that name generation to lib/ironic and makes the script create only single VMs as directed. This centralizes the naming of things to lib/ironic and will make it easier to reference these things elsewhere. Change-Id: I98e61f7188e027e690303e32aff7cd2347f6d2c2
This commit is contained in:
parent
a2c241774a
commit
22ec45e63a
27
lib/ironic
27
lib/ironic
@ -354,6 +354,15 @@ function init_ironic {
|
|||||||
create_ironic_cache_dir
|
create_ironic_cache_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# _ironic_bm_vm_names() - Generates list of names for baremetal VMs.
|
||||||
|
function _ironic_bm_vm_names {
|
||||||
|
local idx
|
||||||
|
local num_vms=$(($IRONIC_VM_COUNT - 1))
|
||||||
|
for idx in $(seq 0 $num_vms); do
|
||||||
|
echo "baremetal${IRONIC_VM_NETWORK_BRIDGE}_${idx}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# start_ironic() - Start running processes, including screen
|
# start_ironic() - Start running processes, including screen
|
||||||
function start_ironic {
|
function start_ironic {
|
||||||
# Start Ironic API server, if enabled.
|
# Start Ironic API server, if enabled.
|
||||||
@ -449,10 +458,13 @@ function create_bridge_and_vms {
|
|||||||
else
|
else
|
||||||
local log_arg=""
|
local log_arg=""
|
||||||
fi
|
fi
|
||||||
sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-nodes \
|
local vm_name
|
||||||
$IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \
|
for vm_name in $(_ironic_bm_vm_names); do
|
||||||
amd64 $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \
|
sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-node $vm_name \
|
||||||
$log_arg" >> $IRONIC_VM_MACS_CSV_FILE
|
$IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \
|
||||||
|
amd64 $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \
|
||||||
|
$log_arg" >> $IRONIC_VM_MACS_CSV_FILE
|
||||||
|
done
|
||||||
create_ovs_taps
|
create_ovs_taps
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +667,12 @@ function cleanup_baremetal_basic_ops {
|
|||||||
chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE
|
chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE
|
||||||
fi
|
fi
|
||||||
sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH
|
sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH
|
||||||
sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-nodes $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE"
|
|
||||||
|
local vm_name
|
||||||
|
for vm_name in $(_ironic_bm_vm_names); do
|
||||||
|
sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-node $vm_name $IRONIC_VM_NETWORK_BRIDGE"
|
||||||
|
done
|
||||||
|
|
||||||
sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override
|
sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override
|
||||||
restart_service xinetd
|
restart_service xinetd
|
||||||
sudo iptables -D INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true
|
sudo iptables -D INPUT -d $HOST_IP -p udp --dport 69 -j ACCEPT || true
|
||||||
|
25
tools/ironic/scripts/cleanup-node
Executable file
25
tools/ironic/scripts/cleanup-node
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# **cleanup-nodes**
|
||||||
|
|
||||||
|
# Cleans up baremetal poseur nodes and volumes created during ironic setup
|
||||||
|
# Assumes calling user has proper libvirt group membership and access.
|
||||||
|
|
||||||
|
set -exu
|
||||||
|
|
||||||
|
LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
|
||||||
|
LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
|
||||||
|
|
||||||
|
NAME=$1
|
||||||
|
NETWORK_BRIDGE=$2
|
||||||
|
|
||||||
|
export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
|
||||||
|
|
||||||
|
VOL_NAME="$NAME.qcow2"
|
||||||
|
virsh list | grep -q $NAME && virsh destroy $NAME
|
||||||
|
virsh list --inactive | grep -q $NAME && virsh undefine $NAME
|
||||||
|
|
||||||
|
if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then
|
||||||
|
virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
|
||||||
|
virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL
|
||||||
|
fi
|
@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# **cleanup-nodes**
|
|
||||||
|
|
||||||
# Cleans up baremetal poseur nodes and volumes created during ironic setup
|
|
||||||
# Assumes calling user has proper libvirt group membership and access.
|
|
||||||
|
|
||||||
set -exu
|
|
||||||
|
|
||||||
LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
|
|
||||||
LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
|
|
||||||
|
|
||||||
VM_COUNT=$1
|
|
||||||
NETWORK_BRIDGE=$2
|
|
||||||
|
|
||||||
export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
|
|
||||||
|
|
||||||
for (( idx=0; idx<$VM_COUNT; idx++ )); do
|
|
||||||
NAME="baremetal${NETWORK_BRIDGE}_${idx}"
|
|
||||||
VOL_NAME="baremetal${NETWORK_BRIDGE}-${idx}.qcow2"
|
|
||||||
virsh list | grep -q $NAME && virsh destroy $NAME
|
|
||||||
virsh list --inactive | grep -q $NAME && virsh undefine $NAME
|
|
||||||
|
|
||||||
if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then
|
|
||||||
virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
|
|
||||||
virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL
|
|
||||||
fi
|
|
||||||
done
|
|
@ -9,19 +9,19 @@ set -ex
|
|||||||
# Keep track of the devstack directory
|
# Keep track of the devstack directory
|
||||||
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
|
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
|
||||||
|
|
||||||
CPU=$1
|
NAME=$1
|
||||||
MEM=$(( 1024 * $2 ))
|
CPU=$2
|
||||||
|
MEM=$(( 1024 * $3 ))
|
||||||
# extra G to allow fuzz for partition table : flavor size and registered size
|
# extra G to allow fuzz for partition table : flavor size and registered size
|
||||||
# need to be different to actual size.
|
# need to be different to actual size.
|
||||||
DISK=$(( $3 + 1))
|
DISK=$(( $4 + 1))
|
||||||
|
|
||||||
case $4 in
|
case $5 in
|
||||||
i386) ARCH='i686' ;;
|
i386) ARCH='i686' ;;
|
||||||
amd64) ARCH='x86_64' ;;
|
amd64) ARCH='x86_64' ;;
|
||||||
*) echo "Unsupported arch $4!" ; exit 1 ;;
|
*) echo "Unsupported arch $4!" ; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
TOTAL=$(($5 - 1))
|
|
||||||
BRIDGE=$6
|
BRIDGE=$6
|
||||||
EMULATOR=$7
|
EMULATOR=$7
|
||||||
LOGDIR=$8
|
LOGDIR=$8
|
||||||
@ -53,32 +53,27 @@ if [ -f /etc/debian_version ]; then
|
|||||||
PREALLOC="--prealloc-metadata"
|
PREALLOC="--prealloc-metadata"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DOMS=""
|
if [ -n "$LOGDIR" ] ; then
|
||||||
for idx in $(seq 0 $TOTAL) ; do
|
VM_LOGGING="--console-log $LOGDIR/${NAME}_console.log"
|
||||||
NAME="baremetal${BRIDGE}_${idx}"
|
else
|
||||||
if [ -n "$LOGDIR" ] ; then
|
VM_LOGGING=""
|
||||||
VM_LOGGING="--console-log $LOGDIR/${NAME}_console.log"
|
fi
|
||||||
else
|
VOL_NAME="${NAME}.qcow2"
|
||||||
VM_LOGGING=""
|
|
||||||
fi
|
|
||||||
DOMS="$DOMS $NAME"
|
|
||||||
VOL_NAME="baremetal${BRIDGE}-${idx}.qcow2"
|
|
||||||
(virsh list --all | grep -q $NAME) && continue
|
|
||||||
|
|
||||||
virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
|
if ! virsh list --all | grep -q $NAME; then
|
||||||
virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL >&2
|
virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
|
||||||
virsh vol-create-as $LIBVIRT_STORAGE_POOL ${VOL_NAME} ${DISK}G --format qcow2 $PREALLOC >&2
|
virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL >&2
|
||||||
volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME)
|
virsh vol-create-as $LIBVIRT_STORAGE_POOL ${VOL_NAME} ${DISK}G --format qcow2 $PREALLOC >&2
|
||||||
# Pre-touch the VM to set +C, as it can only be set on empty files.
|
volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME)
|
||||||
sudo touch "$volume_path"
|
# Pre-touch the VM to set +C, as it can only be set on empty files.
|
||||||
sudo chattr +C "$volume_path" || true
|
sudo touch "$volume_path"
|
||||||
$TOP_DIR/scripts/configure-vm \
|
sudo chattr +C "$volume_path" || true
|
||||||
--bootdev network --name $NAME --image "$volume_path" \
|
$TOP_DIR/scripts/configure-vm \
|
||||||
--arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER \
|
--bootdev network --name $NAME --image "$volume_path" \
|
||||||
--emulator $EMULATOR --network $BRIDGE $VM_LOGGING >&2
|
--arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER \
|
||||||
done
|
--emulator $EMULATOR --network $BRIDGE $VM_LOGGING >&2
|
||||||
|
|
||||||
for dom in $DOMS ; do
|
fi
|
||||||
# echo mac
|
|
||||||
virsh dumpxml $dom | grep "mac address" | head -1 | cut -d\' -f2
|
# echo mac
|
||||||
done
|
virsh dumpxml $NAME | grep "mac address" | head -1 | cut -d\' -f2
|
Loading…
Reference in New Issue
Block a user