diff --git a/openappstack/__main__.py b/openappstack/__main__.py index 0f8a8274a10e7f181baf7ffd149cbb8c787121bd..f85238fb5346cf44fe9436bfbd22d573eecb4a86 100755 --- a/openappstack/__main__.py +++ b/openappstack/__main__.py @@ -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: diff --git a/openappstack/cluster.py b/openappstack/cluster.py index 26d7538ddacdfa4f18276094f0f06ebf82d006ec..f03834f9d6eda12e405255d30e25ea27cb57196d 100644 --- a/openappstack/cluster.py +++ b/openappstack/cluster.py @@ -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)