from .interface import TerraformInterface
-__version__ = '1.6.2'
+__version__ = '1.6.3'
LOG = logging.getLogger(__name__)
'production',
'test',
'development',
- 'pre_development',
- 'dev_chronie'
)
DS_TYPES = (
re_key_interface = re.compile(r'^\s*interfaces?\s*$', re.IGNORECASE)
re_key_has_backup = re.compile(r'^\s*has[_-]?backup\s*$', re.IGNORECASE)
re_key_has_puppet = re.compile(r'^\s*has[_-]?puppet\s*$', re.IGNORECASE)
+ re_key_is_rhel = re.compile(r'^\s*is[_-]?rhel\s*$', re.IGNORECASE)
re_memory_value = re.compile(r'^\s*(\d+(?:\.\d*)?)\s*(?:(\D+)\s*)?$')
+ re_rhel_template = re.compile(r'(?:rhel|red[_-\s]*hat[_-\s]*enterprise)', re.IGNORECASE)
re_invalid_chars = re.compile(r'[^a-z0-9@\._-]', re.IGNORECASE)
re_invalid_chars_role = re.compile(r'[^a-z0-9:@\._-]', re.IGNORECASE)
puppet_customer=None, puppet_project=None, puppet_tier=None, puppet_env=None,
puppet_initial_install=True, vm_template=None, nameservers=None, searchdomains=None,
dns_options=None, has_backup=True, has_puppet=True, already_existing=None,
- vsphere=None):
+ vsphere=None, is_rhel=None):
self._vsphere = self.default_vsphere
self._is_template = bool(is_template)
self._has_backup = bool(has_backup)
self._has_puppet = bool(has_puppet)
self._already_existing = False
+ self._is_rhel = None
self.disks = None
self.interfaces = []
name=name, fqdn=fqdn, num_cpus=num_cpus, memory=memory, folder=folder,
boot_delay=boot_delay, vm_template=vm_template, puppet_contact=puppet_contact,
puppet_customer=puppet_customer, puppet_tier=puppet_tier, puppet_env=puppet_env,
- puppet_initial_install=puppet_initial_install,
+ puppet_initial_install=puppet_initial_install, is_rhel=is_rhel,
cluster=cluster, rootdisk_size=rootdisk_size, nameservers=nameservers,
searchdomains=searchdomains, dns_options=dns_options, purpose=purpose,
customer=customer, ds_cluster=ds_cluster, datastore=datastore, ds_type=ds_type,
if vm.interfaces and vm.fqdn and not vm.interfaces[0].fqdn:
vm.interfaces[0].fqdn = vm.fqdn
+ if not vm.is_template:
+ if vm.is_rhel is None:
+ vm.is_rhel = cls.guess_rhel(vm)
+
vm.initialized = True
return vm
vm.ds_type = value
return True
+ if cls.re_key_is_rhel.search(key) and value:
+ vm.is_rhel = value
+ return True
+
return False
# -------------------------------------------------------------------------
return domains
+ # -------------------------------------------------------------------------
+ @classmethod
+ def guess_rhel(cls, vm):
+ """Trying to guess, whether the VM to deploy should be a RHEL instance."""
+
+ if not vm.vm_template:
+ msg = _(
+ "The VM {!r} was no VMware template assigned, assuming the VM "
+ "should become a RHEL instance.").format(vm.fqdn)
+ LOG.warn(msg)
+ return True
+
+ ret = False
+ if cls.re_rhel_template.search(vm.vm_template):
+ ret = True
+
+ msg = _("Guessing the VM {fqdn!r} should become a RHEL instance: {ret!r}").format(
+ fqdn=vm.fqdn, ret=ret)
+ LOG.debug(msg)
+
+ return ret
+
# -----------------------------------------------------------
@property
def is_template(self):
def already_existing(self, value):
self._already_existing = to_bool(value)
+ # -----------------------------------------------------------
+ @property
+ def is_rhel(self):
+ """A flag indicating, that the VM should ishould be managed by puppet."""
+ return self._is_rhel
+
+ @is_rhel.setter
+ def is_rhel(self, value):
+ if value is None:
+ self._is_rhel = None
+ return
+ self._is_rhel = bool(value)
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res['hiera_project'] = self.hiera_project
res['hostname'] = self.hostname
res['interfaces'] = []
+ res['is_rhel'] = self.is_rhel
res['is_template'] = self.is_template
res['memory'] = self.memory
res['name'] = self.name