From 7a9d4552bdb65db5f9f20a52e35dc3f223c26dc9 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 23 Nov 2023 10:08:47 +0100 Subject: [PATCH] Defining VSphere tag category and tag for OS RHEL --- lib/cr_tf/config.py | 60 +++++++++++++++++++++++++++++++++++++- lib/cr_tf/handler/files.py | 29 +++++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/lib/cr_tf/config.py b/lib/cr_tf/config.py index f9baf84..c19eb82 100644 --- a/lib/cr_tf/config.py +++ b/lib/cr_tf/config.py @@ -32,7 +32,7 @@ from .vs_config import VsphereConfig from .xlate import XLATOR -__version__ = '1.8.3' +__version__ = '1.9.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -70,6 +70,14 @@ class CrTfConfiguration(BaseConfiguration): }, } + default_vsphere_tag_cat_os_id = 'OS' + default_vsphere_tag_cat_os_name = 'OS' + default_vsphere_tag_cat_os_desc = 'The operating system of a VM.' + + default_vsphere_tag_os_rhel_id = 'os_rhel' + default_vsphere_tag_os_rhel_name = 'rhel' + default_vsphere_tag_os_rhel_desc = 'RedHat Enterprise Linux' + default_min_root_size_gb = 32.0 default_tz_name = 'Europe/Berlin' default_guest_id = "oracleLinux7_64Guest" @@ -124,6 +132,14 @@ class CrTfConfiguration(BaseConfiguration): self._rhsm_user = self.default_rhsm_user self._rhsm_password = None + self._vsphere_tag_cat_os_id = self.default_vsphere_tag_cat_os_id + self._vsphere_tag_cat_os_name = self.default_vsphere_tag_cat_os_name + self._vsphere_tag_cat_os_desc = self.default_vsphere_tag_cat_os_desc + + self._vsphere_tag_os_rhel_id = self.default_vsphere_tag_os_rhel_id + self._vsphere_tag_os_rhel_name = self.default_vsphere_tag_os_rhel_name + self._vsphere_tag_os_rhel_desc = self.default_vsphere_tag_os_rhel_desc + self._no_pdns = False self.puppet_envs_add = set() @@ -223,6 +239,42 @@ class CrTfConfiguration(BaseConfiguration): raise ValueError(msg) self._pdns_api_timeout = val + # ----------------------------------------------------------- + @property + def vsphere_tag_cat_os_id(self): + """The terraform ID of the VSphere tag category 'OS'.""" + return self._vsphere_tag_cat_os_id + + # ----------------------------------------------------------- + @property + def vsphere_tag_cat_os_name(self): + """The name of the VSphere OS tag category.""" + return self._vsphere_tag_cat_os_name + + # ----------------------------------------------------------- + @property + def vsphere_tag_cat_os_desc(self): + """The description of the VSphere OS tag category.""" + return self._vsphere_tag_cat_os_desc + + # ----------------------------------------------------------- + @property + def vsphere_tag_os_rhel_id(self): + """The terraform ID of the VSphere tag for OS RHEL.""" + return self._vsphere_tag_os_rhel_id + + # ----------------------------------------------------------- + @property + def vsphere_tag_os_rhel_name(self): + """The name of the VSphere tag for OS RHEL.""" + return self._vsphere_tag_os_rhel_name + + # ----------------------------------------------------------- + @property + def vsphere_tag_os_rhel_desc(self): + """The description of the VSphere tag for OS RHEL.""" + return self._vsphere_tag_os_rhel_desc + # ----------------------------------------------------------- @property def vm_root_password(self): @@ -413,6 +465,12 @@ class CrTfConfiguration(BaseConfiguration): res['root_min_size'] = self.root_min_size res['root_max_size'] = self.root_max_size res['rhsm_user'] = self.rhsm_user + res['vsphere_tag_cat_os_id'] = self.vsphere_tag_cat_os_id + res['vsphere_tag_cat_os_name'] = self.vsphere_tag_cat_os_name + res['vsphere_tag_cat_os_desc'] = self.vsphere_tag_cat_os_desc + res['vsphere_tag_os_rhel_id'] = self.vsphere_tag_os_rhel_id + res['vsphere_tag_os_rhel_name'] = self.vsphere_tag_os_rhel_name + res['vsphere_tag_os_rhel_desc'] = self.vsphere_tag_os_rhel_desc res['vsphere'] = {} for vsphere_name in self.vsphere.keys(): diff --git a/lib/cr_tf/handler/files.py b/lib/cr_tf/handler/files.py index 8832cf3..38cae7c 100644 --- a/lib/cr_tf/handler/files.py +++ b/lib/cr_tf/handler/files.py @@ -28,7 +28,7 @@ from ..errors import AbortExecution from ..xlate import XLATOR -__version__ = '0.4.2' +__version__ = '0.5.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -500,6 +500,33 @@ class CrTfHandlerFilesMixin(): ''') content += tpl.format(tn=tpl_tf_name, n=tname) + tpl = textwrap.dedent('''\ + resource "vsphere_tag_category" "{cid}" {{ + name = "{cname}" + description = "{cdesc}" + cardinality = "SINGLE" + associable_types = [ + "VirtualMachine", + ] + }} + + resource "vsphere_tag" "{tid}" {{ + name = "{tname}" + category_id = "${{vsphere_tag_category.{cid}.id}}" + description = "{tdesc}" + }} + + ''').format( + cid=self.config.vsphere_tag_cat_os_id, + cname=self.config.vsphere_tag_cat_os_name, + cdesc=self.config.vsphere_tag_cat_os_desc, + tid=self.config.vsphere_tag_os_rhel_id, + tname=self.config.vsphere_tag_os_rhel_name, + tdesc=self.config.vsphere_tag_os_rhel_desc, + ) + content += tpl + + if self.simulate: if self.verbose: print(content) -- 2.39.5