]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Defining VSphere tag category and tag for OS RHEL
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 23 Nov 2023 09:08:47 +0000 (10:08 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 23 Nov 2023 09:08:47 +0000 (10:08 +0100)
lib/cr_tf/config.py
lib/cr_tf/handler/files.py

index f9baf849f358e265dc93237608274a654c5aab04..c19eb8289fa60fbeddc820a53864ce6fab11722b 100644 (file)
@@ -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():
index 8832cf362186c840d5736acedb027621e2a8a678..38cae7ce17a4a3eec3f6f9d4b54efb7dad28bd8b 100644 (file)
@@ -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)