8.1.3.1.1. cobbler.items.abstract package

8.1.3.1.1.1. Submodules

8.1.3.1.1.2. cobbler.items.abstract.base_item module

“BaseItem” is the highest point in the object hierarchy of Cobbler. All concrete objects that can be generated should inherit from it or one of its derived classes.

class cobbler.items.abstract.base_item.BaseItem(api: CobblerAPI, *args: Any, **kwargs: Any)[source]

Bases: ABC

Abstract base class to represent the common attributes that a concrete item needs to have at minimum.

COLLECTION_TYPE = 'base'
TYPE_NAME = 'base'
property cache: ItemCache

Getting the ItemCache object.

Note

This is a read only property.

Getter

This is the ItemCache object.

check_if_valid() None[source]

Raise exceptions if the object state is inconsistent.

Raises

CX – In case the name of the item is not set.

clean_cache(name: Optional[str] = None)[source]

Clearing the Item cache.

Parameters

name – The name of Item attribute or None.

property comment: str

For every object you are able to set a unique comment which will be persisted on the object.

Getter

The comment or an emtpy string.

Setter

The new comment for the item.

property ctime: float

Property which represents the creation time of the object.

Getter

The float which can be passed to Python time stdlib.

Setter

Should only be used by the Cobbler Item Factory.

deserialize() None[source]

Deserializes the object itself and, if necessary, recursively all the objects it depends on.

find_match(kwargs: Dict[str, Any], no_errors: bool = False) bool[source]

Find from a given dict if the item matches the kv-pairs.

Parameters
  • kwargs – The dict to match for in this item.

  • no_errors – How strict this matching is.

Returns

True if matches or False if the item does not match.

find_match_single_key(data: Dict[str, Any], key: str, value: Any, no_errors: bool = False) bool[source]

Look if the data matches or not. This is an alternative for find_match().

Parameters
  • data – The data to search through.

  • key – The key to look for int the item.

  • value – The value for the key.

  • no_errors – How strict this matching is.

Returns

Whether the data matches or not.

from_dict(dictionary: Dict[Any, Any]) None[source]

Modify this object to take on values in dictionary.

Parameters

dictionary – This should contain all values which should be updated.

Raises
  • AttributeError – In case during the process of setting a value for an attribute an error occurred.

  • KeyError – In case there were keys which could not be set in the item dictionary.

property inmemory: bool

If set to false, only the Item name is in memory. The rest of the Item’s properties can be retrieved either on demand or as a result of the load_items background task.

Getter

The inmemory for the item.

Setter

The new inmemory value for the object. Should only be used by the Cobbler serializers.

abstract make_clone() BaseItem[source]

Must be defined in any subclass

property mtime: float

Represents the last modification time of the object via the API. This is not updated automagically.

Getter

The float which can be fed into a Python time object.

Setter

The new time something was edited via the API.

property name: str

Property which represents the objects name.

Getter

The name of the object.

Setter

Updating this has broad implications. Please try to use the rename() functionality from the corresponding collection.

property owners: List[Any]

This is a feature which is related to the ownership module of Cobbler which gives only specific people access to specific records. Otherwise this is just a cosmetic feature to allow assigning records to specific users.

Warning

This is never validated against a list of existing users. Thus you can lock yourself out of a record.

Note

This property can be set to <<inherit>>.

Getter

Return the list of users which are currently assigned to the record.

Setter

The list of people which should be new owners. May lock you out if you are using the ownership authorization module.

serialize() Dict[str, Any][source]

This method is a proxy for to_dict() and contains additional logic for serialization to a persistent location.

Returns

The dictionary with the information for serialization.

sort_key(sort_fields: List[Any])[source]

Convert the item to a dict and sort the data after specific given fields.

Parameters

sort_fields – The fields to sort the data after.

Returns

The sorted data.

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

This converts everything in this object to a dictionary.

Parameters

resolved – If this is True, Cobbler will resolve the values to its final form, rather than give you the objects raw value.

Returns

A dictionary with all values present in this object.

property uid: str

The uid is the internal unique representation of a Cobbler object. It should never be used twice, even after an object was deleted.

Getter

The uid for the item. Should be unique across a running Cobbler instance.

Setter

The new uid for the object. Should only be used by the Cobbler Item Factory.

8.1.3.1.1.3. cobbler.items.abstract.bootable_item module

Cobbler module that contains the code for a generic Cobbler item.

Changelog:

V3.4.0 (unreleased):
  • Renamed to BootableItem

  • (Re-)Added Cache implementation with the following new methods and properties:
    • cache

    • inmemory

    • clean_cache()

  • Overhauled the parent/child system:
    • children is now inside item.py.

    • tree_walk() was added.

    • logical_parent was added.

    • get_parent() was added which returns the internal reference that is used to return the object of the parent property.

  • Removed:
    • mgmt_classes

    • mgmt_parameters

    • last_cached_mtime

    • fetchable_files

    • boot_files

V3.3.4 (unreleased):
  • No changes

V3.3.3:
  • Added:
    • grab_tree

V3.3.2:
  • No changes

