Source code for

Cobbler module that at runtime holds all systems in Cobbler.

# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: Copyright 2008-2009, Red Hat, Inc and Others
# SPDX-FileCopyrightText: Michael DeHaan <michael.dehaan AT gmail>

from typing import TYPE_CHECKING, Any, Dict

from cobbler import utils
from cobbler.cexceptions import CX
from cobbler.cobbler_collections import collection
from cobbler.items import system

    from cobbler.api import CobblerAPI

[docs]class Systems(collection.Collection[system.System]): """ Systems are hostnames/MACs/IP names and the associated profile they belong to. """
[docs] @staticmethod def collection_type() -> str: return "system"
[docs] @staticmethod def collection_types() -> str: return "systems"
[docs] def factory_produce( self, api: "CobblerAPI", seed_data: Dict[str, Any] ) -> system.System: """ Return a Distro forged from seed_data :param api: Parameter is skipped. :param seed_data: Data to seed the object with. :returns: The created object. """ return system.System(self.api, **seed_data)
[docs] def remove( self, name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True, recursive: bool = False, ) -> None: """ Remove element named 'name' from the collection :raises CX: In case the name of the object was not given. """ obj = self.listing.get(name, None) if obj is None: raise CX(f"cannot delete an object that does not exist: {name}") if isinstance(obj, list): # Will never happen, but we want to make mypy happy. raise CX("Ambiguous match detected!") if with_delete: if with_triggers: utils.run_triggers( self.api, obj, "/var/lib/cobbler/triggers/delete/system/pre/*", [] ) if with_sync: lite_sync = self.api.get_sync() lite_sync.remove_single_system(obj) with self.lock: del self.listing[name] self.collection_mgr.serialize_delete(self, obj) if with_delete: if with_triggers: utils.run_triggers( self.api, obj, "/var/lib/cobbler/triggers/delete/system/post/*", [] ) utils.run_triggers( self.api, obj, "/var/lib/cobbler/triggers/change/*", [] )