]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Adding and using lib/cr_vmware_tpl/handler.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 21 Mar 2018 10:36:36 +0000 (11:36 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 21 Mar 2018 10:36:36 +0000 (11:36 +0100)
lib/cr_vmware_tpl/app.py
lib/cr_vmware_tpl/handler.py [new file with mode: 0644]

index 67dfc6797ec4994d1e9c6bb8187e9bc03582c5a0..1edc615f73d3b11924487a5f6e6fb5ad068d1065 100644 (file)
@@ -32,7 +32,9 @@ from .obj import PpBaseObject
 
 from .config import CrTplConfiguration
 
-__version__ = '0.2.3'
+from .handler import CrTplHandler
+
+__version__ = '0.3.1'
 LOG = logging.getLogger(__name__)
 
 
@@ -157,6 +159,9 @@ class CrTplApplication(PpBaseObject):
         self.config = CrTplConfiguration(
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
 
+        self.handler = CrTplHandler(
+            appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+
         self.post_init()
 
     # -----------------------------------------------------------
@@ -400,6 +405,8 @@ class CrTplApplication(PpBaseObject):
                 h=self.config.vsphere_host, u=self.config.vsphere_user)
             self.config.password = getpass.getpass(prompt=prompt)
 
+        self.handler.config = self.config
+        self.handler.initialized = True
         self.initialized = True
 
     # -------------------------------------------------------------------------
@@ -422,6 +429,7 @@ class CrTplApplication(PpBaseObject):
         """
 
         LOG.info("Starting ...")
+        self.handler()
 
     # -------------------------------------------------------------------------
     def __call__(self):
diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py
new file mode 100644 (file)
index 0000000..8db51e5
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2018 by Frank Brehm, Berlin
+@summary: A handler module for creating the VMWare template
+"""
+from __future__ import absolute_import
+
+# Standard module
+import sys
+import os
+import logging
+
+# Third party modules
+import six
+
+
+# Own modules
+from .errors import FunctionNotImplementedError, PpError
+
+from .obj import PpBaseObject
+
+from .config import CrTplConfiguration
+
+__version__ = '0.1.1'
+LOG = logging.getLogger(__name__)
+
+
+# =============================================================================
+class HandlerError(PpError, RuntimeError):
+    """Base error class for all exceptions happened during
+    execution this handler"""
+
+    pass
+
+
+# =============================================================================
+class CrTplHandler(PpBaseObject):
+    """
+    A handler class for creating a vSphere template.
+    """
+
+    # -------------------------------------------------------------------------
+    def __init__(
+        self, appname=None, verbose=0, version=__version__, base_dir=None,
+            config=None, initialized=False):
+
+        super(CrTplHandler, self).__init__(
+            appname=appname,
+            verbose=verbose,
+            version=version,
+            base_dir=base_dir,
+            initialized=False,
+        )
+
+        self.config = config
+
+        if initialized:
+            self.initialized = True
+
+    # -------------------------------------------------------------------------
+    def __call__(self):
+        """Executing the underlying action."""
+
+        if not self.initialized:
+            raise HandlerError("{}-object not initialized.".format(self.__class__.__name__))
+
+        if not isinstance(self.config, CrTplConfiguration):
+            raise HandlerError((
+                "self.config is not a CrTplConfiguration-instance, but a "
+                "{}-instance instead.").format(self.config.__class__.__name__))
+
+        LOG.debug("Starting ...")
+
+
+# =============================================================================
+
+if __name__ == "__main__":
+
+    pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list