def validate_breed(breed: str) -> str: """ This is a setter for the operating system breed. :param breed: The os-breed which shall be set. :raises TypeError: If breed is not a str. :raises ValueError: If breed is not a supported breed. """ if not isinstance(breed, str): raise TypeError("breed must be of type str") if not breed: return "" # FIXME: The following line will fail if load_signatures() from utils.py was not called! valid_breeds = utils.get_valid_breeds() breed = breed.lower() if breed and breed in valid_breeds: return breed nicer = ", ".join(valid_breeds) raise ValueError( "Invalid value for breed (\"%s\"). Must be one of %s, different breeds have different levels of " "support!" % (breed, nicer))
def __init__(self, is_cobblerd=False): """ Constructor """ # FIXME: this should be switchable through some simple system self.__dict__ = CobblerAPI.__shared_state self.perms_ok = False if not CobblerAPI.__has_loaded: if os.path.exists("/etc/cobbler/use.couch"): self.use_couch = True else: self.use_couch = False # NOTE: we do not log all API actions, because # a simple CLI invocation may call adds and such # to load the config, which would just fill up # the logs, so we'll do that logging at CLI # level (and remote.py web service level) instead. random.seed() self.is_cobblerd = is_cobblerd try: self.logger = clogger.Logger("/var/log/cobbler/cobbler.log") except CX: # return to CLI/other but perms are not valid # perms_ok is False return # FIXME: conslidate into 1 server instance self.selinux_enabled = utils.is_selinux_enabled() self.dist = utils.check_dist() self.os_version = utils.os_release() CobblerAPI.__has_loaded = True # load the modules first, or nothing else works... module_loader.load_modules() self._collection_mgr = collection_manager.CollectionManager(self) self.deserialize() # import signatures try: utils.load_signatures(self.settings().signature_path) except Exception as e: self.log("Failed to load signatures from %s: %s" % (self.settings().signature_path, e)) return self.log("%d breeds and %d OS versions read from the signature file" % ( len(utils.get_valid_breeds()), len(utils.get_valid_os_versions())) ) self.authn = self.get_module_from_file( "authentication", "module", "authn_configfile" ) self.authz = self.get_module_from_file( "authorization", "module", "authz_allowall" ) # FIXME: pass more loggers around, and also see that those # using things via tasks construct their own yumgen/tftpgen # versus reusing this one, which has the wrong logger # (most likely) for background tasks. self.yumgen = yumgen.YumGen(self._collection_mgr) self.tftpgen = tftpgen.TFTPGen(self._collection_mgr, logger=self.logger) self.power_mgr = power_manager.PowerManager(self, self._collection_mgr) self.logger.debug("API handle initialized") self.perms_ok = True
# this data structure is described in item.py FIELDS = [ # non-editable in UI (internal) ["ctime", 0, 0, "", False, "", 0, "float"], ["depth", 0, 0, "Depth", False, "", 0, "int"], ["mtime", 0, 0, "", False, "", 0, "float"], ["source_repos", [], 0, "Source Repos", False, "", 0, "list"], ["tree_build_time", 0, 0, "Tree Build Time", False, "", 0, "str"], ["uid", "", 0, "", False, "", 0, "str"], # editable in UI ["arch", 'x86_64', 0, "Architecture", True, "", utils.get_valid_archs(), "str"], ["autoinstall_meta", {}, 0, "Automatic Installation Template Metadata", True, "Ex: dog=fang agent=86", 0, "dict"], ["boot_files", {}, 0, "TFTP Boot Files", True, "Files copied into tftpboot beyond the kernel/initrd", 0, "list"], ["boot_loader", "<<inherit>>", 0, "Boot loader", True, "Network installation boot loader", utils.get_supported_system_boot_loaders(), "str"], ["breed", 'redhat', 0, "Breed", True, "What is the type of distribution?", utils.get_valid_breeds(), "str"], ["comment", "", 0, "Comment", True, "Free form text description", 0, "str"], ["fetchable_files", {}, 0, "Fetchable Files", True, "Templates for tftp or wget/curl", 0, "list"], ["initrd", None, 0, "Initrd", True, "Absolute path to kernel on filesystem", 0, "str"], ["kernel", None, 0, "Kernel", True, "Absolute path to kernel on filesystem", 0, "str"], ["kernel_options", {}, 0, "Kernel Options", True, "Ex: selinux=permissive", 0, "dict"], ["kernel_options_post", {}, 0, "Kernel Options (Post Install)", True, "Ex: clocksource=pit noapic", 0, "dict"], ["mgmt_classes", [], 0, "Management Classes", True, "Management classes for external config management", 0, "list"], ["name", "", 0, "Name", True, "Ex: Fedora-11-i386", 0, "str"], ["os_version", "virtio26", 0, "OS Version", True, "Needed for some virtualization optimizations", utils.get_valid_os_versions(), "str"], ["owners", "SETTINGS:default_ownership", 0, "Owners", True, "Owners list for authz_ownership (space delimited)", 0, "list"], ["template_files", {}, 0, "Template Files", True, "File mappings for built-in config management", 0, "list"] ] class Distro(item.Item):
def __init__(self, is_cobblerd=False): """ Constructor """ # FIXME: this should be switchable through some simple system self.__dict__ = CobblerAPI.__shared_state self.perms_ok = False if not CobblerAPI.__has_loaded: # NOTE: we do not log all API actions, because # a simple CLI invocation may call adds and such # to load the config, which would just fill up # the logs, so we'll do that logging at CLI # level (and remote.py web service level) instead. random.seed() self.is_cobblerd = is_cobblerd try: self.logger = clogger.Logger("/var/log/cobbler/cobbler.log") except CX: # return to CLI/other but perms are not valid # perms_ok is False return # FIXME: conslidate into 1 server instance self.selinux_enabled = utils.is_selinux_enabled() self.dist = utils.check_dist() self.os_version = utils.os_release() CobblerAPI.__has_loaded = True # load the modules first, or nothing else works... module_loader.load_modules() self._collection_mgr = collection_manager.CollectionManager(self) self.deserialize() # import signatures try: utils.load_signatures(self.settings().signature_path) except Exception as e: self.log("Failed to load signatures from %s: %s" % (self.settings().signature_path, e)) return self.log("%d breeds and %d OS versions read from the signature file" % ( len(utils.get_valid_breeds()), len(utils.get_valid_os_versions())) ) self.authn = self.get_module_from_file( "authentication", "module", "authn_configfile" ) self.authz = self.get_module_from_file( "authorization", "module", "authz_allowall" ) # FIXME: pass more loggers around, and also see that those # using things via tasks construct their own yumgen/tftpgen # versus reusing this one, which has the wrong logger # (most likely) for background tasks. self.yumgen = yumgen.YumGen(self._collection_mgr) self.tftpgen = tftpgen.TFTPGen(self._collection_mgr, logger=self.logger) self.power_mgr = power_manager.PowerManager(self, self._collection_mgr) self.logger.debug("API handle initialized") self.perms_ok = True
from cobbler.utils import _ # this data structure is described in item.py FIELDS = [ # non-editable in UI (internal) ['ctime', 0, 0, "", False, "", 0, "float"], ['depth', 0, 0, "", False, "", 0, "int"], ['mtime', 0, 0, "", False, "", 0, "float"], ['parent', '', 0, "", False, "", 0, "str"], ['uid', "", 0, "", False, "", 0, "str"], # editable in UI ['arch', 'x86_64', 0, "Architecture", True, "", utils.get_valid_archs(), "str"], ['autoinstall', '', 0, "Automatic installation file", True, "Path to autoinst/answer file template", 0, "str"], ['breed', 'redhat', 0, "Breed", True, "", utils.get_valid_breeds(), "str"], ['comment', '', 0, "Comment", True, "Free form text description", 0, "str"], ['file', '', 0, "File", True, "Path to local file or nfs://user@host:path", 0, "str"], ['image_type', "iso", 0, "Image Type", True, "", ["iso", "direct", "memdisk", "virt-image"], "str"], ['name', '', 0, "Name", True, "", 0, "str"], ['network_count', 1, 0, "Virt NICs", True, "", 0, "int"], ['os_version', '', 0, "OS Version", True, "ex: rhel4", utils.get_valid_os_versions(), "str"], ['owners', "SETTINGS:default_ownership", 0, "Owners", True, "Owners list for authz_ownership (space delimited)", [], "list"], ['virt_auto_boot', "SETTINGS:virt_auto_boot", 0, "Virt Auto Boot", True, "Auto boot this VM?", 0, "bool"], ['virt_bridge', "SETTINGS:default_virt_bridge", 0, "Virt Bridge", True, "", 0, "str"], ['virt_cpus', 1, 0, "Virt CPUs", True, "", 0, "int"], ["virt_disk_driver", "SETTINGS:default_virt_disk_driver", 0, "Virt Disk Driver Type", True, "The on-disk format for the virtualization disk", "raw", "str"], ['virt_file_size', "SETTINGS:default_virt_file_size", 0, "Virt File Size (GB)", True, "", 0, "float"], ['virt_path', '', 0, "Virt Path", True, "Ex: /directory or VolGroup00", 0, "str"], ['virt_ram', "SETTINGS:default_virt_ram", 0, "Virt RAM (MB)", True, "", 0, "int"], ['virt_type', "SETTINGS:default_virt_type", 0, "Virt Type", True, "", ["xenpv", "xenfv", "qemu", "kvm", "vmware"], "str"],
"autoinstall_meta", {}, 0, "Automatic Installation Template Metadata", True, "Ex: dog=fang agent=86", 0, "dict" ], [ "boot_files", {}, 0, "TFTP Boot Files", True, "Files copied into tftpboot beyond the kernel/initrd", 0, "list" ], [ "boot_loader", "<<inherit>>", 0, "Boot loader", True, "Network installation boot loader", utils.get_supported_system_boot_loaders(), "str" ], [ "breed", 'redhat', 0, "Breed", True, "What is the type of distribution?", utils.get_valid_breeds(), "str" ], [ "comment", "", 0, "Comment", True, "Free form text description", 0, "str" ], [ "fetchable_files", {}, 0, "Fetchable Files", True, "Templates for tftp or wget/curl", 0, "list" ], [ "initrd", None, 0, "Initrd", True, "Absolute path to kernel on filesystem", 0, "str" ], [ "kernel", None, 0, "Kernel", True,
# design issues that require this should be avoided forever more, and there are few exceptions. Cobbler # must operate as normal with the default value for all fields and not choke on the default values. FIELDS = [ ["name", "", 0, "Name", True, "Ex: Fedora-11-i386", 0, "str"], ["ctime", 0, 0, "", False, "", 0, "float"], ["mtime", 0, 0, "", False, "", 0, "float"], ["uid", "", 0, "", False, "", 0, "str"], ["owners", "SETTINGS:default_ownership", 0, "Owners", True, "Owners list for authz_ownership (space delimited)", 0, "list"], ["kernel", None, 0, "Kernel", True, "Absolute path to kernel on filesystem", 0, "str"], ["initrd", None, 0, "Initrd", True, "Absolute path to kernel on filesystem", 0, "str"], ["kernel_options", {}, 0, "Kernel Options", True, "Ex: selinux=permissive", 0, "dict"], ["kernel_options_post", {}, 0, "Kernel Options (Post Install)", True, "Ex: clocksource=pit noapic", 0, "dict"], ["ks_meta", {}, 0, "Kickstart Metadata", True, "Ex: dog=fang agent=86", 0, "dict"], ["arch", 'x86_64', 0, "Architecture", True, "", utils.get_valid_archs(), "str"], ["breed", 'redhat', 0, "Breed", True, "What is the type of distribution?", utils.get_valid_breeds(), "str"], ["os_version", "generic26", 0, "OS Version", True, "Needed for some virtualization optimizations", utils.get_valid_os_versions(), "str"], ["source_repos", [], 0, "Source Repos", False, "", 0, "list"], ["depth", 0, 0, "Depth", False, "", 0, "int"], ["comment", "", 0, "Comment", True, "Free form text description", 0, "str"], ["tree_build_time", 0, 0, "Tree Build Time", False, "", 0, "str"], ["mgmt_classes", [], 0, "Management Classes", True, "Management classes for external config management", 0, "list"], ["boot_files", {}, 0, "TFTP Boot Files", True, "Files copied into tftpboot beyond the kernel/initrd", 0, "list"], ["fetchable_files", {}, 0, "Fetchable Files", True, "Templates for tftp or wget", 0, "list"], ["template_files", {}, 0, "Template Files", True, "File mappings for built-in config management", 0, "list"] ] class Distro(item.Item): """ A cobbler distribution object
from cobbler.cexceptions import CX from cobbler.utils import _ # this data structure is described in item.py FIELDS = [ # non-editable in UI (internal) ["ctime", 0, 0, "", False, "", 0, "float"], ["depth", 0, 0, "", False, "", 0, "int"], ["mtime", 0, 0, "", False, "", 0, "float"], ["parent", "", 0, "", False, "", 0, "str"], ["uid", "", 0, "", False, "", 0, "str"], # editable in UI ["arch", "x86_64", 0, "Architecture", True, "", utils.get_valid_archs(), "str"], ["autoinstall", "", 0, "Automatic installation file", True, "Path to autoinst/answer file template", 0, "str"], ["breed", "redhat", 0, "Breed", True, "", utils.get_valid_breeds(), "str"], ["comment", "", 0, "Comment", True, "Free form text description", 0, "str"], ["file", "", 0, "File", True, "Path to local file or nfs://user@host:path", 0, "str"], ["image_type", "iso", 0, "Image Type", True, "", ["iso", "direct", "memdisk", "virt-image"], "str"], ["name", "", 0, "Name", True, "", 0, "str"], ["network_count", 1, 0, "Virt NICs", True, "", 0, "int"], ["os_version", "", 0, "OS Version", True, "ex: rhel4", utils.get_valid_os_versions(), "str"], [ "owners", "SETTINGS:default_ownership", 0, "Owners", True, "Owners list for authz_ownership (space delimited)", [], "list",