From 2190184e15a30b00dc085cc23c33c563a651d8b7 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 25 Sep 2019 17:21:14 +0200 Subject: [PATCH] Start refactoring lib/cr_tf/config.py --- lib/cr_tf/config.py | 60 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/cr_tf/config.py b/lib/cr_tf/config.py index 0684846..af2a2d7 100644 --- a/lib/cr_tf/config.py +++ b/lib/cr_tf/config.py @@ -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) -- 2.39.5