7.1.8. cobbler.settings package

7.1.8.1. Subpackages

7.1.8.2. Submodules

7.1.8.3. cobbler.settings.cli module

Tool to manage the settings of Cobbler without the daemon running.

cobbler.settings.cli.automigrate(args: Namespace) int[source]

Automigrates settings based on provided arguments.

Parameters:

args – argparse.Namespace containing configuration and migration options.

cobbler.settings.cli.main(args: List[str] | None = None) int[source]

Main entrypoint for the the cobbler-settings script.

cobbler.settings.cli.migrate(args: Namespace) int[source]

Migrate settings file to a specified version, optionally updating the target file.

Parameters:

args – argparse.Namespace containing migration options and arguments.

cobbler.settings.cli.modify(args: Namespace) int[source]

Modify a single configuration setting based on the provided arguments.

Parameters:

args – argparse.Namespace containing configuration and migration options.

cobbler.settings.cli.validate(args: Namespace) int[source]

Validates the Cobbler settings file against the specified version schema.

Parameters:

args – argparse.Namespace containing the required attributes.

7.1.8.4. Module contents

Cobbler app-wide settings

class cobbler.settings.Settings[source]

Bases: object

This class contains all app-wide settings of Cobbler. It should only exist once in a Cobbler instance.

static collection_type() str[source]

This is a hardcoded string which represents the collection type.

Returns:

“setting”

static collection_types() str[source]

return the collection plural name

from_dict(new_values: Dict[str, Any]) Settings | None[source]

Modify this object to load values in dictionary. If the handed dict would lead to an invalid object it is silently discarded.

Warning

If the dict from the args has not all settings included Cobbler may behave unexpectedly.

Parameters:

new_values – The dictionary with settings to replace.

Returns:

Returns the settings instance this method was called from.

is_valid() bool[source]

Silently drops all errors and returns True when everything is valid.

Returns:

If this settings object is valid this returns true. Otherwise false.

property manage_dhcp: bool

Property to disclose if at least one of IPv4 or IPv6 DHCP is managed.

save(filepath: str = '/etc/cobbler/settings.yaml', ignore_keys: List[str] | None = None) None[source]

Saves the settings to the disk. :param filepath: This sets the path of the settingsfile to write. :param ignore_keys: The list of ignore keys to exclude from migration.

to_dict(resolved: bool = False) Dict[str, Any][source]

Return an easily serializable representation of the config.

Deprecated since version 3.2.1: Use obj.__dict__ directly please. Will be removed with 3.3.0

Parameters:

resolved – Present for the compatibility with the Cobbler collections.

Returns:

The dict with all user settings combined with settings which are left to the default.

cobbler.settings.migrate(yaml_dict: Dict[str, Any], settings_path: Path, ignore_keys: List[str] | None = None) Dict[str, Any][source]

Migrates the current settings

Parameters:
  • yaml_dict – The settings dict

  • settings_path – The settings path

  • ignore_keys – The list of ignore keys to exclude from migration.

Returns:

The migrated settings

cobbler.settings.read_settings_file(filepath: str = '/etc/cobbler/settings.yaml', ignore_keys: List[str] | None = None) Dict[str, Any][source]

Utilizes read_yaml_file(). If the read settings file is invalid in the context of Cobbler we will return an empty dictionary.

Parameters:
  • filepath – The path to the settings file.

  • ignore_keys – The list of ignore keys to exclude from validation.

Raises:
  • SchemaMissingKeyError – In case keys are minssing.

  • SchemaWrongKeyError – In case keys are not listed in the schema.

  • SchemaError – In case the schema is wrong.

Returns:

A dictionary with the settings. As a word of caution: This may not represent a correct settings object, it will only contain a correct YAML representation.

cobbler.settings.read_yaml_file(filepath: str = '/etc/cobbler/settings.yaml') Dict[str, Any][source]

Reads settings files from filepath and saves the content in a dictionary.

Parameters:

filepath – Settings file path, defaults to “/ect/cobbler/settings.yaml”

Raises:
  • FileNotFoundError – In case file does not exist or is a directory.

  • yaml.YAMLError – In case the file is not a valid YAML file.

Returns:

The aggregated dict of all settings.

cobbler.settings.update_settings_file(data: Dict[str, Any], filepath: str = '/etc/cobbler/settings.yaml', ignore_keys: List[str] | None = None) bool[source]

Write data handed to this function into the settings file of Cobbler. This function overwrites the existing content. It will only write valid settings. If you are trying to save invalid data this will raise a SchemaException described in cobbler.settings.validate().

Parameters:
  • data – The data to put into the settings file.

  • filepath – This sets the path of the settingsfile to write.

  • ignore_keys – The list of ignore keys to exclude from validation.

Returns:

True if the action succeeded. Otherwise return False.

cobbler.settings.validate_settings(settings_content: Dict[str, Any], ignore_keys: List[str] | None = None) Dict[str, Any][source]

This function performs logical validation of our loaded YAML files. This function will: - Perform type validation on all values of all keys. - Provide defaults for optional settings. :param settings_content: The dictionary content from the YAML file. :param ignore_keys: The list of ignore keys to exclude from validation. :raises SchemaError: In case the data given is invalid. :return: The Settings of Cobbler which can be safely used inside this instance.