]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Start refactoring lib/cr_tf/config.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Sep 2019 15:21:14 +0000 (17:21 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Sep 2019 15:21:14 +0000 (17:21 +0200)
lib/cr_tf/config.py

index 068484688632e528d7e16edbd87c0bc7599facbb..af2a2d789f394d94d9b9666917756fbf06a49a8b 100644 (file)
@@ -18,6 +18,9 @@ from pathlib import Path
 import pytz
 
 # Own modules
+
+from fb_tools.obj import FbBaseObject
+
 from fb_tools.config import ConfigError, BaseConfiguration
 
 from fb_tools.common import to_bool, RE_FQDN
@@ -29,7 +32,7 @@ from fb_tools.pdns import DEFAULT_USE_HTTPS as DEFAULT_PDNS_API_USE_HTTPS
 
 from .xlate import XLATOR
 
-__version__ = '1.1.5'
+__version__ = '1.2.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -44,6 +47,58 @@ class CrTfConfigError(ConfigError):
     pass
 
 
+# =============================================================================
+class VsphereConfig(FbBaseObject):
+    """Class for encapsulation of config data of a connection to a VSPhere center."""
+
+    default_port = 443
+    default_user = 'Administrator@vsphere.local'
+    default_dc = 'vmcc'
+    default_cluster = 'vmcc-l105-01'
+
+    default_template_name = 'oracle-linux-7-template'
+
+    # -------------------------------------------------------------------------
+    def __init__(
+        self, appname=None, verbose=0, version=__version__, base_dir=None, name=None,
+            host=None, port=None, user=None, password=None, dc=None, cluster=None,
+            template_name=None, initialized=False):
+
+        self._name = None
+        self._host = None
+        self._port = self.default_port
+        self._user = self.default_user
+        self._password = None
+        self._dc = self.default_dc
+        self._cluster = self.default_cluster
+        self._template_name = self.default_template_name
+
+        super(VsphereConfig, self).__init__(
+            appname=appname, verbose=verbose, version=version,
+            base_dir=base_dir, initialized=False,
+        )
+
+        if name is not None:
+            self.name = name
+        if host is not None:
+            self.host = host
+        if port is not None:
+            self.port = port
+        if user is not None:
+            self.user = user
+        if password is not None:
+            self.password = password
+        if dc is not None:
+            self.dc = dc
+        if cluster is not None:
+            self.cluster = cluster
+        if template_name is not None:
+            self.template_name = template_name
+
+        if initialized:
+            self.initialized = True
+
+
 # =============================================================================
 class CrTfConfiguration(BaseConfiguration):
     """
@@ -51,12 +106,13 @@ class CrTfConfiguration(BaseConfiguration):
     and methods to read it from configuration files.
     """
 
-    default_vsphere_host = 'vcs01.ppbrln.internal'
     default_vsphere_port = 443
     default_vsphere_user = 'Administrator@vsphere.local'
     default_vsphere_dc = 'vmcc'
     default_vsphere_cluster = 'vmcc-l105-01'
+
     default_template_name = 'oracle-linux-7-template'
+
     default_pdns_master_server = 'master.pp-dns.com'
     default_pdns_api_port = DEFAULT_PDNS_API_PORT
     default_pdns_api_use_https = bool(DEFAULT_PDNS_API_USE_HTTPS)