from ..xlate import XLATOR
-__version__ = '4.2.0'
+__version__ = '4.2.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
tz = pytz.timezone(tz_name)
steps = (
- 'init', 'vmw-init', 'read-yaml', 'pdns-zones', 'vmw-test', 'collect-folders',
+ 'init', 'vmw-init', 'read-yaml', 'pdns-zones', 'consul', 'vmw-test', 'collect-folders',
'vmw-clusters', 'vmw-datastores', 'vmw-ds-clusters', 'vmw-vms', 'vmw-networks',
'vmw-templates', 'validate-yaml', 'validate-storage', 'validate-iface', 'validate-dns',
'perform-dns', 'project-dir', 'tf-files', 'ensure-vmw-folders',
'vmw-init': _('After initialisation of VSPhere handlers.'),
'read-yaml': _('After reading the given YAML file.'),
'pdns-zones': _('After retrieving all DNS zones from PowerDNS.'),
+ 'consul': _('Check Consul database and cleanup, if necessary.'),
'vmw-test': _('After testing VSPhere handlers.'),
'collect-folders': _('After collecting all VMWare and local folders.'),
'vmw-clusters': _('After collecting all VMWare clusters.'),
self.exec_pdns_zones()
+ print()
+ self.set_project(yaml_file)
+ self.check_consul()
+
print()
LOG.info(_("Collecting first information from vSPhere."))
self.test_vsphere_handlers()
- self.exec_collect_folders(yaml_file)
+ self.exec_collect_folders()
self.assign_default_vmw_values()
print()
print()
+ # -------------------------------------------------------------------------·
+ def check_consul(self):
+ """Checks for the existence of the project and cleaning it up, if it exists."""
+ if self.stop_at_step == 'consul':
+ self.incr_verbosity()
+
+ key = self.full_project_name
+ if not key:
+ key = self.project_name
+
+ print()
+ LOG.info(_(
+ 'Checking the Consul database for key {!r} and cleanup, if necessary ...').format(
+ key)
+ )
+
+ project_data = self.consul.get_key(key)
+ if not project_data:
+ LOG.info(_('No data for project {!r} found on Consul database.').format(key))
+ else:
+ msg = _('Found data for project {!r} on Consul database.').format(key)
+ LOG.warn(msg)
+ if self.verbose > 2:
+ msg = _('Found data:') + '\n' + pp(project_data)
+ LOG.debug(msg)
+
+ LOG.info(_("Finished step {!r}.").format('consul'))
+ if self.stop_at_step == 'consul':
+ raise AbortExecution('consul')
+
+ # -------------------------------------------------------------------------·
+ def set_project(self, yaml_file):
+ """Set project name and directory."""
+ LOG.debug(_('Setting project name and directory based on file {!r} ...').format(
+ str(yaml_file)))
+
+ yfile = Path(yaml_file)
+
+ yfile_base = yfile.name
+ yfile_dir = yfile.parent.resolve()
+ (yfile_stem, yfile_ext) = os.path.splitext(yfile_base)
+ self.project_name = yfile_stem
+ LOG.info(_("Project name is {!r}.").format(str(self.project_name)))
+ self.project_dir = yfile_dir / yfile_stem
+ LOG.info(_("Project directory is: {!r}.").format(str(self.project_dir)))
+
# -------------------------------------------------------------------------·
def exec_terraform(self):
import re
import sys
-from pathlib import Path
-
from operator import attrgetter
# Third party modules
from ..xlate import XLATOR
-__version__ = '1.0.0'
+__version__ = '1.0.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
"""A mixin module for the handler module for interacting with VMware/VSphere.."""
# -------------------------------------------------------------------------·
- def exec_collect_folders(self, yaml_file):
+ def exec_collect_folders(self):
if self.stop_at_step == 'collect-folders':
self.incr_verbosity()
self.vsphere_folders.sort(key=str.lower)
LOG.debug(_("Collected used vSphere folders:") + "\n" + pp(self.vsphere_folders))
- # Set project name and directory
- yfile = Path(yaml_file)
- yfile_base = yfile.name
- yfile_dir = yfile.parent.resolve()
- (yfile_stem, yfile_ext) = os.path.splitext(yfile_base)
- self.project_name = yfile_stem
- LOG.info(_("Project name is {!r}.").format(str(self.project_name)))
- self.project_dir = yfile_dir / yfile_stem
- LOG.info(_("Project directory is: {!r}.").format(str(self.project_dir)))
-
# Evaluating root terraform directory
if not self.is_venv:
i = 4