8000 Convert Cobbler Item FIELDS array of arrays to Python properties by SchoolGuy · Pull Request #2433 · cobbler/cobbler · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Convert Cobbler Item FIELDS array of arrays to Python properties #2433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
3 changes: 1 addition & 2 deletions cobbler/actions/hardlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def run(self):
and intelligent over time.
"""

# FIXME: if these directories become configurable some
# changes will be required here.
# FIXME: if these directories become configurable some changes will be required here.

self.logger.info("now hardlinking to save space, this may take some time.")

Expand Down
6DB6
4 changes: 0 additions & 4 deletions cobbler/actions/replicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ def generate_include_map(self):
self.logger.debug("Adding image %s for system %s." % (img, sys))
self.must_include["image"][img] = 1

# FIXME: remove debug
for ot in OBJ_TYPES:
self.logger.debug("transfer list for %s is %s" % (ot, list(self.must_include[ot].keys())))

# -------------------------------------------------------

def run(self, cobbler_master=None, port: str = "80", distro_patterns=None, profile_patterns=None,
Expand Down
12 changes: 6 additions & 6 deletions cobbler/actions/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def add_single_distro(self, name):
# cascade sync
kids = distro.get_children()
for k in kids:
self.add_single_profile(k.name, rebuild_menu=False)
self.add_single_profile(k, rebuild_menu=False)
self.tftpgen.make_pxe_menu()

def add_single_image(self, name):
Expand All @@ -345,7 +345,7 @@ def add_single_image(self, name):
self.tftpgen.copy_single_image_files(image)
kids = image.get_children()
for k in kids:
self.add_single_system(k.name)
self.add_single_system(k)
self.tftpgen.make_pxe_menu()

def remove_single_distro(self, name):
Expand Down Expand Up @@ -388,12 +388,12 @@ def add_single_profile(self, name: str, rebuild_menu: bool = True) -> Optional[b
# Rebuild the yum configuration files for any attached repos generate any templates listed in the distro.
self.tftpgen.write_templates(profile)
# Cascade sync
kids = profile.get_children()
kids = profile.children
for k in kids:
if k.COLLECTION_TYPE == "profile":
self.add_single_profile(k.name, rebuild_menu=False)
if self.api.find_profile(name=k) is not None:
self.add_single_profile(k, rebuild_menu=False)
else:
self.add_single_system(k.name)
self.add_single_system(k)
if rebuild_menu:
self.tftpgen.make_pxe_menu()
return True
Expand Down
87 changes: 36 additions & 51 deletions cobbler/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,21 @@
from typing import Optional, List, Union

from cobbler.actions import status, hardlink, sync, buildiso, replicate, report, log, acl, check, reposync
from cobbler import autoinstall_manager
from cobbler import autoinstall_manager, enums, settings
from cobbler.cobbler_collections import manager
from cobbler.items import package, system, image, profile, repo, mgmtclass, distro, file, menu
from cobbler import module_loader
from cobbler import power_manager
from cobbler import settings
from cobbler import tftpgen
from cobbler import utils
from cobbler import yumgen
from cobbler import autoinstallgen
from cobbler import download_manager
from cobbler.cexceptions import CX


ERROR = 100
INFO = 10
DEBUG = 5

# FIXME: add --quiet depending on if not --verbose?
RSYNC_CMD = "rsync -a %s '%s' %s --progress"


# notes on locking:
# - CobblerAPI is a singleton object
# - The XMLRPC variants allow 1 simultaneous request, therefore we flock on our settings file for now on a request by
Expand All @@ -68,7 +62,7 @@ def __init__(self, is_cobblerd: bool = False, settingsfile_location: str = "/etc
"""
Constructor

:param is_cobblerd: Wether this API is run as a deamon or not.
:param is_cobblerd: Wether this API is run as a daemon or not.
:param settingsfile_location: The location of the settings file on the disk.
"""

Expand All @@ -87,12 +81,7 @@ def __init__(self, is_cobblerd: bool = False, settingsfile_location: str = "/etc
main_thread = threading.main_thread()
main_thread.setName("Daemon")

try:
self.logger = logging.getLogger()
except CX:
# return to CLI/other but perms are not valid
# perms_ok is False
return
self.logger = logging.getLogger()

# FIXME: consolidate into 1 server instance

Expand Down Expand Up @@ -422,7 +411,8 @@ def copy_menu(self, ref, newname):

# ==========================================================================

def remove_item(self, what: str, ref: str, recursive: bool = False, delete: bool = True, with_triggers: bool = True):
def remove_item(self, what: str, ref: str, recursive: bool = False, delete: bool = True,
with_triggers: bool = True):
"""
Remove a general item. This method should not be used by an external api. Please use the specific
remove_<itemtype> methods.
Expand All @@ -437,7 +427,7 @@ def remove_item(self, what: str, ref: str, recursive: bool = False, delete: bool
if isinstance(ref, str):
ref = self.get_item(what, ref)
if ref is None:
return # nothing to remove
return # nothing to remove
self.log("remove_item(%s)" % what, [ref.name])
self.get_items(what).remove(ref.name, recursive=recursive, with_delete=delete, with_triggers=with_triggers)

Expand Down Expand Up @@ -590,7 +580,7 @@ def rename_repo(self, ref, newname):
"""
self.rename_item("repo", ref, newname)

def rename_image(self, ref, newname):
def rename_image(self, ref, newname: str):
"""
Rename an image to a new name.

Expand Down Expand Up @@ -1000,7 +990,7 @@ def find_menu(self, name=None, return_list=False, no_errors=False, **kargs):

# ==========================================================================

def __since(self, mtime, collector, collapse: bool = False) -> list:
def __since(self, mtime: float, collector, collapse: bool = False) -> list:
"""
Called by get_*_since functions. This is an internal part of Cobbler.

Expand All @@ -1020,7 +1010,7 @@ def __since(self, mtime, collector, collapse: bool = False) -> list:
results2.append(x.to_dict())
return results2

def get_distros_since(self, mtime, collapse: bool = False):
def get_distros_since(self, mtime: float, collapse: bool = False):
"""
Returns distros modified since a certain time (in seconds since Epoch)

Expand All @@ -1030,7 +1020,7 @@ def get_distros_since(self, mtime, collapse: bool = False):
"""
return self.__since(mtime, self.distros, collapse=collapse)

def get_profiles_since(self, mtime, collapse: bool = False) -> list:
def get_profiles_since(self, mtime: float, collapse: bool = False) -> list:
"""
Returns profiles modified since a certain time (in seconds since Epoch)

Expand All @@ -1041,7 +1031,7 @@ def get_profiles_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.profiles, collapse=collapse)

def get_systems_since(self, mtime, collapse: bool = False) -> list:
def get_systems_since(self, mtime: float, collapse: bool = False) -> list:
"""
Return systems modified since a certain time (in seconds since Epoch)

Expand All @@ -1052,7 +1042,7 @@ def get_systems_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.systems, collapse=collapse)

def get_repos_since(self, mtime, collapse: bool = False) -> list:
def get_repos_since(self, mtime: float, collapse: bool = False) -> list:
"""
Return repositories modified since a certain time (in seconds since Epoch)

Expand All @@ -1063,7 +1053,7 @@ def get_repos_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.repos, collapse=collapse)

def get_images_since(self, mtime, collapse: bool = False) -> list:
def get_images_since(self, mtime: float, collapse: bool = False) -> list:
"""
Return images modified since a certain time (in seconds since Epoch)

Expand All @@ -1074,7 +1064,7 @@ def get_images_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.images, collapse=collapse)

def get_mgmtclasses_since(self, mtime, collapse: bool = False) -> list:
def get_mgmtclasses_since(self, mtime: float, collapse: bool = False) -> list:
"""
Return management classes modified since a certain time (in seconds since Epoch)

Expand All @@ -1085,7 +1075,7 @@ def get_mgmtclasses_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.mgmtclasses, collapse=collapse)

def get_packages_since(self, mtime, collapse: bool = False) -> list:
def get_packages_since(self, mtime: float, collapse: bool = False) -> list:
"""
Return packages modified since a certain time (in seconds since Epoch)

Expand All @@ -1096,7 +1086,7 @@ def get_packages_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.packages, collapse=collapse)

def get_files_since(self, mtime, collapse: bool = False) -> list:
def get_files_since(self, mtime: float, collapse: bool = False) -> list:
"""
Return files modified since a certain time (in seconds since Epoch)

Expand All @@ -1107,7 +1097,7 @@ def get_files_since(self, mtime, collapse: bool = False) -> list:
"""
return self.__since(mtime, self.files, collapse=collapse)

def get_menus_since(self, mtime, collapse=False) -> list:
def get_menus_since(self, mtime: float, collapse=False) -> list:
"""
Return files modified since a certain time (in seconds since Epoch)

Expand Down Expand Up @@ -1158,15 +1148,15 @@ def signature_update(self):

# ==========================================================================

def dump_vars(self, obj, format: bool = False):
def dump_vars(self, obj, formatted_output: bool = False):
"""
Dump all known variables related to that object.

:param obj: The object for which the variables should be dumped.
:param format: If True the values will align in one column and be pretty printed for cli example.
:param formatted_output: If True the values will align in one column and be pretty printed for cli example.
:return: A dictionary with all the information which could be collected.
"""
return obj.dump_vars(format)
return obj.dump_vars(formatted_output)

# ==========================================================================

Expand All @@ -1192,30 +1182,29 @@ def auto_add_repos(self):

if self.find_repo(auto_name) is None:
cobbler_repo = self.new_repo()
cobbler_repo.set_name(auto_name)
cobbler_repo.set_breed("yum")
cobbler_repo.set_arch(basearch)
cobbler_repo.set_yumopts({})
cobbler_repo.set_environment({})
cobbler_repo.set_apt_dists([])
cobbler_repo.set_apt_components([])
cobbler_repo.set_comment(repository.name)
cobbler_repo.name = auto_name
cobbler_repo.breed = enums.RepoBreeds.YUM
cobbler_repo.arch = basearch
cobbler_repo.comment = repository.name
baseurl = repository.baseurl
metalink = repository.metalink
mirrorlist = repository.mirrorlist

if metalink is not None:
mirror = metalink
mirror_type = "metalink"
mirror_type = enums.MirrorType.METALINK
elif mirrorlist is not None:
mirror = mirrorlist
mirror_type = "mirrorlist"
mirror_type = enums.MirrorType.MIRRORLIST
elif len(baseurl) > 0:
mirror = baseurl[0]
mirror_type = "baseurl"
mirror_type = enums.MirrorType.BASEURL
else:
mirror = ""
mirror_type = enums.MirrorType.NONE

cobbler_repo.set_mirror(mirror)
cobbler_repo.set_mirror_type(mirror_type)
cobbler_repo.mirror = mirror
cobbler_repo.mirror_type = mirror_type
self.log("auto repo adding: %s" % auto_name)
self.add_repo(cobbler_repo)
else:
Expand Down Expand Up @@ -1471,7 +1460,6 @@ def reposync(self, name=None, tries: int = 1, nofail: bool = False):
:param tries: How many tries should be executed before the action fails.
:param nofail: If True then the action will fail, otherwise the action will just be skipped. This respects the
``tries`` parameter.
:param logger: The logger to audit the removal with.
"""
self.log("reposync", [name])
action_reposync = reposync.RepoSync(self._collection_mgr, tries=tries, nofail=nofail)
Expand All @@ -1484,7 +1472,6 @@ def status(self, mode):
Get the status of the current Cobbler instance.

:param mode: "text" or anything else. Meaning whether the output is thought for the terminal or not.
:param logger: The logger to audit the removal with.
:return: The current status of Cobbler.
"""
statusifier = status.CobblerStatusReport(self._collection_mgr, mode)
Expand Down Expand Up @@ -1537,7 +1524,7 @@ def import_tree(self, mirror_url: str, mirror_name: str, network_root=None, auto
if not mirror_url.endswith("/"):
mirror_url = "%s/" % mirror_url

if mirror_url.startswith("http://") or mirror_url.startswith("https://") or mirror_url.startswith("ftp://")\
if mirror_url.startswith("http://") or mirror_url.startswith("https://") or mirror_url.startswith("ftp://") \
or mirror_url.startswith("nfs://"):
# HTTP mirrors are kind of primative. rsync is better. That's why this isn't documented in the manpage and
# we don't support them.
Expand Down Expand Up @@ -1588,7 +1575,7 @@ def import_tree(self, mirror_url: str, mirror_name: str, network_root=None, auto
self.log("Network root given to --available-as is missing a colon, please see the manpage example.")
return False

import_module = self.get_module_by_name("managers.import_signatures")\
import_module = self.get_module_by_name("managers.import_signatures") \
.get_import_manager(self._collection_mgr)
import_module.run(path, mirror_name, network_root, autoinstall_file, arch, breed, os_version)

Expand All @@ -1603,7 +1590,6 @@ def acl_config(self, adduser=None, addgroup=None, removeuser=None, removegroup=N
:param addgroup:
:param removeuser:
:param removegroup:
:param logger: The logger to audit the removal with.
"""
action_acl = acl.AclConfig(self._collection_mgr)
action_acl.run(
Expand Down Expand Up @@ -1833,8 +1819,7 @@ def get_valid_obj_boot_loaders(self, obj):
"""
Return the list of valid boot loaders for the object

:param token: The API-token obtained via the login() method.
:param obj: The object for which the boot loaders should be looked up.
:return: Get a list of all valid boot loaders.
"""
return obj.get_supported_boot_loaders()
return obj.supported_boot_loaders
5 changes: 2 additions & 3 deletions cobbler/autoinstallgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ def generate_autoyast(self, profile=None, system=None, raw_data=None) -> str:
cobblerElement.appendChild(cobblerElementSystem)
cobblerElement.appendChild(cobblerElementProfile)

# FIXME: this is all broken and no longer works.
# this entire if block should probably not be
# hard-coded anyway
# FIXME: this is all broken and no longer works. This entire if block should probably not be hard-coded
# anyway
# self.api.log(document.childNodes[2].childNodes)
# document.childNodes[1].insertBefore( cobblerElement, document.childNodes[2].childNodes[1])
# document.childNodes[1].insertBefore( cobblerElement, document.childNodes[1].childNodes[0])
Expand Down
Loading
0