7.1.3. cobbler.cobbler_collections package

7.1.3.1. Submodules

7.1.3.2. cobbler.cobbler_collections.collection module

This module contains the code for the abstract base collection that powers all the other collections.

class cobbler.cobbler_collections.collection.Collection(collection_mgr: CollectionManager)[source]

Bases: Generic[ITEM]

Base class for any serializable list of things.

SEARCH_REKEY = {'boot_loader': 'boot_loaders', 'dhcp-tag': 'dhcp_tag', 'enable_gpxe': 'enable_ipxe', 'inherit': 'parent', 'ip': 'ipv4.address', 'kopts': 'kernel_options', 'kopts_post': 'kernel_options_post', 'mac': 'mac_address', 'netboot-enabled': 'netboot_enabled', 'virt-auto-boot': 'virt.auto_boot', 'virt-bridge': 'virt_bridge', 'virt-cpus': 'virt.cpus', 'virt-disk-driver': 'virt.disk_driver', 'virt-file-size': 'virt.file_size', 'virt-group': 'virt.group', 'virt-host': 'virt.host', 'virt-path': 'virt.path', 'virt-ram': 'virt.ram', 'virt-type': 'virt.type'}
add(ref: ITEM, save: bool = False, with_copy: bool = False, with_triggers: bool = True, with_sync: bool = True, quick_pxe_update: bool = False, check_for_duplicate_names: bool = False, rebuild_menu: bool = True) None[source]

Add an object to the collection

Parameters:
  • ref – The reference to the object.

  • save – If this is true then the object is persisted on the disk.

  • with_copy – Is a bit of a misnomer, but lots of internal add operations can run with “with_copy” as False. True means a real final commit, as if entered from the command line (or basically, by a user). With with_copy as False, the particular add call might just be being run during deserialization, in which case extra semantics around the add don’t really apply. So, in that case, don’t run any triggers and don’t deal with any actual files.

  • with_sync – If a sync should be triggered when the object is renamed.

  • with_triggers – If triggers should be run when the object is added.

  • quick_pxe_update – This decides if there should be run a quick or full update after the add was done.

  • check_for_duplicate_names – If the name of an object should be unique or not.

Raises:
  • TypError – Raised in case ref is None.

  • ValueError – Raised in case the name of ref is empty.

add_quick_pxe_sync(ref: ITEM, rebuild_menu: bool = True)[source]

Execute the quick sync that is required after an item has been added.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to add to the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

add_single_index_value(key: str | int, value: str, indx_dict: Dict[str | int, str | Set[str]], is_indx_nonunique: bool) None[source]

Add the single index value.

add_to_indexes(ref: ITEM) None[source]

Add indexes for the object.

Parameters:

ref – The reference to the object whose indexes are updated.

check_for_duplicate_names(ref: ITEM) None[source]

This method verified if the name of an object is a duplicate or not.

Raises:
  • TypeError – In case the search result had an incorrect type.

  • CX – In case an item with that name already exists.

abstractmethod static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

abstractmethod static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

copy(ref: ITEM, newname: str, with_sync: bool = True, with_triggers: bool = True)[source]

Copy an object with a new name into the same collection.

Parameters:
  • ref – The reference to the object which should be copied.

  • newname – The new name for the copied object.

  • with_sync – If a sync should be triggered when the object is copying.

  • with_triggers – If triggers should be run when the object is copying.

property deserialize_running: bool

If set to true, then the collection items are currently being loaded from disk.

Getter:

The deserialize_running for the collection.

Setter:

The new deserialize_running value for the collection.

abstractmethod factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) ITEM[source]

Must override in subclass. Factory_produce returns an Item object from dict.

Parameters:
  • api – The API to resolve all information with.

  • seed_data – Unused Parameter in the base collection.

find(return_list: bool = False, no_errors: bool = False, **kwargs: str | int | bool | Dict[Any, Any] | List[Any]) List[ITEM] | ITEM | None[source]

Return first object in the collection that matches all item=’value’ pairs passed, else return None if no objects can be found. When return_list is set, can also return a list. Empty list would be returned instead of None in that case.

Parameters:
  • return_list – If a list should be returned or the first match.

  • no_errors – If errors which are possibly thrown while searching should be ignored or not.

  • kwargs – This dict needs to have one or more keys with search criteria. You may specify more keys to narrow down the search.

