forked from patrikarlos/NSO_A2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operate
executable file
·52 lines (46 loc) · 1.46 KB
/
operate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#private key is to be given as 3rd argument.
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <openrc> <tag> <ssh_key>"
exit 1
fi
OPENRC=$1
TAG=$2
SSH_KEY=$3
install_dependencies() {
touch install.log
chmod 777 install.log
echo "Checking and installing necessary dependencies..."
if ! command -v python3 &> install.log; then
sudo apt update > install.log
sudo apt install -y python3 > install.log
fi
if ! command -v pip3 &> install.log; then
sudo apt install -y python3-pip > install.log
fi
if ! command -v openstack &> install.log; then
sudo apt install -y python3-openstackclient > install.log
fi
if ! command -v ansible &> install.log; then
sudo add-apt-repository --yes --update ppa:ansible/ansible > install.log
sudo apt install -y ansible > install.log
fi
if ! dpkg-query -W -f='${Status}' software-properties-common 2>install.log | grep -q "ok installed"; then
sudo apt install -y software-properties-common > install.log
fi
pip3 install python-openstackclient argparse subprocess32 python-openstacksdk > install.log
}
# Function to set up permissions
setup_permissions() {
chmod 777 scripts/operate.py
}
invoke_python_script() {
source $OPENRC
echo "sourced $OPENRC"
python3 scripts/operate.py $OPENRC $TAG $SSH_KEY || exit 1
}
# Main script execution
install_dependencies
setup_permissions
invoke_python_script
echo " operate phase complete"