V3.3.1:
  • No changes

V3.3.0:
  • This release switched from pure attributes to properties (getters/setters).

  • Added:
    • depth: int

    • comment: str

    • owners: Union[list, str]

    • mgmt_classes: Union[list, str]

    • mgmt_classes: Union[dict, str]

    • conceptual_parent: Union[distro, profile]

  • Removed:
    • collection_mgr: collection_mgr

    • Remove unreliable caching:
      • get_from_cache()

      • set_cache()

      • remove_from_cache()

  • Changed:
    • Constructor: Takes an instance of CobblerAPI instead of CollectionManager.

    • children: dict -> list

    • ctime: int -> float

    • mtime: int -> float

    • uid: str

    • kernel_options: dict -> Union[dict, str]

    • kernel_options_post: dict -> Union[dict, str]

    • autoinstall_meta: dict -> Union[dict, str]

    • fetchable_files: dict -> Union[dict, str]

    • boot_files: dict -> Union[dict, str]

V3.2.2:
  • No changes

V3.2.1:
  • No changes

V3.2.0:
  • No changes

V3.1.2:
  • No changes

V3.1.1:
  • No changes

V3.1.0:
  • No changes

V3.0.1:
  • No changes

V3.0.0:
  • Added:
    • collection_mgr: collection_mgr

    • kernel_options: dict

    • kernel_options_post: dict

    • autoinstall_meta: dict

    • fetchable_files: dict

    • boot_files: dict

    • template_files: dict

    • name: str

    • last_cached_mtime: int

  • Changed:
    • Rename: cached_datastruct -> cached_dict

  • Removed:
    • config

V2.8.5:
  • Added:
    • config: ?

    • settings: settings

    • is_subobject: bool

    • parent: Union[distro, profile]

    • children: dict

    • log_func: collection_mgr.api.log

    • ctime: int

    • mtime: int

    • uid: str

    • last_cached_mtime: int

    • cached_datastruct: str

class cobbler.items.abstract.bootable_item.BootableItem(api: CobblerAPI, *args: Any, is_subobject: bool = False, **kwargs: Any)[source]

Bases: InheritableItem, ABC

A BootableItem is a serializable thing that can appear in a Collection

COLLECTION_TYPE = 'bootable_abstract'
TYPE_NAME = 'bootable_abstract'
property autoinstall_meta: Dict[Any, Any]

A comma delimited list of key value pairs, like ‘a=b,c=d,e=f’ or a dict. The meta tags are used as input to the templating system to preprocess automatic installation template files.

Note

This property can be set to <<inherit>>.

Getter

The metadata or an empty dict.

Setter

Accepts anything which can be split by input_string_or_dict().

deserialize() None[source]

Deserializes the object itself and, if necessary, recursively all the objects it depends on.

dump_vars(formatted_output: bool = True, remove_dicts: bool = False) Union[Dict[str, Any], str][source]

Dump all variables.

Parameters
  • formatted_output – Whether to format the output or not.

  • remove_dicts – If True the dictionaries will be put into str form.

Returns

The raw or formatted data.

property kernel_options: Dict[Any, Any]

Kernel options are a space delimited list, like ‘a=b c=d e=f g h i=j’ or a dict.

Note

This property can be set to <<inherit>>.

Getter

The parsed kernel options.

Setter

The new kernel options as a space delimited list. May raise ValueError in case of parsing problems.

property kernel_options_post: Dict[str, Any]

Post kernel options are a space delimited list, like ‘a=b c=d e=f g h i=j’ or a dict.

Note

This property can be set to <<inherit>>.

Getter

The dictionary with the parsed values.

Setter

Accepts str in above mentioned format or directly a dict.

property template_files: Dict[str, str]

File mappings for built-in configuration management. The keys are the template source files and the value is the destination. The destination must be inside the bootloc (most of the time TFTP server directory).

This property took over the duties of boot_files additionaly. During signature import the values of “boot_files” will be added to “template_files”.

Getter

The dictionary with name-path key-value pairs.

Setter

A dict. If not a dict must be a str which is split by input_string_or_dict(). Raises TypeError otherwise.

8.1.3.1.1.4. cobbler.items.abstract.inheritable_item module

“InheritableItem” the entry point for items that have logical parents and children.

Changelog:
  • V3.4.0 (unreleased):
    • Initial creation of the class

class cobbler.items.abstract.inheritable_item.HierarchyItem(dependant_item_type: str, dependant_type_attribute: str)[source]

Bases: NamedTuple

NamedTuple to display the dependency that a single item has. The dependant_item_type object is stored in the dependant_type_attribute attribute of the Item.

For example, an item with HierarchyItem(“profile”, “repos”) contains Profile objects in the repos attribute.

dependant_item_type: str

Alias for field number 0

dependant_type_attribute: str

Alias for field number 1

class cobbler.items.abstract.inheritable_item.InheritableItem(api: CobblerAPI, *args: Any, is_subobject: bool = False, **kwargs: Any)[source]

Bases: BaseItem, ABC

Abstract class that acts as a starting point in the inheritance for items that have a parent and children.