Returns:

The first item or a list with all matches.

Raises:

ValueError – In case no arguments for searching were specified.

find_by_indexes(kwargs: Dict[str, Any]) List[ITEM] | None[source]

Searching for items in the collection by indexes.

Parameters:

kwargs – The dict to match for the items.

from_list(_list: List[Dict[str, Any]]) None[source]

Create all collection object items from _list.

Parameters:

_list – The list with all item dictionaries.

get(name: str) ITEM | None[source]

Return object with name in the collection

Parameters:

name – The name of the object to retrieve from the collection.

Returns:

The object if it exists. Otherwise, “None”.

index_helper(ref: ITEM, index_name: str, index_key: Any, index_operation: Callable[[str | int, str, Dict[str | int, str | Set[str]], bool], None]) None[source]

Add/Remove index entry.

Parameters:
  • ref – The reference to the object.

  • index_name – Index name.

  • index_key – The Item attribute value.

  • index_operation – Method for adding/removing an index entry.

init_indexes() None[source]

Initializing Indexes.

property inmemory: bool

If set to true, then all items of the collection are loaded into memory.

Getter:

The inmemory for the collection.

Setter:

The new inmemory value for the collection.

property lite_sync: CobblerSync

Provide a ready to use CobblerSync object.

Getter:

Return the object that can update the filesystem state to a new one.

remove(ref: ITEM, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False, rebuild_menu: bool = True) None[source]

Remove an item from collection. This method must be overridden in any subclass.

Parameters:
  • ref – The item to remove

  • with_delete – sync and run triggers

  • with_sync – sync to server file system

  • with_triggers – run “on delete” triggers

  • recursive – recursively delete children

  • rebuild_menu – rebuild menu after removing the item

Raises:

CX – In case any subitem (images, profiles or systems) would be orphaned. If the option recursive is set then the orphaned items would be removed automatically.

remove_from_indexes(ref: ITEM) None[source]

Remove index keys for the object.

Parameters:

ref – The reference to the object whose index keys are removed.

remove_quick_pxe_sync(ref: ITEM, rebuild_menu: bool = True) None[source]

Execute the quick sync that is required after an item has been removed.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to remove from the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

remove_single_index_value(key: str | int, value: str, indx_dict: Dict[str | int, str | Set[str]], is_indx_nonunique: bool) None[source]

Revove the single index value.

rename(ref: ITEM, newname: str)[source]

Allows an object “ref” to be given a new name without affecting the rest of the object tree.

Parameters:
  • ref – The reference to the object which should be renamed.

  • newname – The new name for the object.

to_list() List[Dict[str, Any]][source]

Serialize the collection

Returns:

All elements of the collection as a list.

update_index_value(ref: ITEM, attribute_name: str, old_value: Any, new_value: Any) None[source]

Update index keys for the object.

Parameters:

ref – The reference to the object whose index keys are updated.

7.1.3.3. cobbler.cobbler_collections.distro_group module

DistroGroupCollection

class cobbler.cobbler_collections.distro_group.DistroGroups(collection_mgr: CollectionManager)[source]

Bases: Collection[DistroGroup]

The collection for distro groups.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) DistroGroup[source]

Return a Distro Group forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – The data the object is initialized with.

Returns:

The created DistroGroup.

7.1.3.4. cobbler.cobbler_collections.distros module

Cobbler module that at runtime holds all distros in Cobbler.

class cobbler.cobbler_collections.distros.Distros(collection_mgr: CollectionManager)[source]

Bases: Collection[Distro]

A distro represents a network bootable matched set of kernels and initrd files.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) distro.Distro[source]

Return a Distro forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – Data to seed the object with.

Returns:

The created object.

remove(ref: Distro, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False, rebuild_menu: bool = True) None[source]

Remove the given element from the collection

Parameters:
  • ref – The object to delete

  • with_delete – In case the deletion triggers are executed for this distro.

  • with_sync – In case a Cobbler Sync should be executed after the action.

  • with_triggers – In case the Cobbler Trigger mechanism should be executed.

  • recursive – In case you want to delete all objects this distro references.

  • rebuild_menu – unused

Raises:

CX – In case any subitem (profiles or systems) would be orphaned. If the option recursive is set then the orphaned items would be removed automatically.

remove_quick_pxe_sync(ref: Distro, rebuild_menu: bool = True) None[source]

