from .xlate import XLATOR
-__version__ = '0.4.4'
+__version__ = '0.4.5'
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,
raise ExpectedCobblerError(msg)
# -------------------------------------------------------------------------
- def add_system(self, name, fqdn, mac_address, comment=None, status=None):
+ def ensure_system_ks(self):
+
+ local_ks_base = 'template-' + self.config.os_id + '.ks'
+ local_ks = self.base_dir / 'kickstart' / local_ks_base
+ remote_ks = self.config.system_ks
+
+ self.ensure_remote_file(local_ks, remote_ks)
+
+ # -------------------------------------------------------------------------
+ def add_system(self, name, fqdn, mac_address, comment=None):
"""Creating a new system."""
profile = self.config.cobbler_profile
if not comment:
comment = "VMWare template for creating a {} system.".format(os_id)
- if not status:
- status = 'development'
+ status = self.config.system_status
ks_meta_list = []
ks_meta_list.append("ROOT_PWD_HASH={}".format(self.config.get_root_pwd_hash()))
- ks_meta_list.append("SWAP_SIZE_MB=512")
+ ks_meta_list.append("SWAP_SIZE_MB={}".format(self.config.swap_size_mb))
ks_meta = None
if ks_meta_list:
from .xlate import XLATOR
-__version__ = '1.5.4'
+__version__ = '1.5.5'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
mname = method.name.lower()
method_list[mname] = method
+ valid_system_status = ('development', 'testing', 'acceptance', 'production')
+ default_system_status = 'development'
+
+ default_swap_size_mb = 512
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
self.data_size_gb = self.default_data_size_gb
self.num_cpus = self.default_num_cpus
self.ram_mb = self.default_ram_mb
+ self.swap_size_mb = self.default_swap_size_mb
self.network = self.default_network
self.mac_address = self.default_mac_address
self.max_wait_for_general = self.default_max_wait_for_general
self.cobbler_ws_base_url = self.default_cobbler_ws_base_url
self.cobbler_ws_docroot = self.default_cobbler_ws_docroot
self.cobbler_ws_rel_filesdir = self.default_cobbler_ws_rel_filesdir
+ self.system_status = self.default_system_status
self.excluded_datastores = []
"""The root password of the VM to create."""
return self._root_password
+ # -------------------------------------------------------------------------
+ @property
+ def system_ks(self):
+ """The path to the system kickstart file."""
+ ks_base = 'template-' + self.os_id + '-' + self.system_status + '.ks'
+ return self.cobbler_ks_dir / ks_base
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res['data_size_kb'] = self.data_size_kb
res['data_size'] = self.data_size
res['ram_gb'] = self.ram_gb
+ res['system_ks'] = self.system_ks
res['root_password'] = None
if self.root_password:
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)
+ re_swap_space = re.compile(r'^\s*swap[-_]?space(?:[-_]?mb)?\s*$', re.IGNORECASE)
for (key, value) in config.items(section_name):
if key.lower() == 'vm':
elif re_root_pwd.match(key) and value.strip():
self._root_password = value.strip()
continue
+ elif re_swap_space.match(key) and value.strip():
+ self.swap_size_mb = int(value)
+ continue
return
r'^\s*(?:ws|webserver)[-_]?docroot\s*$', re.IGNORECASE)
re_ws_rel_filesdir_key = re.compile(
r'^\s*(?:ws|webserver)[-_]?rel(?:ative)?[-_]?filesdir\s*$', re.IGNORECASE)
+ rs_system_status = re.compile(r'^\s*system[-_]?status\s*$', re.IGNORECASE)
for (key, value) in config.items(section_name):
if key.lower() == 'distro' and value.strip() != '':
continue
if re_ws_rel_filesdir_key.match(key) and value.strip() != '':
self.cobbler_ws_rel_filesdir = Path(value.strip())
+ continue
+ if rs_system_status.match(key) and value.strip() != '':
+ val = value.strip().lower()
+ if val in self.valid_system_status:
+ self.system_status = val
+ else:
+ msg = _(
+ "The value of {what!r} must be one of {valid!r}, "
+ "but found {val!r}.").format(what='system_status',
+ valid=self.valid_system_status, val=value)
+ LOG.error(msg)
+ continue
# -------------------------------------------------------------------------
def get_root_pwd_hash(self, method='sha256'):