]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Fix reading YAML file
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 1 Oct 2019 09:29:36 +0000 (11:29 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 1 Oct 2019 09:29:36 +0000 (11:29 +0200)
lib/cr_tf/handler.py
lib/cr_tf/terraform/vm.py

index caff48bb1b1464d32f421f0cc04852cdb6f3fc7c..4739628bb4c94e7ebaa9c594821155287bbccd84 100644 (file)
@@ -59,7 +59,7 @@ from .terraform.disk import TerraformDisk
 
 from .xlate import XLATOR
 
-__version__ = '2.9.0'
+__version__ = '2.9.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -886,8 +886,7 @@ class CreateTerraformHandler(BaseHandler):
 
         try:
             vm = TerraformVm.from_def(
-                vm_def, name=name, is_template=True, template_vm=template_vm,
-                default_cluster=self.config.vsphere_cluster, appname=self.appname,
+                vm_def, name=name, is_template=True, template_vm=template_vm, appname=self.appname,
                 verbose=self.verbose, base_dir=self.base_dir, simulate=self.simulate,
                 force=self.force, terminal_has_colors=self.terminal_has_colors)
         except Exception as e:
@@ -911,8 +910,7 @@ class CreateTerraformHandler(BaseHandler):
 
         try:
             vm = TerraformVm.from_def(
-                vm_def, is_template=False, template_vm=template_vm,
-                default_cluster=self.config.vsphere_cluster, appname=self.appname,
+                vm_def, is_template=False, template_vm=template_vm, appname=self.appname,
                 verbose=self.verbose, base_dir=self.base_dir, simulate=self.simulate,
                 force=self.force, terminal_has_colors=self.terminal_has_colors)
         except Exception as e:
index fa79142dfa0359674958dc13e63a4f35ee745768..953a2b227e8ee909c22d487a4f9bfc93d56ad053 100644 (file)
@@ -37,7 +37,7 @@ from .disk import TerraformDisk, TerraformDiskDict
 
 from .interface import TerraformInterface
 
-__version__ = '1.3.1'
+__version__ = '1.4.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -70,6 +70,8 @@ ngettext = XLATOR.ngettext
 class TerraformVm(HandlingObject):
     """A class encapsulating a VirtualMachine managed by Terraform."""
 
+    default_vsphere = 'life'
+
     default_boot_delay = 5
     default_customer = 'Pixelpark'
     default_ds_type = 'sata'
@@ -137,8 +139,9 @@ class TerraformVm(HandlingObject):
             customer=None, rootdisk_size=None, purpose=None, puppet_contact=None, puppet_role=None,
             puppet_customer=None, puppet_project=None, puppet_tier=None, puppet_env=None,
             vm_template=None, nameservers=None, has_backup=True, has_puppet=True,
-            already_existing=None):
+            already_existing=None, vsphere=None):
 
+        self._vsphere = self.default_vsphere
         self._is_template = bool(is_template)
         self._name = None
         self._fqdn = None
@@ -159,7 +162,7 @@ class TerraformVm(HandlingObject):
         self._puppet_tier = self.default_puppet_tier
         self._puppet_env = None
         self._puppet_role = self.default_puppet_role
-        self._vm_template = CrTfConfiguration.default_template_name
+        self._vm_template = None
         self._has_backup = bool(has_backup)
         self._has_puppet = bool(has_puppet)
         self._already_existing = False
@@ -182,7 +185,7 @@ class TerraformVm(HandlingObject):
             cluster=cluster, rootdisk_size=rootdisk_size, nameservers=nameservers, purpose=purpose,
             customer=customer, ds_cluster=ds_cluster, datastore=datastore, ds_type=ds_type,
             already_existing=already_existing, initialized=initialized, puppet_role=puppet_role,
-            puppet_project=puppet_project,)
+            puppet_project=puppet_project, vsphere=vsphere)
 
     # -------------------------------------------------------------------------
     def _post_init(self, name=None, fqdn=None, nameservers=None, initialized=False, **kwargs):
@@ -226,7 +229,7 @@ class TerraformVm(HandlingObject):
     @classmethod
     def from_def(
         cls, vm_def, name=None, is_template=False, template_vm=None, appname=None,
-            verbose=0, base_dir=None, simulate=False, force=False, default_cluster='',
+            verbose=0, base_dir=None, simulate=False, force=False,
             terminal_has_colors=False, initialized=False):
 
         if verbose > 2:
@@ -250,7 +253,7 @@ class TerraformVm(HandlingObject):
         else:
             vm = cls(
                 appname=appname, verbose=verbose, base_dir=base_dir, simulate=simulate,
-                force=force, is_template=is_template, name=name, cluster=default_cluster,
+                force=force, is_template=is_template, name=name,
                 terminal_has_colors=terminal_has_colors)
         vm.initialized = False
 
@@ -335,6 +338,10 @@ class TerraformVm(HandlingObject):
             vm.fqdn = value
             return True
 
+        if key.lower() == 'vsphere' and value:
+            vm.vsphere = value
+            return
+
         if key.lower() == 'cluster':
             vm.cluster = value
             return True
@@ -557,6 +564,7 @@ class TerraformVm(HandlingObject):
             puppet_env=self.puppet_env, puppet_role=self.puppet_role, nameservers=self.nameservers,
             rootdisk_size=self.rootdisk_size, has_backup=self.has_backup,
             has_puppet=self.has_puppet, puppet_project=self.puppet_project,
+            vsphere=self.vsphere,
         )
 
         vm.disks = copy.copy(self.disks)
@@ -676,6 +684,26 @@ class TerraformVm(HandlingObject):
 
         self._name = val
 
+    # -----------------------------------------------------------
+    @property
+    def vsphere(self):
+        """The name of the VSPhere from configuration, in which
+            the VM should be created."""
+        return self._vsphere
+
+    @vsphere.setter
+    def vsphere(self, value):
+        if value is None:
+            msg = _("The name of the vsphere may not be None.")
+            raise TerraformVmDefinitionError(msg)
+
+        val = str(value).strip()
+        if val == '':
+            msg = _("The name of the vsphere may not be empty.")
+            raise TerraformVmDefinitionError(msg)
+
+        self._vsphere = val
+
     # -----------------------------------------------------------
     @property
     def tf_name(self):
@@ -1150,6 +1178,7 @@ class TerraformVm(HandlingObject):
         res['rootdisk_size'] = self.rootdisk_size
         res['tf_name'] = self.tf_name
         res['vm_template'] = self.vm_template
+        res['vsphere'] = self.vsphere
 
         for interface in self.interfaces:
             res['interfaces'].append(interface.as_dict(short=short))