Execute the quick sync that is required after an item has been removed.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to remove from the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

7.1.3.5. cobbler.cobbler_collections.images module

Cobbler module that at runtime holds all images in Cobbler.

class cobbler.cobbler_collections.images.Images(collection_mgr: CollectionManager)[source]

Bases: Collection[Image]

A image instance represents a ISO or virt image we want to track and repeatedly install. It differs from a answer-file based installation.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any])[source]

Return a Distro forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – Data to seed the object with.

Returns:

The created object.

remove_quick_pxe_sync(ref: Image, rebuild_menu: bool = True) None[source]

Execute the quick sync that is required after an item has been removed.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to remove from the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

7.1.3.6. cobbler.cobbler_collections.manager module

Repository of the Cobbler object model

class cobbler.cobbler_collections.manager.CollectionManager(api: CobblerAPI)[source]

Bases: object

Manages a definitive copy of all data cobbler_collections with weakrefs pointing back into the class so they can understand each other’s contents.

deserialize() None[source]

Load all cobbler_collections from disk

Raises:

CX – if there is an error in deserialization

deserialize_one_item(obj: BaseItem) Dict[str, Any][source]

Load a collection item from disk

Parameters:

obj – collection item

distro_groups() DistroGroups[source]

Return the definitive copy of the DistroGroups collection

distros() Distros[source]

Return the definitive copy of the Distros collection

get_items(collection_type: str) Collection[BaseItem][source]

Get a full collection of a single type.

Valid Values vor collection_type are: “distro”, “profile”, “repo”, “image”, “menu”, “network_interface”, “template”, “distro_group”, “profile_group”, “system_group” and “settings”.

Parameters:

collection_type – The type of collection to return.

Returns:

The collection if collection_type is valid.

Raises:

CX – If the collection_type is invalid.

has_loaded = False
images() Images[source]

Return the definitive copy of the Images collection

menus() Menus[source]

Return the definitive copy of the Menus collection

network_interfaces() NetworkInterfaces[source]

Return the definitive copy of the NetworkInterfaces collection

profile_groups() ProfileGroups[source]

Return the definitive copy of the ProfileGroups collection

profiles() Profiles[source]

Return the definitive copy of the Profiles collection

repos() Repos[source]

Return the definitive copy of the Repos collection

serialize() None[source]

Save all cobbler_collections to disk

serialize_delete(collection: Collection[ITEM], item: ITEM) None[source]

Delete a collection item from disk

Parameters:
  • collection – collection

  • item – collection item

serialize_delete_one_item(item: BaseItem) None[source]

Save a collection item to disk

Parameters:

item – collection item

serialize_item(collection: Collection[ITEM], item: ITEM) None[source]

Save a collection item to disk

Deprecated - Use above serialize_one_item function instead collection param can be retrieved

Parameters:
  • collection – Collection

  • item – collection item

serialize_one_item(item: BaseItem) None[source]

Save a collection item to disk

Parameters:

item – collection item

settings() Settings[source]

Return the definitive copy of the application settings

system_groups() SystemGroups[source]

Return the definitive copy of the SystemGroups collection

systems() Systems[source]

Return the definitive copy of the Systems collection

templates() Templates[source]

Return the definitive copy of the Templates collection

7.1.3.7. cobbler.cobbler_collections.menus module

Cobbler module that at runtime holds all menus in Cobbler.

class cobbler.cobbler_collections.menus.Menus(collection_mgr: CollectionManager)[source]

Bases: Collection[Menu]

A menu represents an element of the hierarchical boot menu.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) Menu[source]

Return a Menu forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – Data to seed the object with.

Returns:

The created object.

remove_quick_pxe_sync(ref: Menu, rebuild_menu: bool = True) None[source]

Execute the quick sync that is required after an item has been removed.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to remove from the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

7.1.3.8. cobbler.cobbler_collections.network_interfaces module

Cobbler module that at runtime holds all network interfaces in Cobbler.

class cobbler.cobbler_collections.network_interfaces.NetworkInterfaces(collection_mgr: CollectionManager)[source]

Bases: Collection[NetworkInterface]

A network interface represents a virtual or physical network interface for a given System.

check_for_duplicate_names(ref: NetworkInterface) None[source]

This method verified if the name of an object is a duplicate or not.

