Skip to content
Snippets Groups Projects
Verified Commit 153165bd authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

add "reload" parameter to load_data

parent ef2ce24c
No related branches found
No related tags found
No related merge requests found
......@@ -11,24 +11,11 @@ Env vars optional:
Install requirements:
- Alpine using `requirements.txt`:
- On Alpine, install with:
apk --no-cache add python3-dev build-base libffi-dev linux-headers \
openssl-dev openssh-client
pip3 install -r requirements.txt
- Alpine using packages (much faster):
apk --no-cache add ansible musl-dev linux-headers gcc py3-psutil \
openssh-client
pip3 install requests tabulate testinfra
- Debian (using deb packages):
apt-get install -y --no-install-recommends ansible gcc libc6-dev \
python3-pip python3-setuptools python3-wheel \
python3-psutil
pip3 install requests tabulate testinfra
"""
import argparse
......@@ -205,7 +192,7 @@ def main(): # pylint: disable=too-many-statements,too-many-branches,too-many-lo
if args.terminate_droplet:
# In case none of the subparser's functions have been called, load data
clus.load_data()
clus.load_data(reload=False)
cosmos.terminate_droplets_by_name(clus.hostname)
if not hasattr(args, 'func') and not args.terminate_droplet:
......
......@@ -45,12 +45,19 @@ class Cluster:
if load_data:
self.load_data()
def load_data(self):
"""Loads cluster data from inventory.yml and settings.yml files"""
def load_data(self, reload=True):
"""
Loads cluster data from inventory.yml and settings.yml files
:param bool reload: If reload is True (default), load values from the
files even if they are already set in the class.
"""
with open(self.settings_file, 'r') as stream:
settings = yaml.safe_load(stream)
self.ip_address = settings['ip_address']
self.domain = settings['domain']
if self.ip_address is None or reload:
self.ip_address = settings['ip_address']
if self.domain is None or reload:
self.domain = settings['domain']
log.debug("""Read data from settings.yml:
ip address: %s
......@@ -58,8 +65,9 @@ class Cluster:
with open(self.inventory_file, 'r') as stream:
inventory = yaml.safe_load(stream)
# Work with the master node from the inventory
self.hostname = inventory['all']['children']['master']['hosts']
# Work with the master node from the inventory
if self.hostname is None or reload:
self.hostname = inventory['all']['children']['master']['hosts']
log.debug('Read data from inventory.yml:\n\thostname: %s', self.hostname)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment