libvirt: Add override variable for DISK variables
Add an override variable for the DISK file location for each node in a virtual lab. Introduced the ability to set disk file location for all nodes in a config file. (was hardcoded to /var/lib/libvirt/images) This enhancement enables better utilization of the host's disk resources, allowing for more complex deployments such as 'Distributed Cloud'. Test plan: PASS: pylint, flake8, bashate PASS: Regression for default and madcloud examples PASS: Able to change what is storage and how many are applied PASS: Copy default.yaml and modify values of disk directories for nodes and compare to default.yaml Story: 2010816 Task: 48397 Change-Id: If19404ed151739c4abcbd5f2c3b9fb62132ed6fe Signed-off-by: Bailey Henry <Henry.Bailey@windriver.com>
This commit is contained in:
parent
2462c55035
commit
02f67a5746
@ -1,6 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
import ipaddress
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
@ -12,29 +18,186 @@ import yaml
|
||||
BRIDGE_LIMIT = 9
|
||||
|
||||
# Fields that should be set in a Yaml configuration file
|
||||
SUPPORTED_HOST_KEYS = ['disk']
|
||||
|
||||
GEN_FIELDS = ('bridge_interface', 'controller', 'worker',
|
||||
'domain_dir', 'storage')
|
||||
'domain_dir', 'storage', 'default_disk')
|
||||
|
||||
IP_FIELDS = ('ext_network', 'ext_IP')
|
||||
|
||||
HOST_FIELDS = ('controllerlist', 'workerlist', 'storagelist')
|
||||
|
||||
NODES_NUM = ('worker_nodes_num', 'storage_nodes_num')
|
||||
|
||||
FIELDS = GEN_FIELDS + IP_FIELDS + NODES_NUM
|
||||
FIELDS = GEN_FIELDS + IP_FIELDS + HOST_FIELDS + NODES_NUM
|
||||
|
||||
HELP_TEXT = """
|
||||
use:
|
||||
./config.py <config_file> <key>
|
||||
./config.py <config_file> <list key> <index> <key>
|
||||
./config.py --validate <config_file>
|
||||
"""
|
||||
|
||||
|
||||
# Allows the user to see how this script is used
|
||||
def print_help():
|
||||
print("use: ./config.py <config_file> <key>"
|
||||
" or use: ./config.py --validate <config_file>",
|
||||
file=sys.stderr)
|
||||
print(HELP_TEXT, file=sys.stderr)
|
||||
|
||||
|
||||
# Checks if there are any unexpected fields in the file
|
||||
def existence_check(data):
|
||||
for key in data:
|
||||
if key not in FIELDS:
|
||||
print('unexpected field: %s' % key)
|
||||
print('unexpected field: %s' % key, file=sys.stderr)
|
||||
|
||||
|
||||
def host_key_check(listdata, printname):
|
||||
# listdata is a list of hosts
|
||||
index = 0
|
||||
error = 0
|
||||
for host in listdata:
|
||||
index += 1
|
||||
# each host in the list is a dictionary of keys
|
||||
if type(host) is not dict:
|
||||
print('list item %s in %s is not dictionary' %
|
||||
(index, printname), file=sys.stderr)
|
||||
error += 1
|
||||
continue
|
||||
for key in host.keys():
|
||||
if key not in SUPPORTED_HOST_KEYS:
|
||||
print('unexpected field %s in host %s of %s' %
|
||||
(key, index, printname), file=sys.stderr)
|
||||
return error
|
||||
|
||||
|
||||
# Iterated through lists and returns specific fields
|
||||
def item_from_list(data, fields, num):
|
||||
try:
|
||||
listdata = data[fields[0]]
|
||||
key2 = fields[2]
|
||||
|
||||
if key2 in SUPPORTED_HOST_KEYS:
|
||||
try:
|
||||
item = listdata[num][key2]
|
||||
except (IndexError, KeyError):
|
||||
# Node index is not config yaml
|
||||
# Specified data key is not in config yaml
|
||||
item = data['default_disk']
|
||||
|
||||
else:
|
||||
print('ValueError: key %s is not supported' % key2,
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
except TypeError as e:
|
||||
print('Sanity: incorrect key type for list or dictionary read:'
|
||||
' % s ' % e, file=sys.stderr)
|
||||
item = data['default_disk']
|
||||
return(item)
|
||||
|
||||
|
||||
# Checks if the input is valid path
|
||||
def check_path(value, field):
|
||||
if not isinstance(value, str):
|
||||
print(field + ' does not contain string value for path',
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
if not os.path.exists(value):
|
||||
print(field + ' does not contain valid path', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
# Validation for checking general fields
|
||||
def general_validate(value, field):
|
||||
if (field == 'bridge_interface' and len(value) > BRIDGE_LIMIT):
|
||||
print(field + ' variable too long', file=sys.stderr)
|
||||
return 1
|
||||
if (field == 'default_disk'):
|
||||
return (check_path(value, field))
|
||||
if value.isalnum() is False:
|
||||
print(field + ' is not alphanumerical', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
# Validation for checking IP addresses
|
||||
def ip_validate(value, field):
|
||||
try:
|
||||
IP, netmask = value.split('/')
|
||||
except ValueError:
|
||||
print(field + ' does not look like IP/mask', file=sys.stderr)
|
||||
return 1
|
||||
try:
|
||||
netmask = int(netmask)
|
||||
except ValueError:
|
||||
print(field + ': not a valid netmask', file=sys.stderr)
|
||||
return 1
|
||||
try:
|
||||
ipaddress.ip_address(IP)
|
||||
except ValueError:
|
||||
print(field + ' is not a valid IP address', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
# Validation for checking paths
|
||||
def host_validate(value, field, data):
|
||||
errnum = 0
|
||||
if isinstance(value, list):
|
||||
# This is a host list, check if the keys are recognized
|
||||
errnum = host_key_check(value, field)
|
||||
if errnum:
|
||||
return errnum
|
||||
|
||||
# validate each recognized key
|
||||
for i in range(len(value)):
|
||||
for key in SUPPORTED_HOST_KEYS:
|
||||
fieldlist = [field, i, key]
|
||||
item = item_from_list(data, fieldlist, i)
|
||||
if key == 'disk':
|
||||
err = check_path(item, field)
|
||||
if not err == 0:
|
||||
print('%s index %s has bad path' % (field, i),
|
||||
file=sys.stderr)
|
||||
errnum += err
|
||||
else:
|
||||
print(field + ' is not a list',
|
||||
file=sys.stderr)
|
||||
errnum += 1
|
||||
return errnum
|
||||
|
||||
|
||||
# Validation for the amount of nodes set
|
||||
def nodes_validate(value, field, data):
|
||||
nodes_num = value
|
||||
if type(value) is not int:
|
||||
try:
|
||||
nodes_num = int(value)
|
||||
except ValueError:
|
||||
print(field + ' does not have an integer', file=sys.stderr)
|
||||
return 1
|
||||
if (field == 'worker_nodes_num'):
|
||||
try:
|
||||
listdata = data['workerlist']
|
||||
except KeyError:
|
||||
# this error is printed by key check for workerlist
|
||||
return 1
|
||||
if (len(listdata) != (nodes_num + 1)):
|
||||
print('Amount of worker nodes allocated not equal to'
|
||||
' amount set', file=sys.stderr)
|
||||
return 1
|
||||
if (field == 'storage_nodes_num'):
|
||||
try:
|
||||
listdata = data['storagelist']
|
||||
except KeyError:
|
||||
# this error is printed by key check for storagelist
|
||||
return 1
|
||||
if (len(listdata) != (nodes_num + 1)):
|
||||
print('Amount of storage nodes allocated not equal to'
|
||||
' amount set', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
# Opens the config file and returns its contents
|
||||
@ -70,76 +233,72 @@ def validator(config_file):
|
||||
try:
|
||||
value = data[field]
|
||||
except KeyError:
|
||||
print(' %s does not exist' % field)
|
||||
print(' %s does not exist' % field, file=sys.stderr)
|
||||
ERROR += 1
|
||||
continue
|
||||
|
||||
# Checking that most fields are alphanumerical
|
||||
if (field in GEN_FIELDS):
|
||||
|
||||
# Checks if bridge_interface is smaller that nine
|
||||
# characters long
|
||||
|
||||
if (field == 'bridge_interface' and len(value) > BRIDGE_LIMIT):
|
||||
|
||||
print(field + ' variable too long')
|
||||
ERROR += 1
|
||||
|
||||
if value.isalnum() is False:
|
||||
print(field + ' is not alphanumerical')
|
||||
ERROR += 1
|
||||
ERROR += general_validate(value, field)
|
||||
|
||||
# Checking that there are valid IPv4 addresses
|
||||
elif (field in IP_FIELDS):
|
||||
# Removing the /24 subnet mask
|
||||
try:
|
||||
IP, netmask = value.split('/')
|
||||
except ValueError:
|
||||
print(field + ' does not look like IP/mask', file=sys.stderr)
|
||||
ERROR += 1
|
||||
continue
|
||||
ERROR += ip_validate(value, field)
|
||||
|
||||
try:
|
||||
netmask = int(netmask)
|
||||
except ValueError:
|
||||
print(field + ': not a valid netmask')
|
||||
ERROR += 1
|
||||
|
||||
try:
|
||||
ipaddress.ip_address(IP)
|
||||
except (ValueError):
|
||||
print(field + ' is not a valid IP address', file=sys.stderr)
|
||||
ERROR += 1
|
||||
elif (field in HOST_FIELDS):
|
||||
ERROR += host_validate(value, field, data)
|
||||
|
||||
# Checking that node counts are numbers
|
||||
elif (field in NODES_NUM):
|
||||
try:
|
||||
int(value)
|
||||
except ValueError:
|
||||
print(field + ' does not have an integer', file=sys.stderr)
|
||||
ERROR += 1
|
||||
ERROR += nodes_validate(value, field, data)
|
||||
|
||||
if ERROR > 0:
|
||||
print('total errors: %s ' % ERROR)
|
||||
print('total errors: %s ' % ERROR, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Allows the user to read any value in their configuration file
|
||||
def readvalue(config_file, key):
|
||||
data = reader(config_file)
|
||||
def readvalue(config_file, fieldlist):
|
||||
|
||||
try:
|
||||
value = data[key]
|
||||
data = reader(config_file)
|
||||
if len(fieldlist) == 3:
|
||||
try:
|
||||
datalist = data[fieldlist[0]]
|
||||
except KeyError as e:
|
||||
print('KeyError: %s' % e, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if isinstance(datalist, list):
|
||||
|
||||
try:
|
||||
num = (int(fieldlist[1]))
|
||||
except ValueError as e:
|
||||
print('ValueError: %s' % e, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
result = item_from_list(data, fieldlist, num)
|
||||
print(result)
|
||||
else:
|
||||
print('TypeError: %s is not list' % fieldlist[0], file=sys.stderr)
|
||||
sys.exit(1)
|
||||
elif len(fieldlist) == 1:
|
||||
try:
|
||||
value = data[fieldlist[0]]
|
||||
except (KeyError) as e:
|
||||
print('KeyError: %s' % e, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print(value)
|
||||
|
||||
except KeyError as e:
|
||||
print('KeyError: %s' % e, file=sys.stderr)
|
||||
else:
|
||||
print_help()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
|
||||
if '--help' in args:
|
||||
if '--help' in args or not len(args):
|
||||
print_help()
|
||||
sys.exit(0)
|
||||
|
||||
@ -154,19 +313,20 @@ if __name__ == "__main__":
|
||||
print_help()
|
||||
sys.exit(1)
|
||||
|
||||
if len(args) == 2:
|
||||
if len(args) > 4:
|
||||
print("Error: too many arguments.",
|
||||
file=sys.stderr)
|
||||
print_help()
|
||||
sys.exit(1)
|
||||
|
||||
if len(args) >= 2:
|
||||
input_file = args[0]
|
||||
input_key = args[1]
|
||||
readvalue(input_file, input_key)
|
||||
input_keys = args[1:]
|
||||
|
||||
readvalue(input_file, input_keys)
|
||||
|
||||
elif len(args) < 2:
|
||||
print("Error: missing required arguments.",
|
||||
file=sys.stderr)
|
||||
print_help()
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
print("Error: too many arguments.",
|
||||
file=sys.stderr)
|
||||
print_help()
|
||||
sys.exit(1)
|
||||
|
@ -5,6 +5,16 @@ ext_IP: 10.10.10.1/24
|
||||
controller: controller
|
||||
worker: worker
|
||||
storage: storage
|
||||
worker_nodes_num: '1'
|
||||
storage_nodes_num: '1'
|
||||
worker_nodes_num: 1
|
||||
storage_nodes_num: 1
|
||||
domain_dir: 'vms'
|
||||
default_disk: /var/lib/libvirt/images
|
||||
controllerlist:
|
||||
- disk: /var/lib/libvirt/images
|
||||
- disk: /var/lib/libvirt/images
|
||||
workerlist:
|
||||
- disk: /var/lib/libvirt/images
|
||||
- disk: /var/lib/libvirt/images
|
||||
storagelist:
|
||||
- disk: /var/lib/libvirt/images
|
||||
- disk: /var/lib/libvirt/images
|
||||
|
@ -4,6 +4,10 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
source set_defaults.sh
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
|
||||
|
||||
@ -28,27 +32,16 @@ if [[ -z ${CONFIGURATION} ]]; then
|
||||
fi
|
||||
|
||||
configuration_check ${CONFIGURATION}
|
||||
|
||||
CONFIGURATION=${CONFIGURATION:-simplex}
|
||||
CONTROLLER=${CONTROLLER:-controller}
|
||||
DOMAIN_DIRECTORY=${DOMAIN_DIRECTORY:-vms}
|
||||
|
||||
destroy_controller ${CONFIGURATION} ${CONTROLLER}
|
||||
|
||||
if ([ "$CONFIGURATION" == "controllerstorage" ] || [ "$CONFIGURATION" == "dedicatedstorage" ]); then
|
||||
WORKER=${WORKER:-worker}
|
||||
WORKER_NODES_NUMBER=${WORKER_NODES_NUMBER:-1}
|
||||
for ((i=0; i<=$WORKER_NODES_NUMBER; i++)); do
|
||||
WORKER_NODE=${CONFIGURATION}-${WORKER}-${i}
|
||||
destroy_node "worker" $WORKER_NODE
|
||||
destroy_node "worker" ${i} ${CONFIGURATION}
|
||||
done
|
||||
fi
|
||||
|
||||
if ([ "$CONFIGURATION" == "dedicatedstorage" ]); then
|
||||
STORAGE=${STORAGE:-storage}
|
||||
STORAGE_NODES_NUMBER=${STORAGE_NODES_NUMBER:-1}
|
||||
for ((i=0; i<=$STORAGE_NODES_NUMBER; i++)); do
|
||||
STORAGE_NODE=${CONFIGURATION}-${STORAGE}-${i}
|
||||
destroy_node "storage" ${STORAGE_NODE}
|
||||
destroy_node "storage" ${i} ${CONFIGURATION}
|
||||
done
|
||||
fi
|
||||
|
@ -1,8 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr}
|
||||
EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-10.10.10.0/24}
|
||||
EXTERNAL_IP=${EXTERNAL_IP:-10.10.10.1/24}
|
||||
source set_defaults.sh
|
||||
|
||||
for i in {1..4}; do
|
||||
BRIDGE_INTERFACE_NAME=${BRIDGE_INTERFACE}$i
|
||||
|
@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
source set_defaults.sh
|
||||
|
||||
usage() {
|
||||
echo "$0 [-h] [-c <configuration>] [-i <iso image>]"
|
||||
@ -34,6 +41,24 @@ configuration_check() {
|
||||
fi
|
||||
}
|
||||
|
||||
get_disk(){
|
||||
|
||||
local field=$1
|
||||
local num=$2
|
||||
local diskdir
|
||||
|
||||
if [ -n "$CONFIG_FILE" ] && [ -f "$CONFIG_FILE" ]; then
|
||||
diskdir=$( ./config.py $CONFIG_FILE $field $num disk )
|
||||
fi
|
||||
|
||||
if [ -z "$diskdir" ]; then
|
||||
# DEFAULT_DISK_DIR is always defined because the calling scripts
|
||||
# is required to source set_defaults.sh
|
||||
diskdir=$DEFAULT_DISK_DIR
|
||||
fi
|
||||
echo $diskdir
|
||||
}
|
||||
|
||||
# delete a node's disk file in a safe way
|
||||
delete_disk() {
|
||||
local fpath="$1"
|
||||
@ -77,6 +102,8 @@ create_controller() {
|
||||
local BRIDGE_INTERFACE=$3
|
||||
local ISOIMAGE=$4
|
||||
local DOMAIN_FILE
|
||||
local DISK_LOCATION
|
||||
|
||||
if ([ "$CONFIGURATION" == "simplex" ]); then
|
||||
CONTROLLER_NODE_NUMBER=0
|
||||
else
|
||||
@ -85,6 +112,15 @@ create_controller() {
|
||||
for ((i=0; i<=$CONTROLLER_NODE_NUMBER; i++)); do
|
||||
CONTROLLER_NODE=${CONFIGURATION}-${CONTROLLER}-${i}
|
||||
DOMAIN_FILE=${DOMAIN_DIRECTORY}/${CONTROLLER_NODE}.xml
|
||||
|
||||
DISK_LOCATION="$( get_disk controllerlist $i )"
|
||||
mkdir -p "${DISK_LOCATION}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -n "Cannot create directory for virtual disks: "
|
||||
echo "${DISK_LOCATION}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ([ "$CONFIGURATION" == "simplex" ] || [ "$CONFIGURATION" == "duplex" ]); then
|
||||
DISK_0_SIZE=600
|
||||
cp controller_allinone.xml ${DOMAIN_FILE}
|
||||
@ -94,20 +130,20 @@ create_controller() {
|
||||
fi
|
||||
sed -i -e "
|
||||
s,NAME,${CONTROLLER_NODE},
|
||||
s,DISK0,/var/lib/libvirt/images/${CONTROLLER_NODE}-0.img,
|
||||
s,DISK1,/var/lib/libvirt/images/${CONTROLLER_NODE}-1.img,
|
||||
s,DISK0,${DISK_LOCATION}/${CONTROLLER_NODE}-0.img,
|
||||
s,DISK1,${DISK_LOCATION}/${CONTROLLER_NODE}-1.img,
|
||||
s,%BR1%,${BRIDGE_INTERFACE}1,
|
||||
s,%BR2%,${BRIDGE_INTERFACE}2,
|
||||
s,%BR3%,${BRIDGE_INTERFACE}3,
|
||||
s,%BR4%,${BRIDGE_INTERFACE}4,
|
||||
" ${DOMAIN_FILE}
|
||||
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/${CONTROLLER_NODE}-0.img ${DISK_0_SIZE}G
|
||||
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/${CONTROLLER_NODE}-1.img 200G
|
||||
sudo qemu-img create -f qcow2 ${DISK_LOCATION}/${CONTROLLER_NODE}-0.img ${DISK_0_SIZE}G
|
||||
sudo qemu-img create -f qcow2 ${DISK_LOCATION}/${CONTROLLER_NODE}-1.img 200G
|
||||
if ([ "$CONFIGURATION" == "simplex" ] || [ "$CONFIGURATION" == "duplex" ]); then
|
||||
sed -i -e "
|
||||
s,DISK2,/var/lib/libvirt/images/${CONTROLLER_NODE}-2.img,
|
||||
s,DISK2,${DISK_LOCATION}/${CONTROLLER_NODE}-2.img,
|
||||
" ${DOMAIN_FILE}
|
||||
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/${CONTROLLER_NODE}-2.img 200G
|
||||
sudo qemu-img create -f qcow2 ${DISK_LOCATION}/${CONTROLLER_NODE}-2.img 200G
|
||||
fi
|
||||
if [ $i -eq 0 ]; then
|
||||
sed -i -e "s,ISO,${ISOIMAGE}," ${DOMAIN_FILE}
|
||||
@ -125,12 +161,14 @@ create_controller() {
|
||||
destroy_controller() {
|
||||
local CONFIGURATION=$1
|
||||
local CONTROLLER=$2
|
||||
local DISK_LOCATION
|
||||
if ([ "$CONFIGURATION" == "simplex" ]); then
|
||||
CONTROLLER_NODE_NUMBER=0
|
||||
else
|
||||
CONTROLLER_NODE_NUMBER=1
|
||||
fi
|
||||
for ((i=0; i<=$CONTROLLER_NODE_NUMBER; i++)); do
|
||||
DISK_LOCATION="$( get_disk controllerlist $i )"
|
||||
CONTROLLER_NODE=${CONFIGURATION}-${CONTROLLER}-${i}
|
||||
DOMAIN_FILE=$DOMAIN_DIRECTORY/$CONTROLLER_NODE.xml
|
||||
if virsh list --all --name | grep ${CONTROLLER_NODE}; then
|
||||
@ -140,10 +178,10 @@ destroy_controller() {
|
||||
sudo virsh destroy ${CONTROLLER_NODE}
|
||||
fi
|
||||
sudo virsh undefine ${CONTROLLER_NODE}
|
||||
delete_disk /var/lib/libvirt/images/${CONTROLLER_NODE}-0.img
|
||||
delete_disk /var/lib/libvirt/images/${CONTROLLER_NODE}-1.img
|
||||
delete_disk ${DISK_LOCATION}/${CONTROLLER_NODE}-0.img
|
||||
delete_disk ${DISK_LOCATION}/${CONTROLLER_NODE}-1.img
|
||||
if ([ "$CONFIGURATION" == "simplex" ] || [ "$CONFIGURATION" == "duplex" ]); then
|
||||
delete_disk /var/lib/libvirt/images/${CONTROLLER_NODE}-2.img
|
||||
delete_disk ${DISK_LOCATION}/${CONTROLLER_NODE}-2.img
|
||||
fi
|
||||
[ -e ${DOMAIN_FILE} ] && delete_xml ${DOMAIN_FILE}
|
||||
fi
|
||||
@ -153,16 +191,35 @@ destroy_controller() {
|
||||
# Create a Node
|
||||
create_node() {
|
||||
local IDENTITY=$1
|
||||
local NODE=$2
|
||||
local BRIDGE_INTERFACE=$3
|
||||
local INDEX=$2
|
||||
local CONFIGURATION=$3
|
||||
local BRIDGE_INTERFACE=$4
|
||||
local DISK_LOCATION
|
||||
local NODE
|
||||
|
||||
if [ $IDENTITY == 'worker' ]; then
|
||||
NODE="${CONFIGURATION}-${WORKER}-${INDEX}"
|
||||
DISK_LOCATION="$( get_disk workerlist $INDEX )"
|
||||
elif [ $IDENTITY == 'storage' ]; then
|
||||
NODE="${CONFIGURATION}-${STORAGE}-${INDEX}"
|
||||
DISK_LOCATION="$( get_disk storagelist $INDEX )"
|
||||
fi
|
||||
mkdir -p "${DISK_LOCATION}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -n "Cannot create directory for virtual disks: "
|
||||
echo "${DISK_LOCATION}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local DOMAIN_FILE=${DOMAIN_DIRECTORY}/${NODE}.xml
|
||||
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/${NODE}-0.img 200G
|
||||
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/${NODE}-1.img 200G
|
||||
|
||||
sudo qemu-img create -f qcow2 ${DISK_LOCATION}/${NODE}-0.img 200G
|
||||
sudo qemu-img create -f qcow2 ${DISK_LOCATION}/${NODE}-1.img 200G
|
||||
cp ${IDENTITY}.xml ${DOMAIN_FILE}
|
||||
sed -i -e "
|
||||
s,NAME,${NODE},;
|
||||
s,DISK0,/var/lib/libvirt/images/${NODE}-0.img,;
|
||||
s,DISK1,/var/lib/libvirt/images/${NODE}-1.img,
|
||||
s,DISK0,${DISK_LOCATION}/${NODE}-0.img,;
|
||||
s,DISK1,${DISK_LOCATION}/${NODE}-1.img,
|
||||
s,%BR1%,${BRIDGE_INTERFACE}1,
|
||||
s,%BR2%,${BRIDGE_INTERFACE}2,
|
||||
s,%BR3%,${BRIDGE_INTERFACE}3,
|
||||
@ -174,8 +231,21 @@ create_node() {
|
||||
# Delete a Node
|
||||
destroy_node() {
|
||||
local IDENTITY=$1
|
||||
local NODE=$2
|
||||
local INDEX=$2
|
||||
local CONFIGURATION=$3
|
||||
local DISK_LOCATION
|
||||
local NODE
|
||||
|
||||
if [ $IDENTITY == 'worker' ]; then
|
||||
NODE="${CONFIGURATION}-${WORKER}-${INDEX}"
|
||||
DISK_LOCATION="$( get_disk workerlist $INDEX )"
|
||||
elif [ $IDENTITY == 'storage' ]; then
|
||||
NODE="${CONFIGURATION}-${STORAGE}-${INDEX}"
|
||||
DISK_LOCATION="$( get_disk storagelist $INDEX )"
|
||||
fi
|
||||
|
||||
local DOMAIN_FILE=$DOMAIN_DIRECTORY/$NODE.xml
|
||||
|
||||
if virsh list --all --name | grep ${NODE}; then
|
||||
STATUS=$(virsh list --all | grep ${NODE} | awk '{ print $3}')
|
||||
if ([ "$STATUS" == "running" ])
|
||||
@ -183,8 +253,8 @@ destroy_node() {
|
||||
sudo virsh destroy ${NODE}
|
||||
fi
|
||||
sudo virsh undefine ${NODE}
|
||||
delete_disk /var/lib/libvirt/images/${NODE}-0.img
|
||||
delete_disk /var/lib/libvirt/images/${NODE}-1.img
|
||||
delete_disk ${DISK_LOCATION}/${NODE}-0.img
|
||||
delete_disk ${DISK_LOCATION}/${NODE}-1.img
|
||||
[ -e ${DOMAIN_FILE} ] && delete_xml ${DOMAIN_FILE}
|
||||
fi
|
||||
}
|
||||
|
@ -1,7 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
source set_defaults.sh
|
||||
|
||||
GET_CFG="./config.py $1"
|
||||
|
||||
export CONFIG_FILE="$1"
|
||||
export BRIDGE_INTERFACE="$( ${GET_CFG} bridge_interface )"
|
||||
export EXTERNAL_NETWORK="$( ${GET_CFG} ext_network )"
|
||||
export EXTERNAL_IP="$( ${GET_CFG} ext_IP )"
|
||||
@ -11,3 +19,4 @@ export STORAGE="$( ${GET_CFG} storage )"
|
||||
export WORKER_NODES_NUMBER="$( ${GET_CFG} worker_nodes_num )"
|
||||
export STORAGE_NODES_NUMBER="$( ${GET_CFG} storage_nodes_num )"
|
||||
export DOMAIN_DIRECTORY="$( ${GET_CFG} domain_dir )"
|
||||
export DEFAULT_DISK_DIR="$( ${GET_CFG} default_disk )"
|
||||
|
25
libvirt/set_defaults.sh
Normal file
25
libvirt/set_defaults.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
# This script specifies default values for lab configuration,
|
||||
# these environment variables are meant to be overridden by the
|
||||
# user if they choose. The default values in this file will be
|
||||
# used if not specified by the user.
|
||||
|
||||
export BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr}
|
||||
export EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-10.10.10.0/24}
|
||||
export EXTERNAL_IP=${EXTERNAL_IP:-10.10.10.1/24}
|
||||
|
||||
export CONTROLLER=${CONTROLLER:-controller}
|
||||
export WORKER=${WORKER:-worker}
|
||||
export STORAGE=${STORAGE:-storage}
|
||||
|
||||
export WORKER_NODES_NUMBER=${WORKER_NODES_NUMBER:-1}
|
||||
export STORAGE_NODES_NUMBER=${STORAGE_NODES_NUMBER:-1}
|
||||
|
||||
export DOMAIN_DIRECTORY=${DOMAIN_DIRECTORY:-vms}
|
||||
export DEFAULT_DISK_DIR=${DEFAULT_DISK_DIR:-/var/lib/libvirt/images}
|
@ -4,6 +4,10 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
source set_defaults.sh
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
|
||||
source ${SCRIPT_DIR}/functions.sh
|
||||
@ -32,32 +36,30 @@ fi
|
||||
iso_image_check ${ISOIMAGE}
|
||||
configuration_check ${CONFIGURATION}
|
||||
|
||||
CONFIGURATION=${CONFIGURATION:-simplex}
|
||||
BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr}
|
||||
CONTROLLER=${CONTROLLER:-controller}
|
||||
WORKER=${WORKER:-worker}
|
||||
WORKER_NODES_NUMBER=${WORKER_NODES_NUMBER:-1}
|
||||
STORAGE=${STORAGE:-storage}
|
||||
STORAGE_NODES_NUMBER=${STORAGE_NODES_NUMBER:-1}
|
||||
DOMAIN_DIRECTORY=${DOMAIN_DIRECTORY:-vms}
|
||||
|
||||
bash ${SCRIPT_DIR}/destroy_configuration.sh -c $CONFIGURATION
|
||||
|
||||
[ ! -d ${DOMAIN_DIRECTORY} ] && mkdir ${DOMAIN_DIRECTORY}
|
||||
|
||||
create_controller $CONFIGURATION $CONTROLLER $BRIDGE_INTERFACE $ISOIMAGE
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ([ "$CONFIGURATION" == "controllerstorage" ] || [ "$CONFIGURATION" == "dedicatedstorage" ]); then
|
||||
for ((i=0; i<=$WORKER_NODES_NUMBER; i++)); do
|
||||
WORKER_NODE=${CONFIGURATION}-${WORKER}-${i}
|
||||
create_node "worker" ${WORKER_NODE} ${BRIDGE_INTERFACE}
|
||||
create_node "worker" ${i} ${CONFIGURATION} ${BRIDGE_INTERFACE}
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if ([ "$CONFIGURATION" == "dedicatedstorage" ]); then
|
||||
for ((i=0; i<=$STORAGE_NODES_NUMBER; i++)); do
|
||||
STORAGE_NODE=${CONFIGURATION}-${STORAGE}-${i}
|
||||
create_node "storage" ${STORAGE_NODE} ${BRIDGE_INTERFACE}
|
||||
create_node "storage" ${i} ${CONFIGURATION} ${BRIDGE_INTERFACE}
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
|
@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
source set_defaults.sh
|
||||
|
||||
usage() {
|
||||
echo "$0 [-h]"
|
||||
@ -18,10 +25,6 @@ while getopts "i:" o; do
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr}
|
||||
EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-10.10.10.0/24}
|
||||
EXTERNAL_IP=${EXTERNAL_IP:-10.10.10.1/24}
|
||||
|
||||
if [[ -r /sys/class/net/${BRIDGE_INTERFACE}1 ]]; then
|
||||
echo "${BRIDGE_INTERFACE}1 exists, cowardly refusing to overwrite it, exiting..."
|
||||
exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user