From ba854de02b5bf69df31101e9d2423640588bc13c Mon Sep 17 00:00:00 2001 From: Michael Calmer Date: Thu, 9 Jan 2025 14:52:49 +0100 Subject: [PATCH] Allow refresh of all system pillar data via API and spacecmd --- .../frontend/xmlrpc/system/SystemHandler.java | 21 ++++++---- ...mcalmer.api-for-pillar-refresh-all-systems | 2 + .../satellite_tools/mgr-sign-metadata-ctl | 6 ++- ...mcalmer.api-for-pillar-refresh-all-systems | 1 + ...mcalmer.api-for-pillar-refresh-all-systems | 1 + spacecmd/src/spacecmd/system.py | 39 +++++++++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems create mode 100644 python/spacewalk/spacewalk-backend.changes.mcalmer.api-for-pillar-refresh-all-systems create mode 100644 spacecmd/spacecmd.changes.mcalmer.api-for-pillar-refresh-all-systems diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java index 02505f1ee61b..81dafca59699 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java @@ -9072,7 +9072,7 @@ public int setPillar(User loggedInUser, String minionId, String category, Map refreshPillar(User loggedInUser, List sids) { @@ -9091,7 +9091,7 @@ public List refreshPillar(User loggedInUser, List sids) { * and can be one of 'general', 'group_membership', 'virtualization' or 'custom_info'. * @apidoc.param #session_key() * @apidoc.param #param("string", "subset", "subset of the pillar to refresh.") - * @apidoc.param #array_single("int", "sids") + * @apidoc.param #array_single("int", "sids", "System IDs to be refreshed. If empty, all systems will be refreshed") * @apidoc.returntype #array_single("int", "skippedIds", "System IDs which couldn't be refreshed") */ public List refreshPillar(User loggedInUser, String subset, List sids) { @@ -9099,9 +9099,16 @@ public List refreshPillar(User loggedInUser, String subset, List sysids; + if (sids == null || sids.isEmpty()) { + sysids = MinionServerFactory.lookupVisibleToUser(loggedInUser).map(MinionServer::getId).toList(); + } + else { + sysids = sids.stream().map(Integer::longValue).toList(); + } + for (Long sysId : sysids) { + if (SystemManager.isAvailableToUser(loggedInUser, sysId)) { + Server system = SystemManager.lookupByIdAndUser(sysId, loggedInUser); system.asMinionServer().ifPresentOrElse( minionServer -> { if (subsetValue != null) { @@ -9113,13 +9120,13 @@ public List refreshPillar(User loggedInUser, String subset, List { log.warn("system {} is not a salt minion, hence pillar will not be updated", sysId); - skipped.add(sysId); + skipped.add(sysId.intValue()); } ); } else { log.warn("system {} is not available to user, hence pillar will not be refreshed", sysId); - skipped.add(sysId); + skipped.add(sysId.intValue()); } } return skipped; diff --git a/java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems b/java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems new file mode 100644 index 000000000000..eb5658f366cd --- /dev/null +++ b/java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems @@ -0,0 +1,2 @@ +- Modify systems refresh Pillar API to allow refresh pillar data + of all systems diff --git a/python/spacewalk/satellite_tools/mgr-sign-metadata-ctl b/python/spacewalk/satellite_tools/mgr-sign-metadata-ctl index 5df1cd4c6e50..1249a71bb1b0 100644 --- a/python/spacewalk/satellite_tools/mgr-sign-metadata-ctl +++ b/python/spacewalk/satellite_tools/mgr-sign-metadata-ctl @@ -29,8 +29,10 @@ function regenerate_metadata { systemctl restart taskomatic echo "done." echo - echo "Scheduling repo metadata regeneration..." read_spacecmd_user_pass + echo "Refreshing pillar data..." + spacecmd -q -u $SPACECMD_USER -p $SPACECMD_PASS "system_refreshpillar" + echo "Scheduling repo metadata regeneration..." spacecmd -q -u $SPACECMD_USER -p $SPACECMD_PASS "softwarechannel_regenerateyumcache -f *" RETVAL=$? if [ $RETVAL -ne 0 ]; then @@ -317,5 +319,7 @@ if [[ $ACTION = "enable" || $ACTION = "disable" ]]; then echo echo "NOTE. For the changes to become effective run:" echo " mgr-sign-metadata-ctl regen-metadata" + echo "and schedule a highstate for all your systems to" + echo "apply the new repository configuration." echo fi diff --git a/python/spacewalk/spacewalk-backend.changes.mcalmer.api-for-pillar-refresh-all-systems b/python/spacewalk/spacewalk-backend.changes.mcalmer.api-for-pillar-refresh-all-systems new file mode 100644 index 000000000000..d3b34510a8f2 --- /dev/null +++ b/python/spacewalk/spacewalk-backend.changes.mcalmer.api-for-pillar-refresh-all-systems @@ -0,0 +1 @@ +- Refresh pillar data together with regenration of channel metadata diff --git a/spacecmd/spacecmd.changes.mcalmer.api-for-pillar-refresh-all-systems b/spacecmd/spacecmd.changes.mcalmer.api-for-pillar-refresh-all-systems new file mode 100644 index 000000000000..3b31e8c73a0e --- /dev/null +++ b/spacecmd/spacecmd.changes.mcalmer.api-for-pillar-refresh-all-systems @@ -0,0 +1 @@ +- Add command to refresh systems pillar data diff --git a/spacecmd/src/spacecmd/system.py b/spacecmd/src/spacecmd/system.py index 5ef4bf1b5540..2f56b6b6030d 100644 --- a/spacecmd/src/spacecmd/system.py +++ b/spacecmd/src/spacecmd/system.py @@ -2057,6 +2057,45 @@ def do_system_rename(self, args): #################### +def help_system_refreshpillar(self): + print(_('system_refreshpillar: Refresh pillar data of system(s) ')) + print(_('usage: system_refreshpillar []')) + print('') + print(self.HELP_SYSTEM_OPTS) + +def complete_system_refreshpillar(self, text, line, beg, end): + return self.tab_complete_systems(text) + +def do_system_refreshpillar(self, args): + arg_parser = get_argument_parser() + + (args, _options) = parse_command_arguments(args, arg_parser) + + sids = [] + # use the systems listed in the SSM + if args: + if re.match('ssm', args[0], re.I): + systems = self.ssm.keys() + else: + systems = self.expand_systems(args) + + for system in sorted(systems): + system_id = self.get_system_id(system) + if not system_id: + continue + sids.append(system_id) + + self.client.system.refreshPillar(self.session, sids) + + num = "%s" % len(sids) + if (num == "0"): + num = "all" + print('Refreshed Pillar data for "%s" systems' % (num)) + return 0 + +#################### + + def help_system_listcustomvalues(self): print(_('system_listcustomvalues: List the custom values for a system')) print(_('usage: system_listcustomvalues '))