from .xlate import XLATOR
-__version__ = '0.4.2'
+__version__ = '0.4.3'
LOG = logging.getLogger(__name__)
A handler class for executing cobbler actions.
"""
+ valid_status = ('development', 'testing', 'acceptance', 'production')
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
rc=proc.returncode, err=err)
raise ExpectedCobblerError(msg)
+ # -------------------------------------------------------------------------
+ def add_system(self, name, fqdn, mac_address, comment=None, status=None):
+ """Creating a new system."""
+
+ profile = self.config.cobbler_profile
+ os_id = self.config.os_id
+
+ LOG.info(_("Creating new sytem {!r} ...").format(name))
+
+ if not comment:
+ comment = "VMWare template for creating a {} system.".format(os_id)
+ if not status:
+ status = 'development'
+
+ ks_meta_list = []
+ ks_meta_list.append("ROOT_PWD_HASH={}".format(self.config.get_root_pwd_hash()))
+
+ ks_meta = None
+ if ks_meta_list:
+ ks_meta = ' '.join(ks_meta_list)
+
+ args = ['system', 'add']
+ args.append('--clobber')
+ args.append('--name')
+ args.append(name)
+ args.append('--profile')
+ args.append(profile)
+ args.append('--status')
+ args.append(status)
+ args.append('--kopts')
+ args.append('inst.sshd')
+ args.append('--comment')
+ args.append(comment)
+ if ks_meta:
+ args.append('--ksmeta')
+ args.append(ks_meta)
+
+ if self.verbose > 1:
+ LOG.debug(_("Cobbler arguments for creating a new system:") + "\n" + pp(args))
# =============================================================================
if __name__ == "__main__":
import logging
import re
import copy
+import crypt
# Third party modules
from pathlib import Path
from .xlate import XLATOR
-__version__ = '1.5.2'
+__version__ = '1.5.3'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
max_max_wait_for_finish_general = 60 * 60
max_max_wait_for_finish_install = 24 * 60 * 60
limit_max_nr_templates_stay = 100
+ default_root_password = 'testtest'
default_tpl_vm_domain = 'pixelpark.com'
mac_address_template = "00:16:3e:53:{:02x}:{:02x}"
+ method_list = {}
+ for method in crypt.methods:
+ mname = method.name.lower()
+ method_list[mname] = method
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
self._cobbler_profile_given = False
self._template_name_given = False
+ self._root_password = self.default_root_password
+
self.private_ssh_key = None
self.cobbler_distro = self.default_cobbler_distro
"""Size of RAM in GiB."""
return float(self.ram_mb) / 1024
+ # -------------------------------------------------------------------------
+ @property
+ def root_password(self):
+ """The root password of the VM to create."""
+ return self._root_password
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res['data_size'] = self.data_size
res['ram_gb'] = self.ram_gb
+ res['root_password'] = None
+ if self.root_password:
+ if self.verbose > 4:
+ res['root_password'] = self.root_password
+ else:
+ res['root_password'] = '********'
+
res['password'] = None
if self.password:
if self.verbose > 4:
re_os_id = re.compile(r'^\s*os[-_]?id\s*$', re.IGNORECASE)
re_os_id_subst = re.compile(r'[^a-z0-9_-]+', re.IGNORECASE)
re_vm_domain = re.compile(r'^\s*(?:vm[-_]?)?domain\s*$', re.IGNORECASE)
+ re_root_pwd = re.compile(r'^\s*root[-_]?password\s*$', re.IGNORECASE)
for (key, value) in config.items(section_name):
if key.lower() == 'vm':
elif key.lower() == 'os_version':
self.os_version = value.strip()
continue
+ elif re_root_pwd.match(key) and value.strip():
+ self._root_password = value.strip()
+ continue
return
if re_ws_rel_filesdir_key.match(key) and value.strip() != '':
self.cobbler_ws_rel_filesdir = Path(value.strip())
+ # -------------------------------------------------------------------------
+ def get_root_pwd_hash(self, method='sha256'):
+ """Generates a password hash based on the root password."""
+
+ m = method.lower()
+ if m not in self.method_list:
+ msg = _("Given method {!r} is not a valid crypt method.").format(method)
+ raise ValueError(msg)
+
+ salt = crypt.mksalt(self.method_list[m])
+ pwd_hash = crypt.crypt(self.root_password, salt)
+ if self.verbose > 2:
+ LOG.debug(_("Hashed root password: {!r}").format(pwd_hash))
+
+ return pwd_hash
+
# =============================================================================
if __name__ == "__main__":