from .xlate import XLATOR
-__version__ = '3.0.4'
+__version__ = '3.1.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
self.project_dir = None
self.project_name = None
+ self._terraform_root_dir = None
+
self.all_vms = {}
self.existing_vms = []
raise ValueError(msg)
self._stop_at_step = v
+ # -----------------------------------------------------------
+ @property
+ def terraform_root_dir(self):
+ """Root directory of all terraform directories."""
+ if self.is_venv:
+ return self.base_dir.parent
+ return self._terraform_root_dir
+
+ # -----------------------------------------------------------
+ @property
+ def full_project_name(self):
+ """Complete project name with parent paths."""
+ if not self.project_name:
+ return None
+ if not self.project_dir:
+ return None
+ if not self.terraform_root_dir:
+ return self.project_name
+ return os.path.relpath(str(self.project_dir), self.terraform_root_dir)
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res['stop_at_step'] = self.stop_at_step
res['steps'] = copy.copy(self.steps)
res['tz_name'] = self.tz_name
+ res['terraform_root_dir'] = self.terraform_root_dir
+ res['full_project_name'] = self.full_project_name
res['vsphere'] = {}
for vsphere_name in self.vsphere.keys():
res['vsphere'][vsphere_name] = self.vsphere[vsphere_name].as_dict(short=short)
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
+ cdir = copy.copy(self.project_dir).parent
+ while i > 0:
+ git_dir = cdir / '.git'
+ if git_dir.is_dir():
+ self._terraform_root_dir = cdir
+ break
+ i -= 1
+ if cdir == cdir.parent:
+ break
+ cdir = cdir.parent
+ if not self._terraform_root_dir:
+ msg = _("Did not found root terraform directory above {!r}.").format(
+ str(self.project_dir))
+ LOG.warn(msg)
+
LOG.info(_("Finished step {!r}.").format('collect-folders'))
if self.stop_at_step == 'collect-folders':
raise AbortExecution('collect-folders')