]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Reaching method create_vm()
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 Oct 2018 14:46:45 +0000 (16:46 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 Oct 2018 14:46:45 +0000 (16:46 +0200)
etc/create-vmware-template.ini.default
lib/cr_vmware_tpl/config.py
lib/cr_vmware_tpl/handler.py
python_fb_tools

index b7387c5bc274db0bb858c65d1a689822665ca995..b2373a3b39d14fcd4210cd1ce5fd434ea81038e6 100644 (file)
 
 ;vm = template.pixelpark.com
 
+;vmware_cfg_version = vmx-13
+
+;os_version = oracleLinux7_64Guest
+
 ;name = oracle-linux-7-template
 
 ;data_size_gb = 32
index 1e688a681010f548e4b22b4915dc9e7f402d0f1f..d306f4f137a09e31b055ed80e091b634e2a8cc23 100644 (file)
@@ -53,6 +53,8 @@ class CrTplConfiguration(BaseConfiguration):
     default_mac_address = '00:16:3e:54:ab:2b'
     default_max_wait_for_finish_install = 60 * 60
     default_max_nr_templates_stay = 4
+    default_vmware_cfg_version = 'vmx-13'
+    default_os_version = 'oracleLinux7_64Guest'
     min_max_wait_for_finish_install = 3 * 60
     max_max_wait_for_finish_install = 24 * 60 * 60
     limit_max_nr_templates_stay = 100
@@ -80,6 +82,8 @@ class CrTplConfiguration(BaseConfiguration):
         self.mac_address = self.default_mac_address
         self.max_wait_for_finish_install = self.default_max_wait_for_finish_install
         self.max_nr_templates_stay = self.default_max_nr_templates_stay
+        self.vmware_cfg_version = self.default_vmware_cfg_version
+        self.os_version = self.default_os_version
 
         self.excluded_datastores = []
 
@@ -243,6 +247,10 @@ class CrTplConfiguration(BaseConfiguration):
                 v = value.strip().lower()
                 if v:
                     self.mac_address = v
+            elif key.lower() == 'vmware_cfg_version':
+                self.vmware_cfg_version = value.strip()
+            elif key.lower() == 'os_version':
+                self.os_version = value.strip()
             elif key.lower() == 'max_wait_for_finish_install':
                 v = float(value)
                 if v < self.min_max_wait_for_finish_install:
index 970bba6020eebf94a5663d940babc1e1c5a0b327..b73bc057dedac026216beaca17a5fe33e7df6557 100644 (file)
@@ -89,7 +89,6 @@ class CrTplHandler(BaseHandler):
         self.tpl_vm_folder = None
         self.tpl_data_store = None
         self.tpl_network = None
-        self.tpl_cluster = None
         self.tpl_vm = None
         self.ts_start_install = None
         self.ts_finish_install = None
@@ -165,6 +164,11 @@ class CrTplHandler(BaseHandler):
         self.check_for_temp_tpl_vm(no_error=True)
         self.select_data_store()
 
+        if self.rotate_only:
+            LOG.warn("Only executing of template rotating.")
+        else:
+            self.create_vm()
+
         return 0
 
 
@@ -192,8 +196,8 @@ class CrTplHandler(BaseHandler):
             if self.rotate_only:
                 LOG.warn("Only executing of template rotating.")
             else:
-                self.check_network()
-                self.create_vm()
+#                self.check_network()
+#                self.create_vm()
                 self.tpl_vm = self.get_temp_tpl_vm()
                 if not self.tpl_vm:
                     raise HandlerError(
@@ -401,43 +405,6 @@ class CrTplHandler(BaseHandler):
 
         return tpl_list
 
-    # -------------------------------------------------------------------------
-    def check_network(self):
-
-        content = self.service_instance.RetrieveContent()
-        dc = self.get_obj(content, [vim.Datacenter], self.config.dc)
-
-        LOG.debug("Checking existence of network {!r} ...".format(self.config.network))
-
-        net = None
-        for child in dc.networkFolder.childEntity:
-            net = self._get_network(child)
-            if net:
-                break
-
-        if not net:
-            raise NetworkNotExistingError(self.config.network)
-        LOG.debug("Found network {!r}.".format(self.config.network))
-        self.tpl_network = net
-
-    # -------------------------------------------------------------------------
-    def _get_network(self, child, depth=1):
-
-        if hasattr(child, 'childEntity'):
-            if depth > self.max_depth:
-                return None
-            for sub_child in child.childEntity:
-                net = self._get_network(sub_child, depth + 1)
-                if net:
-                    return net
-            return None
-
-        if isinstance(child, (vim.Network, vim.DistributedVirtualSwitch)):
-            if child.summary.name == self.config.network:
-                return child
-
-        return None
-
     # -------------------------------------------------------------------------
     def select_data_store(self):
 
@@ -502,7 +469,7 @@ class CrTplHandler(BaseHandler):
         tstamp = datetime.datetime.now(tz=TZ).strftime('%Y-%m-%d_%H-%M')
 
         datastore_path = (
-            '[' + self.tpl_data_store.summary.name + '] template-' + tstamp + '/')
+            '[' + self.tpl_data_store.name + '] template-' + tstamp + '/')
         LOG.debug("Datastore path: {!r}".format(datastore_path))
         vm_path_name = datastore_path + self.config.template_vm + '.vmx'
         LOG.debug("VM path name: {!r}".format(vm_path_name))
@@ -595,17 +562,26 @@ class CrTplHandler(BaseHandler):
             memoryMB=self.config.ram_mb, memoryHotAddEnabled=True,
             numCPUs=self.config.num_cpus, cpuHotAddEnabled=True, cpuHotRemoveEnabled=True,
             files=vm_file_info,
-            guestId='oracleLinux64Guest',
-            version='vmx-11',
+            guestId=self.config.os_version,
+            version=self.config.vmware_cfg_version,
             bootOptions=boot_opts,
         )
 
-        if self.verbose > 2:
+        if self.verbose > 1:
             LOG.debug("Generated VM config:\n{}".format(pp(config)))
 
+        tpl_vm_folder = self.vsphere.get_vm_folder(self.config.folder)
+        if self.verbose > 1:
+            LOG.debug("VM-Folder object for template VM: {c} - {n!r}\n{t}".format(
+                c=tpl_vm_folder, n=tpl_vm_folder.name, t=pp(tpl_vm_folder.childType)))
+
+        if self.simulate:
+            LOG.info("Simulation mode - VM {!r} will not be created.".format(
+                self.config.template_vm))
+            return
+
         LOG.debug("Start Creating VM ...")
-        task = self.tpl_vm_folder.CreateVM_Task(
-            config=config, pool=self.tpl_cluster.resourcePool)
+        task = tpl_vm_folder.CreateVM_Task(config=config, pool=self.cluster.resource_pool)
 
         self.wait_for_tasks([task])
 
index b192448f42e85829d04a55044dfd9c244d9106be..1241c9751b81c690aec9e33401cffc7cf2fc4946 160000 (submodule)
@@ -1 +1 @@
-Subproject commit b192448f42e85829d04a55044dfd9c244d9106be
+Subproject commit 1241c9751b81c690aec9e33401cffc7cf2fc4946