Raises:
  • TypeError – In case the search result had an incorrect type.

  • CX – In case an item with that name already exists.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) NetworkInterface[source]

Return a Network Interface forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – The data the object is initalized with.

Returns:

The created repository.

7.1.3.9. cobbler.cobbler_collections.profile_group module

ProfileGroupCollection

class cobbler.cobbler_collections.profile_group.ProfileGroups(collection_mgr: CollectionManager)[source]

Bases: Collection[ProfileGroup]

The collection for profile groups.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) ProfileGroup[source]

Return a Profile Group forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – The data the object is initialized with.

Returns:

The created ProfileGroup.

7.1.3.10. cobbler.cobbler_collections.profiles module

Cobbler module that at runtime holds all profiles in Cobbler.

class cobbler.cobbler_collections.profiles.Profiles(collection_mgr: CollectionManager)[source]

Bases: Collection[Profile]

A profile represents a distro paired with an automatic OS installation template file.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[Any, Any])[source]

Return a Distro forged from seed_data

remove_quick_pxe_sync(ref: Profile, rebuild_menu: bool = True) None[source]

Execute the quick sync that is required after an item has been removed.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to remove from the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

7.1.3.11. cobbler.cobbler_collections.repos module

Cobbler module that at runtime holds all repos in Cobbler.

class cobbler.cobbler_collections.repos.Repos(collection_mgr: CollectionManager)[source]

Bases: Collection[Repo]

Repositories in Cobbler are way to create a local mirror of a yum repository. When used in conjunction with a mirrored distro tree (see “cobbler import”), outside bandwidth needs can be reduced and/or eliminated.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any])[source]

Return a Distro forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – The data the object is initalized with.

Returns:

The created repository.

remove(ref: Repo, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False, rebuild_menu: bool = True)[source]

Remove the given element from the collection

Parameters:
  • ref – The object to delete

  • with_delete – In case the deletion triggers are executed for this repository.

  • with_sync – In case a Cobbler Sync should be executed after the action.

  • with_triggers – In case the Cobbler Trigger mechanism should be executed.

  • recursive – In case you want to delete all objects this repository references.

  • rebuild_menu – unused

Raises:

CX – Raised in case you want to delete a none existing repository.

7.1.3.12. cobbler.cobbler_collections.system_group module

SystemGroupCollection

class cobbler.cobbler_collections.system_group.SystemGroups(collection_mgr: CollectionManager)[source]

Bases: Collection[SystemGroup]

The collection for system groups.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) SystemGroup[source]

Return a System Group forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – The data the object is initialized with.

Returns:

The created SystemGroup.

7.1.3.13. cobbler.cobbler_collections.systems module

Cobbler module that at runtime holds all systems in Cobbler.

class cobbler.cobbler_collections.systems.Systems(collection_mgr: CollectionManager)[source]

Bases: Collection[System]

Systems are hostnames/MACs/IP names and the associated profile they belong to.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) System[source]

Return a System forged from seed_data

Parameters:
  • api – Parameter is skipped.

  • seed_data – Data to seed the object with.

Returns:

The created object.

remove_quick_pxe_sync(ref: System, rebuild_menu: bool = True) None[source]

Execute the quick sync that is required after an item has been removed.

Note

This method is for internal Cobbler use only.

Parameters:
  • ref – The item to remove from the PXE tree

  • rebuild_menu – If the menu hierarchy has to be rebuilt.

7.1.3.14. cobbler.cobbler_collections.templates module

Cobbler module that at runtime holds all templates in Cobbler.

class cobbler.cobbler_collections.templates.Templates(collection_mgr: CollectionManager)[source]

Bases: Collection[Template]

A template represents a text file that has placeholders which are replaced with actual values during rendering.

static collection_type() str[source]

Returns the string key for the name of the collection (used by serializer etc)

static collection_types() str[source]

Returns the string key for the plural name of the collection (used by serializer)

factory_produce(api: CobblerAPI, seed_data: Dict[str, Any]) Template[source]

Return a Template forged from seed_data

Parameters:
  • api – parameter is skipped.

  • seed_data – Data to seed the object with.

Returns:

The created object

refresh_content() None[source]

Refresh the content of all templates in the collection. If the refresh of a template failed a warning is logged.

7.1.3.15. Module contents

The collections have the responsibility of ensuring the relational validity of the data present in Cobbler. Further they hold the data at runtime.