From 92d5562f6dfa1f5d2d984022dc7ccdb14350a501 Mon Sep 17 00:00:00 2001 From: Bailey Henry Date: Tue, 11 Jul 2023 10:17:28 -0400 Subject: [PATCH] libvirt: Add configuration files for mad and default yaml files for mad and default Test plan: PASS: Create configuration files with all needed data PASS: Ensure all data is usable PASS: No Pylint/Bashate errors PASS: Regression test succeeded Story: 2010816 Task: 48350 Change-Id: Id7a380a64348501396b139ebb57ff0f42825ffce Signed-off-by: Bailey Henry --- libvirt/README.rst | 11 ++++++++--- libvirt/config.py | 46 +++++++++++++++++++++++++++++++++++++++++++ libvirt/default.yaml | 10 ++++++++++ libvirt/madcloud.yaml | 10 ++++++++++ libvirt/readconfig.sh | 13 ++++++++++++ 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100755 libvirt/config.py create mode 100755 libvirt/default.yaml create mode 100644 libvirt/madcloud.yaml create mode 100755 libvirt/readconfig.sh diff --git a/libvirt/README.rst b/libvirt/README.rst index 8d6c860..498202a 100644 --- a/libvirt/README.rst +++ b/libvirt/README.rst @@ -28,8 +28,9 @@ an interactive shell that configures everything. Here's an example:: export EXTERNAL_NETWORK=172.30.20.0/24 export EXTERNAL_IP=172.30.20.1/24 -There is also a script ``cleanup_network.sh`` that will remove networking -configuration from libvirt. +Using ``./readconfig.sh madcloud.yaml`` also sets the madcloud +environment variables. Use ``default.yaml`` or ``madcloud.yaml`` as +templates to make custom configurations. Networking ---------- @@ -40,7 +41,11 @@ Set the BRIDGE_INTERFACE environment variable if you need to change stxbr to something unique. The ``destroy_network.sh`` script does the reverse, and should not be used lightly. -It should also only be used after all of the VMs created below have been destroyed. +It should also only be used after all of the VMs created below have been +destroyed. + +There is also a script ``cleanup_network.sh`` that will remove networking +configuration from libvirt. Controllers ----------- diff --git a/libvirt/config.py b/libvirt/config.py new file mode 100755 index 0000000..1191433 --- /dev/null +++ b/libvirt/config.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +import sys +import yaml + +def print_help(): + print("./config.py ", + file=sys.stderr) + +def readvalue(config_file, key): + + try: + with open(config_file, 'r', encoding="utf-8") as f: + data = yaml.load(f, Loader=yaml.Loader) + + value = data[key] + print(value) + + except yaml.YAMLError as e: + print('YAMLError: %s' % e, file=sys.stderr) + except KeyError as e: + print('KeyError: %s' % e, file=sys.stderr) + +if __name__ == "__main__": + args = sys.argv[1:] + + if '--help' in args: + print_help() + sys.exit(1) + + if len(args) == 2: + input_file = args[0] + input_key = args[1] + readvalue(input_file, input_key) + + 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) diff --git a/libvirt/default.yaml b/libvirt/default.yaml new file mode 100755 index 0000000..4b7a476 --- /dev/null +++ b/libvirt/default.yaml @@ -0,0 +1,10 @@ +--- +bridge_interface: stxbr +ext_network: 10.10.10.0/24 +ext_IP: 10.10.10.1/24 +controller: controller +worker: worker +storage: storage +worker_nodes_num: '1' +storage_nodes_num: '1' +domain_dir: 'vms' diff --git a/libvirt/madcloud.yaml b/libvirt/madcloud.yaml new file mode 100644 index 0000000..149f99e --- /dev/null +++ b/libvirt/madcloud.yaml @@ -0,0 +1,10 @@ +--- +bridge_interface: madbr +ext_network: 172.30.20.0/24 +ext_IP: 172.30.20.1/24 +controller: madcloud +worker: madnode +storage: storage +worker_nodes_num: '1' +storage_nodes_num: '1' +domain_dir: 'vms' diff --git a/libvirt/readconfig.sh b/libvirt/readconfig.sh new file mode 100755 index 0000000..b47c2ab --- /dev/null +++ b/libvirt/readconfig.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +GET_CFG="./config.py $1" + +export BRIDGE_INTERFACE="$( ${GET_CFG} bridge_interface )" +export EXTERNAL_NETWORK="$( ${GET_CFG} ext_network )" +export EXTERNAL_IP="$( ${GET_CFG} ext_IP )" +export CONTROLLER="$( ${GET_CFG} controller )" +export WORKER="$( ${GET_CFG} worker )" +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 )"