Skip to content
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

Add an autoinstallation snippet generating repositories for Autoyast #9652

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions java/conf/cobbler/snippets/autoyast_channels
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import uyuni_cobbler_helper
#for $label, $channel in $uyuni_cobbler_helper.channels($distrotree).items()
<listentry>
<ask_on_error config:type="boolean">true</ask_on_error>
<media_url>https://$redhat_management_server/ks/dist/child/$label/$distrotree</media_url>
<name>$channel["name"]</name>
<product>$channel["product"]</product>
</listentry>
#end for
2 changes: 2 additions & 0 deletions java/spacewalk-java.spec
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ Requires: tomcat-native
Requires(pre): salt
Requires(pre): tomcat >= 7
Requires(pre): uyuni-base-server
Requires: uyuni-cobbler-helper

%if 0%{?rhel}
Recommends: rng-tools
Expand Down Expand Up @@ -581,6 +582,7 @@ install -m 644 conf/cobbler/snippets/redhat_register_using_salt %{buildroot}%
install -m 644 conf/cobbler/snippets/minion_script %{buildroot}%{spacewalksnippetsdir}/minion_script
install -m 644 conf/cobbler/snippets/sles_no_signature_checks %{buildroot}%{spacewalksnippetsdir}/sles_no_signature_checks
install -m 644 conf/cobbler/snippets/wait_for_networkmanager_script %{buildroot}%{spacewalksnippetsdir}/wait_for_networkmanager_script
install -m 644 conf/cobbler/snippets/autoyast_channels %{buildroot}%{spacewalksnippetsdir}/autoyast_channels

# special links for rhn-search
RHN_SEARCH_BUILD_DIR=%{_datadir}/rhn/search/lib
Expand Down
51 changes: 51 additions & 0 deletions python/uyuni-cobbler-helper/cobbler_helper.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# spec file for package uyuni-cobbler-helper
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%{!?python3_sitelib: %global python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}


Name: uyuni-cobbler-helper
Version: 0.1.0
Release: 0
Summary: Python helper functions for Uyuni cobbler snippets
License: Apache-2.0
Group: System/Management
URL: https://github.com/uyuni-project/uyuni
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%if !0%{?suse_version} || 0%{?suse_version} >= 1120
BuildArch: noarch
%endif

Requires: python3
Requires: python3-psycopg2 >= 2.8.4
BuildRequires: python3-rpm
BuildRequires: python3-rpm-macros

%description
This package provides utility functions to expose Uyuni data to cobbler snippets.

%prep
%autosetup

%install
install -m 644 uyuni_cobbler_helper.py %{python3_sitelib}/uyuni_cobbler_helper.py

%files
%{python3_sitelib}/uyuni_cobbler_helper.py

%changelog
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add helper function getting channels from a distribution tree
41 changes: 41 additions & 0 deletions python/uyuni-cobbler-helper/uyuni_cobbler_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import psycopg2
import configparser


def channels(distrotree):
cnx = _connect_db()
cursor = cnx.cursor()

query = """SELECT CT.name, CT.label, CP.product
FROM rhnkickstartabletree T,
rhnchanneltreeview CT,
rhnchannel C,
rhnchannelproduct CP
WHERE T.channel_id = CT.parent_or_self_id
AND CT.id = C.id
AND C.channel_product_id = CP.id
AND T.label = %s;"""

cursor.execute(query, (distrotree,))
channels = {}
for row in cursor.fetchall():
channels[row[1]] = {"name": row[0], "product": row[2]}

cnx.close()
return channels


def _connect_db():
config = configparser.ConfigParser()
with open("/etc/rhn/rhn.conf", "r") as fd:
content = "[default]\n" + fd.read()
config.read_string(content)

# pylint: disable-next=undefined-variable
return psycopg2.connect(
host=config.get("default", "db_host"),
user=config.get("default", "db_user"),
password=config.get("default", "db_password"),
dbname=config.get("default", "db_name"),
port=int(config.get("default", "db_port")),
)
1 change: 1 addition & 0 deletions rel-eng/packages/uyuni-cobbler-helper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0-0 python/uyuni-cobbler-helper/
1 change: 1 addition & 0 deletions spacewalk/setup/bin/spacewalk-setup-cobbler
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def manipulate_cobbler_settings(config_dir: str, settings_yaml: str, fqdn: str):
filecontent["redhat_management_server"] = fqdn or socket.getfqdn()
filecontent["client_use_localhost"] = True
filecontent["uyuni_authentication_endpoint"] = "http://localhost"
filecontent["cheetah_import_whitelist"].append("uyuni_cobbler_helper")
yaml_dump = yaml.safe_dump(filecontent)
with open(full_path, "w") as settings_file:
settings_file.write(yaml_dump)
Expand Down
1 change: 1 addition & 0 deletions spacewalk/setup/spacewalk-setup.changes.cbosdo.profile-dl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add uyuni-cobbler-helper to cobbler's python module whitelist
Loading