from .xlate import XLATOR
-__version__ = '1.4.1'
+__version__ = '1.5.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# -------------------------------------------------------------------------
def is_valid(self, raise_on_error=False):
+ name = '<{}>'.format(_('unknown'))
+ if self.name:
+ name = self.name
+ if self.verbose > 1:
+ LOG.debug(_("Checking validity of {o}-object {n!r} ...").format(
+ o=self.__class__.__name__, n=name))
+
error_lst = []
- attribs = ('name', 'host', 'user', 'password')
- for attrib in attribs:
+ mandatory_attribs = ('name', 'host', 'dc', 'cluster')
+ requested_attribs = ('user', 'password')
+
+ for attrib in mandatory_attribs:
cur_val = getattr(self, attrib, None)
if not cur_val:
- name = '<{}>'.format(_('unknown'))
- if self.name:
- name = self.name
msg = _("Attribute {a!r} of the {o}-object {n!r} is not set.").format(
a=attrib, o=self.__class__.__name__, n=name)
error_lst.append(msg)
if not raise_on_error:
LOG.error(msg)
+
if error_lst:
if raise_on_error:
nr = len(error_lst)
msg = msg.format(nr) + '\n * ' + '\n * '.join(error_lst)
raise CrTfConfigError(msg)
return False
+
+ for attrib in requested_attribs:
+ cur_val = getattr(self, attrib, None)
+ if not cur_val:
+ msg = _(
+ "Attribute {a!r} of the {o}-object {n!r} is not set, it "
+ "will be requestet during this script and on starting terraform.").format(
+ a=attrib, o=self.__class__.__name__, n=name)
+ LOG.warn(msg)
+
return True
# =============================================================================
default_pdns_api_path_prefix = DEFAULT_PDNS_API_PREFIX
default_pdns_api_timeout = DEFAULT_PDNS_API_PORT
default_pdns_comment_account = 'provisioning'
+
+ default_vsphere_defs = {
+ 'live': {
+ 'host': 'vcs01.ppbrln.internal',
+ 'port': 443,
+ 'dc': 'vmcc',
+ 'cluster': 'vmcc-l105-01',
+ },
+ 'test': {
+ 'host': 'test-vcsa01.pixelpark.net',
+ 'port': 443,
+ 'dc': 'test-vmcc',
+ 'cluster': 'test-vmcc-l105-01',
+ },
+ }
+
default_min_root_size_gb = 32.0
default_tz_name = 'Europe/Berlin'
default_guest_id = "oracleLinux7_64Guest"
max_pdns_api_timeout = 3600
+ re_excl_ds = re.compile(r'^\s*excluded?[-_]datastores?\s*$', re.IGNORECASE)
+ re_split_ds = re.compile(r'[,;\s]+')
+ re_template = re.compile(r'^\s*template(?:[-_\.]?name)?\s*$', re.IGNORECASE)
+ re_min_root_size = re.compile(
+ r'^\s*min[-_\.]?root[-_\.]?size(?:[-_\.]?gb)\s*$', re.IGNORECASE)
+ re_guest_id = re.compile(r'^\s*guest[-_]?id\s*$', re.IGNORECASE)
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None, simulate=False,
raise ValueError(msg)
self._root_max_size = val
+ # -------------------------------------------------------------------------
+ def init_vsphere_defaults(self):
+
+ for vname in self.default_vsphere_defs.keys():
+
+ vs_data = self.default_vsphere_defs[vname]
+
+ params = {
+ 'appname': self.appname,
+ 'verbose': self.verbose,
+ 'base_dir': self.base_dir,
+ 'name': vname,
+ 'host': vs_data['host'],
+ 'port': vs_data['port'],
+ 'dc': vs_data['dc'],
+ 'cluster': vs_data['cluster'],
+ }
+
+ if self.verbose > 2:
+ msg = _("Creating a {}-object with parameters:").format('VsphereConfig')
+ msg += '\n' + pp(params)
+ LOG.debug(msg)
+ vsphere = VsphereConfig(**params)
+ if self.verbose > 2:
+ LOG.debug(_("Created object:") + '\n' + pp(vsphere.as_dict()))
+
+ self.vsphere[vname] = vsphere
+
# -------------------------------------------------------------------------
def as_dict(self, short=True, show_secrets=False):
"""
LOG.debug(_("Checking config section {s!r} ({n}) ...").format(
s=section_name, n=vsphere_name))
- re_excl_ds = re.compile(r'^\s*excluded?[-_]datastores?\s*$', re.IGNORECASE)
- re_split_ds = re.compile(r'[,;\s]+')
- re_template = re.compile(r'^\s*template(?:[-_\.]?name)?\s*$', re.IGNORECASE)
- re_min_root_size = re.compile(
- r'^\s*min[-_\.]?root[-_\.]?size(?:[-_\.]?gb)\s*$', re.IGNORECASE)
- re_guest_id = re.compile(r'^\s*guest[-_]?id\s*$', re.IGNORECASE)
+ if vsphere_name in self.vsphere:
+ self.eval_config_existing_vsphere(config, section_name, vsphere_name)
+ else:
+ self.eval_config_new_vsphere(config, section_name, vsphere_name)
+
+ # -------------------------------------------------------------------------
+ def eval_config_new_vsphere(self, config, section_name, vsphere_name):
params = {
'appname': self.appname,
params['dc'] = value.strip()
elif key.lower() == 'cluster' and value.strip():
params['cluster'] = value.strip()
- elif re_template.search(key) and value.strip():
+ elif self.re_template.search(key) and value.strip():
params['template_name'] = value.strip()
- elif re_excl_ds.search(key) and value.strip():
+ elif self.re_excl_ds.search(key) and value.strip():
datastores = re_split_ds.split(value.strip())
params['excluded_ds'] = datastores
- elif re_min_root_size.search(key) and value.strip():
+ elif self.re_min_root_size.search(key) and value.strip():
params['min_root_size_gb'] = value
- elif re_guest_id.search(key) and value.strip():
- params['guest_id'] = datastores
+ elif self.re_guest_id.search(key) and value.strip():
+ params['guest_id'] = value.strip()
else:
msg = _(
"Unknown configuration parameter {k!r} with value {v!r} for VSPhere {n!r} "
return
+ # -------------------------------------------------------------------------
+ def eval_config_existing_vsphere(self, config, section_name, vsphere_name):
+
+ vsphere = self.vsphere[vsphere_name]
+
+ for (key, value) in config.items(section_name):
+
+ if key.lower() == 'host' and value.strip():
+ vsphere.host = value.strip()
+ elif key.lower() == 'port':
+ vsphere.port = value
+ elif key.lower() == 'user' and value.strip():
+ vsphere.user = value.strip()
+ elif key.lower() == 'password':
+ vsphere.password = value
+ elif key.lower() == 'dc' and value.strip():
+ vsphere.dc = value.strip()
+ elif key.lower() == 'cluster' and value.strip():
+ vsphere.cluster = value.strip()
+ elif self.re_template.search(key) and value.strip():
+ vsphere.template_name = value.strip()
+ elif self.re_excl_ds.search(key) and value.strip():
+ datastores = re_split_ds.split(value.strip())
+ vsphere.datastores = datastores
+ elif self.re_min_root_size.search(key) and value.strip():
+ vsphere.min_root_size_gb = value.strip()
+ elif self.re_guest_id.search(key) and value.strip():
+ vsphere.guest_id = value.strip()
+ else:
+ msg = _(
+ "Unknown configuration parameter {k!r} with value {v!r} for VSPhere {n!r} "
+ "found.").format(k=key, v=value, n=vsphere_name)
+ LOG.warning(msg)
+
+ if self.verbose > 2:
+ LOG.debug(_("Updated object:") + '\n' + pp(vsphere.as_dict()))
+
+ vsphere.is_valid(raise_on_error=True)
+
+ self.vsphere[vsphere_name] = vsphere
+
+ return
+
# -------------------------------------------------------------------------
def eval_config_pdns(self, config, section):