8.1.2. cobbler.cobbler_collections package

8.1.2.1. Submodules

8.1.2.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': 'ip_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) None[source]

Add an object to the collection

Parameters
  • ref – The reference to the object.

  • save – If this is true then the objet 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.

abstract static collection_type() str[source]

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

abstract static collection_types() str[source]

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

copy(ref: ITEM, newname: str)[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.

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.

abstract 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(name: str = '', return_list: bool = False, no_errors: bool = False, **kargs: Union[str, int, bool, Dict[Any, Any], List[Any]]) Optional[Union[List[ITEM], ITEM]][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
  • name – The object name which should be found.

  • 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.

  • kargs – If name is present, this is optional, otherwise this dict needs to have at least a key with name. You may specify more keys to finetune the search.

Returns

The first item or a list with all matches.

Raises

ValueError – In case no arguments for searching were specified.

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) Optional[Item][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”.

get_names() List[str][source]

Return list of names in the collection.

Returns

list of names in the collection.

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.

abstract remove(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False) None[source]

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

Parameters
  • name – Item Name

  • with_delete – sync and run triggers

  • with_sync – sync to server file system

  • with_triggers – run “on delete” triggers

  • recursive – recursively delete children

Returns

NotImplementedError

rename(ref: ITEM, newname: str, with_sync: bool = True, with_triggers: bool = True)[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.

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

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

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

Serialize the collection

Returns

All elements of the collection as a list.

to_string() str[source]

Creates a printable representation of the collection suitable for reading by humans or parsing from scripts. Actually scripts would be better off reading the JSON in the cobbler_collections files directly.

Returns

The object as a string representation.

8.1.2.3. 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(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False) None[source]

Remove element named ‘name’ from the collection

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.

8.1.2.4. 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(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = True) None[source]

Remove element named ‘name’ from the collection

Raises

CX – In case object does not exist or it would orhan a system.

8.1.2.5. 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: Item) Dict[str, Any][source]

Load a collection item from disk

Parameters

obj – collection item

distros() Distros[source]

Return the definitive copy of the Distros collection

get_items(collection_type: str) Union[Distros, Profiles, Systems, Repos, Images, Menus, Settings][source]

Get a full collection of a single type.

Valid Values vor collection_type are: “distro”, “profile”, “repo”, “image”, “menu” 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

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: ITEM) 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: ITEM) None[source]

Save a collection item to disk

Parameters

item – collection item

settings() Settings[source]

Return the definitive copy of the application settings

systems() Systems[source]

Return the definitive copy of the Systems collection

8.1.2.6. 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(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False) None[source]

Remove element named ‘name’ from the collection

Parameters
  • name – The name of the menu

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

  • 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 menu references.

Raises

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

8.1.2.7. 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(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False)[source]

Remove element named ‘name’ from the collection

Raises

CX – In case the name of the object was not given or any other descendant would be orphaned.

8.1.2.8. 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(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False)[source]

Remove element named ‘name’ from the collection

Raises

CX – In case the object does not exist.

8.1.2.9. 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 Distro forged from seed_data

Parameters
  • api – Parameter is skipped.

  • seed_data – Data to seed the object with.

Returns

The created object.

remove(name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False) None[source]

Remove element named ‘name’ from the collection

Raises

CX – In case the name of the object was not given.

8.1.2.10. 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.