COLLECTION_TYPE = 'inheritable_abstract'
LOGICAL_INHERITANCE: Dict[str, LogicalHierarchy] = {'distro': LogicalHierarchy(up=[], down=[HierarchyItem(dependant_item_type='profile', dependant_type_attribute='distro')]), 'image': LogicalHierarchy(up=[], down=[HierarchyItem(dependant_item_type='system', dependant_type_attribute='image')]), 'profile': LogicalHierarchy(up=[HierarchyItem(dependant_item_type='distro', dependant_type_attribute='distro')], down=[HierarchyItem(dependant_item_type='system', dependant_type_attribute='profile')]), 'system': LogicalHierarchy(up=[HierarchyItem(dependant_item_type='image', dependant_type_attribute='image'), HierarchyItem(dependant_item_type='profile', dependant_type_attribute='profile')], down=[])}
TYPE_DEPENDENCIES: Dict[str, List[HierarchyItem]] = {'distro': [HierarchyItem(dependant_item_type='profile', dependant_type_attribute='distro')], 'image': [HierarchyItem(dependant_item_type='system', dependant_type_attribute='image')], 'menu': [HierarchyItem(dependant_item_type='menu', dependant_type_attribute='parent'), HierarchyItem(dependant_item_type='image', dependant_type_attribute='menu'), HierarchyItem(dependant_item_type='profile', dependant_type_attribute='menu')], 'profile': [HierarchyItem(dependant_item_type='profile', dependant_type_attribute='parent'), HierarchyItem(dependant_item_type='system', dependant_type_attribute='profile')], 'repo': [HierarchyItem(dependant_item_type='profile', dependant_type_attribute='repos')], 'system': []}
TYPE_NAME = 'inheritable_abstract'
property children: List[InheritableItem]

The list of logical children of any depth. :getter: An empty list in case of items which don’t have logical children. :setter: Replace the list of children completely with the new provided one.

property depth: int

This represents the logical depth of an object in the category of the same items. Important for the order of loading items from the disk and other related features where the alphabetical order is incorrect for sorting.

Getter

The logical depth of the object.

Setter

The new int for the logical object-depth.

property descendants: List[InheritableItem]

Get objects that depend on this object, i.e. those that would be affected by a cascading delete, etc.

Note

This is a read only property.

Getter

This is a list of all descendants. May be empty if none exist.

get_conceptual_parent() Optional[InheritableItem][source]

The parent may just be a superclass for something like a sub-profile. Get the first parent of a different type.

Returns

The first item which is conceptually not from the same type.

property get_parent: str

This method returns the name of the parent for the object. In case there is not parent this return empty string.

grab_tree() List[Union[InheritableItem, Settings]][source]

Climb the tree and get every node.

Returns

The list of items with all parents from that object upwards the tree. Contains at least the item itself and the settings of Cobbler.

property is_subobject: bool

Weather the object is a subobject of another object or not.

Getter

True in case the object is a subobject, False otherwise.

Setter

Sets the value. If this is not a bool, this will raise a TypeError.

property logical_parent: Any

This property contains the name of the logical parent of an object. In case there is not parent this return None.

Getter

Returns the parent object or None if it can’t be resolved via the Cobbler API.

Setter

The name of the new logical parent.

property parent: Optional[Union[System, Profile, Distro, Menu]]

This property contains the name of the parent of an object. In case there is not parent this return None.

Getter

Returns the parent object or None if it can’t be resolved via the Cobbler API.

Setter

The name of the new logical parent.

tree_walk(attribute_name: Optional[str] = None) List[InheritableItem][source]

Get all children related by parent/child relationship. :return: The list of children objects.

class cobbler.items.abstract.inheritable_item.LogicalHierarchy(up: List[HierarchyItem], down: List[HierarchyItem])[source]

Bases: NamedTuple

NamedTuple to display the order of hierarchy in the dependency tree.

down: List[HierarchyItem]

Alias for field number 1

up: List[HierarchyItem]

Alias for field number 0

8.1.3.1.1.5. cobbler.items.abstract.item_cache module

Module that contains the logic for Cobbler to cache an item.

The cache significantly speeds up Cobbler. This effect is achieved thanks to the reduced amount of lookups that are required to be done.

class cobbler.items.abstract.item_cache.ItemCache(api: CobblerAPI)[source]

Bases: object

A Cobbler ItemCache object.

clean_cache()[source]

Cleaning the Item cache.

clean_dict_cache()[source]

Cleaninig the dict cache.

get_dict_cache(resolved: bool) Optional[Dict[str, Any]][source]

Gettinging the dict cache.

Parameters

resolved – “resolved” parameter for BaseItem.to_dict().

Returns

The cache value for the object, or None if not set.

set_dict_cache(value: Optional[Dict[str, Any]], resolved: bool)[source]

Setter for the dict cache.

Parameters
  • value – Sets the value for the dict cache.

  • resolved – “resolved” parameter for BaseItem.to_dict().

8.1.3.1.1.6. Module contents

Package to describe the abstract items that we define.