prototypes: bifrost: Check we are running the destroy-env.sh as root
[releng.git] / prototypes / bifrost / scripts / destroy-env.sh
1 #!/bin/bash
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 ##############################################################################
10
11 # We need to execute everything as root
12 if [[ $(whoami) != "root" ]]; then
13     echo "Error: This script must be run as root!"
14     exit 1
15 fi
16
17 virsh destroy jumphost.opnfvlocal || true
18 virsh destroy controller00.opnfvlocal || true
19 virsh destroy compute00.opnfvlocal || true
20 virsh undefine jumphost.opnfvlocal || true
21 virsh undefine controller00.opnfvlocal || true
22 virsh undefine compute00.opnfvlocal || true
23
24 service ironic-conductor stop
25
26 echo "removing from database"
27 mysql -u root ironic --execute "truncate table ports;"
28 mysql -u root ironic --execute "delete from node_tags;"
29 mysql -u root ironic --execute "delete from nodes;"
30 mysql -u root ironic --execute "delete from conductors;"
31 echo "removing leases"
32 [[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases
33 echo "removing logs"
34 rm -rf /var/log/libvirt/baremetal_logs/*.log
35
36 # clean up dib images only if requested explicitly
37 CLEAN_DIB_IMAGES=${CLEAN_DIB_IMAGES:-false}
38
39 if [ $CLEAN_DIB_IMAGES = "true" ]; then
40     rm -rf /httpboot/*
41     rm -rf /tftpboot/*
42 fi
43
44 # remove VM disk images
45 rm -rf /var/lib/libvirt/images/*.qcow2
46
47 echo "restarting services"
48 service dnsmasq restart
49 service libvirtd restart
50 service ironic-api restart
51 service ironic-conductor start
52 service ironic-inspector restart