2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 RedHat and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 # We need to execute everything as root
12 if [[ $(whoami) != "root" ]]; then
13 echo "Error: This script must be run as root!"
17 # Delete all libvirt VMs and hosts from vbmc (look for a port number)
18 for vm in $(vbmc list | awk '/[0-9]/{{ print $2 }}'); do
19 virsh destroy $vm || true
20 virsh undefine $vm || true
24 service ironic-conductor stop || true
26 echo "removing inventory files created by previous builds"
27 rm -rf /tmp/baremetal.*
29 echo "removing ironic database"
30 if $(which mysql &> /dev/null); then
31 mysql -u root ironic --execute "drop database ironic;"
33 echo "removing leases"
34 [[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases
36 rm -rf /var/log/libvirt/baremetal_logs/*
38 # clean up dib images only if requested explicitly
39 CLEAN_DIB_IMAGES=${CLEAN_DIB_IMAGES:-false}
41 if [ $CLEAN_DIB_IMAGES = "true" ]; then
42 rm -rf /httpboot /tftpboot
43 mkdir /httpboot /tftpboot
44 chmod -R 755 /httpboot /tftpboot
47 # remove VM disk images
48 rm -rf /var/lib/libvirt/images/*.qcow2
50 echo "restarting services"
51 service dnsmasq restart || true
52 service libvirtd restart
53 service ironic-api restart || true
54 service ironic-conductor start || true
55 service ironic-inspector restart || true